diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java index 22bab17a2b2..106f5e8657c 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndex.java @@ -15,7 +15,6 @@ import java.util.regex.Pattern; import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -183,14 +182,6 @@ public interface IIndex { * @since 4.0 */ public IIndexFile resolveInclude(IIndexInclude include) throws CoreException; - - /** - * Looks for a binding for the given ICElement. May return null. - * @param element an element a binding is searched for - * @return a binding for the element or null - * @throws CoreException - */ - public IIndexBinding findBinding(ICElement element) throws CoreException; /** * Searches for the binding of a name. The name may be originated by diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java index 0be72933d61..10261cf6542 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexFile.java @@ -57,4 +57,9 @@ public interface IIndexFile { * @throws CoreException */ long getTimestamp() throws CoreException; + + /** + * Find all names within the given range. + */ + IIndexName[] findNames(int offset, int length) throws CoreException; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java index fd54aa5ee81..ecb7b0c4f0f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/CIndex.java @@ -29,7 +29,6 @@ import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IndexFilter; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -55,8 +54,20 @@ public class CIndex implements IIndex { return result; } - public IIndexBinding findBinding(ICElement element) throws CoreException { - // mstodo ICElement to IBinding + public IIndexBinding adaptBinding(IBinding binding) throws CoreException { + if (binding instanceof IIndexFragmentBinding) { + IIndexFragmentBinding fragBinding= (IIndexFragmentBinding) binding; + if (isFragment(fragBinding.getFragment())) { + return fragBinding; + } + } + + for (int i = 0; i < fFragments.length; i++) { + IIndexProxyBinding result= fFragments[i].adaptBinding(binding); + if (result instanceof IIndexFragmentBinding) { + return (IIndexFragmentBinding) result; + } + } return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java index d951fff3573..59d1a30226a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/EmptyCIndex.java @@ -21,7 +21,6 @@ import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IndexFilter; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -32,10 +31,6 @@ final public class EmptyCIndex implements IIndex { private EmptyCIndex() { } - public IIndexBinding findBinding(ICElement element) { - return null; - } - public IIndexName[] findDeclarations(IBinding binding) { return IIndexFragmentName.EMPTY_NAME_ARRAY; } @@ -97,4 +92,8 @@ final public class EmptyCIndex implements IIndex { public IIndexBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException { return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; } + + public IIndexBinding adaptBinding(IBinding binding) throws CoreException { + return null; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index 918137bfa47..d524b0e1e97 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition; import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexMacro; +import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IWritableIndexFragment; @@ -321,4 +322,25 @@ public class PDOMFile implements IIndexFragmentFile { public IIndexFragment getIndexFragment() { return pdom; } + + public IIndexName[] findNames(int offset, int length) throws CoreException { + ArrayList result= new ArrayList(); + for (PDOMName name= getFirstName(); name != null; name= name.getNextInFile()) { + int nameOffset= name.getNodeOffset(); + if (nameOffset >= offset) { + if (nameOffset == offset) { + if (name.getNodeLength() == length) { + result.add(name); + } + } + else if (name.isReference()) { + // names are ordered, but callers are inserted before + // their references + break; + } + } + + } + return (IIndexName[]) result.toArray(new IIndexName[result.size()]); + } }