diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java index de4af83ea04..7bc00b8ed60 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java @@ -17,6 +17,7 @@ import java.net.URI; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; /** @@ -36,4 +37,10 @@ public class ExternalTranslationUnit extends TranslationUnit { super(parent, uri, contentTypeID); } + /** + * A file included from a different project can still belong to a (non-CDT) project + */ + public void setResource(IFile file) { + resource= file; + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java index fcb459ecc6a..9fd09a5ad4b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/PDOMUpdateTask.java @@ -27,7 +27,11 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit; import org.eclipse.cdt.internal.core.pdom.IndexerProgress; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -98,23 +102,32 @@ public class PDOMUpdateTask implements IPDOMIndexerTask { } } if (haveProject && (fUpdateOptions & IIndexManager.UPDATE_EXTERNAL_FILES_FOR_PROJECT) != 0) { + final String projectPrefix= project.getProject().getFullPath().toString() + IPath.SEPARATOR; IIndex index= CCorePlugin.getIndexManager().getIndex(project); index.acquireReadLock(); try { IIndexFile[] files= index.getAllFiles(); for (IIndexFile indexFile : files) { IIndexFileLocation floc= indexFile.getLocation(); - if (floc.getFullPath() == null) { - IPath path= IndexLocationFactory.getPath(floc); + final String fullPath = floc.getFullPath(); + if (fullPath == null || !fullPath.startsWith(projectPrefix)) { + IPath path= IndexLocationFactory.getAbsolutePath(floc); if (path != null) { ITranslationUnit tu= CoreModel.getDefault().createTranslationUnitFrom(project, path); if (tu != null) { + if (fullPath != null) { + if (tu instanceof ExternalTranslationUnit) { + IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); + if (file instanceof IFile) { + ((ExternalTranslationUnit) tu).setResource((IFile) file); + } + } + } set.add(tu); } } } } - } finally { index.releaseReadLock(); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java index 6ad553c9b70..03fd25491c8 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/ProjectIndexerInputAdapter.java @@ -42,15 +42,13 @@ import org.eclipse.core.runtime.content.IContentType; * @since 5.0 */ public class ProjectIndexerInputAdapter extends IndexerInputAdapter { - /** - * mstodo - */ private static final AbstractLanguage[] NO_LANGUAGE = new AbstractLanguage[0]; private final ICProject fCProject; private final HashMap fIflCache; private final FileExistsCache fExistsCache; private AbstractLanguage fLangC; private AbstractLanguage fLangCpp; + private String fProjectPrefix; public ProjectIndexerInputAdapter(ICProject cproject) { this(cproject, true); @@ -58,6 +56,7 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter { public ProjectIndexerInputAdapter(ICProject cproject, boolean useCache) { fCProject= cproject; + fProjectPrefix= cproject.getProject().getFullPath().toString() + IPath.SEPARATOR; if (useCache) { fIflCache= new HashMap(); fExistsCache= new FileExistsCache(); @@ -226,7 +225,8 @@ public class ProjectIndexerInputAdapter extends IndexerInputAdapter { @Override public boolean canBePartOfSDK(IIndexFileLocation ifl) { - return ifl.getFullPath() == null; + final String fullPath = ifl.getFullPath(); + return fullPath == null || !fullPath.startsWith(fProjectPrefix); } @Override