1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 09:15:38 +02:00

Fix computation of translation unit for binary nodes

This commit is contained in:
Anton Leherbauer 2008-03-13 14:54:44 +00:00
parent 606210b7cd
commit 7c6bce8248

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others. * Copyright (c) 2000, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -16,7 +17,6 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URI;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -312,29 +312,29 @@ public class Binary extends Openable implements IBinary {
// Also check for relative path names and attempt to resolve // Also check for relative path names and attempt to resolve
// them relative to the executable. // them relative to the executable.
try { if (filename.startsWith(".")) { //$NON-NLS-1$
filename = obj.getPath().removeLastSegments(1).append(filename).toOSString();
}
File file = new File(filename); File file = new File(filename);
try {
if (file.exists()) { if (file.exists()) {
filename = file.getCanonicalPath(); filename = file.getCanonicalPath();
} else if (filename.startsWith(".")) { //$NON-NLS-1$
file = new File(obj.getPath().removeLastSegments(1).toOSString(), filename);
filename = file.getCanonicalPath();
} }
} catch (IOException e) { // Do nothing. } catch (IOException e) { // Do nothing.
} }
// Create a translation unit for this file and add it as a child of the binary
String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), file.getName());
if (id == null) {
// Don't add files we can't get an ID for.
continue;
}
// See if this source file is already in the project. // See if this source file is already in the project.
// We check this to determine if we should create a TranslationUnit or ExternalTranslationUnit // We check this to determine if we should create a TranslationUnit or ExternalTranslationUnit
IFile sourceFile = getCProject().getProject().getFile(filename);
URI uri = sourceFile.getLocationURI();
IFile wkspFile = null; IFile wkspFile = null;
if (sourceFile.exists())
wkspFile = sourceFile;
else {
IFile[] filesInWP = ResourcesPlugin IFile[] filesInWP = ResourcesPlugin
.getWorkspace().getRoot() .getWorkspace().getRoot()
.findFilesForLocationURI(uri); .findFilesForLocation(new Path(filename));
for (int j = 0; j < filesInWP.length; j++) { for (int j = 0; j < filesInWP.length; j++) {
if (filesInWP[j].isAccessible()) { if (filesInWP[j].isAccessible()) {
@ -342,24 +342,16 @@ public class Binary extends Openable implements IBinary {
break; break;
} }
} }
}
// Create a translation unit for this file and add it as a child of the binary
String id = CoreModel.getRegistedContentTypeId(sourceFile
.getProject(), sourceFile.getName());
if (id != null)
{ // Don't add files we can't get an ID for.
TranslationUnit tu; TranslationUnit tu;
if (wkspFile != null) if (wkspFile != null)
tu = new TranslationUnit(this, wkspFile, id); tu = new TranslationUnit(this, wkspFile, id);
else else
tu = new ExternalTranslationUnit(this, uri, id); tu = new ExternalTranslationUnit(this, file.toURI(), id);
if (! info.includesChild(tu)) if (! info.includesChild(tu))
info.addChild(tu); info.addChild(tu);
} }
}
return true; return true;
} }
return false; return false;