diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java index bd7d25510b1..8397c332365 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/util/CModelUtil.java @@ -17,6 +17,8 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICContainer; @@ -175,5 +177,39 @@ public class CModelUtil { return tu; } return null; + } + + /** + * Returns the translation unit for the location given or null. + * @throws CModelException + */ + public static ITranslationUnit findTranslationUnitForLocation(IIndexFileLocation ifl, ICProject preferredProject) throws CModelException { + String fullPath= ifl.getFullPath(); + if (fullPath != null) { + IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); + if (file instanceof IFile) { + return findTranslationUnit((IFile) file); + } + return null; + } + IPath location= IndexLocationFactory.getAbsolutePath(ifl); + if (location != null) { + CoreModel coreModel = CoreModel.getDefault(); + ITranslationUnit tu= null; + if (preferredProject != null) { + tu= coreModel.createTranslationUnitFrom(preferredProject, location); + } + if (tu == null) { + ICProject[] projects= coreModel.getCModel().getCProjects(); + for (int i = 0; i < projects.length && tu == null; i++) { + ICProject project = projects[i]; + if (!project.equals(preferredProject)) { + tu= coreModel.createTranslationUnitFrom(project, location); + } + } + } + return tu; + } + return null; } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java index 8775be53d4a..dfc544cb904 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBContentProvider.java @@ -105,15 +105,21 @@ public class IBContentProvider extends AsyncTreeContentProvider { for (int i = 0; i < includes.length; i++) { IIndexInclude include = includes[i]; try { - IPath includesPath = IndexLocationFactory.getAbsolutePath(include.getIncludesLocation()); + IIndexFileLocation includesPath= include.getIncludesLocation(); if (fComputeIncludedBy) { - directiveFile= targetFile= new IBFile(tu.getCProject(), IndexLocationFactory.getAbsolutePath(include.getIncludesLocation())); + directiveFile= targetFile= new IBFile(tu.getCProject(), include.getIncludedByLocation()); } else { targetFile= new IBFile(tu.getCProject(), includesPath); } + IPath fullPath= IndexLocationFactory.getPath(includesPath); + String name= "???"; //$NON-NLS-1$ + if (fullPath != null && fullPath.segmentCount() > 0) { + name= fullPath.lastSegment(); + } + IBNode newnode= new IBNode(node, targetFile, directiveFile, - includesPath.lastSegment(), include.getNameOffset(), + name, include.getNameOffset(), include.getNameLength(), include.getIncludedBy().getTimestamp()); newnode.setIsActiveCode(true); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDragSourceListener.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDragSourceListener.java index 745618bb005..c06a9838078 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDragSourceListener.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBDragSourceListener.java @@ -21,6 +21,9 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.dnd.*; import org.eclipse.ui.part.ResourceTransfer; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IndexLocationFactory; + public class IBDragSourceListener implements DragSourceListener { private TreeViewer fTreeViewer; @@ -65,9 +68,9 @@ public class IBDragSourceListener implements DragSourceListener { ArrayList files= new ArrayList(fSelectedNodes.size()); for (Iterator iter = fSelectedNodes.iterator(); iter.hasNext();) { IBNode node = (IBNode) iter.next(); - IFile file= (IFile) node.getAdapter(IFile.class); - if (file != null) { - IPath location= file.getLocation(); + IIndexFileLocation ifl= (IIndexFileLocation) node.getAdapter(IIndexFileLocation.class); + if (ifl != null) { + IPath location= IndexLocationFactory.getAbsolutePath(ifl); if (location != null) { files.add(location.toOSString()); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java index f5f94f505ce..772f0d66243 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java @@ -13,8 +13,10 @@ package org.eclipse.cdt.internal.ui.includebrowser; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IPath; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -24,26 +26,20 @@ import org.eclipse.cdt.internal.corext.util.CModelUtil; import org.eclipse.cdt.internal.ui.util.CoreUtility; public class IBFile { - public IPath fLocation; + public IIndexFileLocation fLocation; public ITranslationUnit fTU= null; public IBFile(ITranslationUnit tu) { fTU= tu; - IResource r= fTU.getResource(); - if (r != null) { - fLocation= r.getLocation(); - } - else { - fLocation= fTU.getPath(); - } + fLocation= IndexLocationFactory.getIFL(tu); } - public IBFile(ICProject preferredProject, IPath location) throws CModelException { + public IBFile(ICProject preferredProject, IIndexFileLocation location) throws CModelException { fLocation= location; fTU= CModelUtil.findTranslationUnitForLocation(location, preferredProject); } - public IPath getLocation() { + public IIndexFileLocation getLocation() { return fLocation; } @@ -65,10 +61,13 @@ public class IBFile { } public IFile getResource() { - if (fTU != null) { - IResource r= fTU.getResource(); - if (r instanceof IFile) { - return (IFile) r; + if (fLocation != null) { + String fullPath= fLocation.getFullPath(); + if (fullPath != null) { + IResource file= ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); + if (file instanceof IFile) { + return (IFile) file; + } } } return null; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java index b5e80bf50f0..cca862c0cf8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java @@ -15,6 +15,8 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.ui.util.CoreUtility; @@ -63,9 +65,9 @@ public class IBNode implements IAdaptable { hashCode+= fDirectiveName.hashCode(); } else if (fRepresentedFile != null) { - IPath path= fRepresentedFile.getLocation(); - if (path != null) { - hashCode+= path.hashCode(); + IIndexFileLocation ifl= fRepresentedFile.getLocation(); + if (ifl != null) { + hashCode+= ifl.hashCode(); } } return hashCode; @@ -89,14 +91,14 @@ public class IBNode implements IAdaptable { CoreUtility.safeEquals(fDirectiveName, rhs.fDirectiveName)); } - private boolean computeIsRecursive(IBNode parent, IPath path) { - if (parent == null || path == null) { + private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) { + if (parent == null || ifl == null) { return false; } - if (path.equals(parent.getRepresentedFile().getLocation())) { + if (ifl.equals(parent.getRepresentedFile().getLocation())) { return true; } - return computeIsRecursive(parent.fParent, path); + return computeIsRecursive(parent.fParent, ifl); } /** @@ -171,6 +173,9 @@ public class IBNode implements IAdaptable { if (adapter.isAssignableFrom(IFile.class)) { return fRepresentedFile.getResource(); } + if (adapter.isAssignableFrom(IIndexFileLocation.class)) { + return fRepresentedFile.getLocation(); + } } return null; } @@ -183,11 +188,11 @@ public class IBNode implements IAdaptable { if (fRepresentedFile == null) { return null; } - IFile file= fRepresentedFile.getResource(); - if (file != null) { - return file.getFullPath(); + IIndexFileLocation ifl= fRepresentedFile.getLocation(); + if (ifl != null) { + return IndexLocationFactory.getPath(ifl); } - return fRepresentedFile.getLocation(); + return null; } public long getTimestamp() { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java index e66829e493a..e5f71601751 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java @@ -69,6 +69,8 @@ import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.part.ViewPart; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexFileLocation; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; @@ -684,9 +686,12 @@ public class IBViewPart extends ViewPart EditorOpener.open(page, f, region, timestamp); } else { - IPath location= ibf.getLocation(); - if (location != null) { - EditorOpener.openExternalFile(page, location, region, timestamp); + IIndexFileLocation ifl = ibf.getLocation(); + if (ifl != null) { + IPath location= IndexLocationFactory.getAbsolutePath(ifl); + if (location != null) { + EditorOpener.openExternalFile(page, location, region, timestamp); + } } } }