1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 22:35:43 +02:00

Index: Add method to find names by position

This commit is contained in:
Markus Schorn 2006-11-22 12:44:56 +00:00
parent dd464d51a3
commit 399fa8e60a
5 changed files with 45 additions and 17 deletions

View file

@ -15,7 +15,6 @@ import java.util.regex.Pattern;
import org.eclipse.cdt.core.dom.IName; import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IBinding; 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.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -183,14 +182,6 @@ public interface IIndex {
* @since 4.0 * @since 4.0
*/ */
public IIndexFile resolveInclude(IIndexInclude include) throws CoreException; public IIndexFile resolveInclude(IIndexInclude include) throws CoreException;
/**
* Looks for a binding for the given ICElement. May return <code>null</code>.
* @param element an element a binding is searched for
* @return a binding for the element or <code>null</code>
* @throws CoreException
*/
public IIndexBinding findBinding(ICElement element) throws CoreException;
/** /**
* Searches for the binding of a name. The name may be originated by * Searches for the binding of a name. The name may be originated by

View file

@ -57,4 +57,9 @@ public interface IIndexFile {
* @throws CoreException * @throws CoreException
*/ */
long getTimestamp() throws CoreException; long getTimestamp() throws CoreException;
/**
* Find all names within the given range.
*/
IIndexName[] findNames(int offset, int length) throws CoreException;
} }

View file

@ -29,7 +29,6 @@ import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter; 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.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -55,8 +54,20 @@ public class CIndex implements IIndex {
return result; return result;
} }
public IIndexBinding findBinding(ICElement element) throws CoreException { public IIndexBinding adaptBinding(IBinding binding) throws CoreException {
// mstodo ICElement to IBinding 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; return null;
} }

View file

@ -21,7 +21,6 @@ import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter; 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.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -32,10 +31,6 @@ final public class EmptyCIndex implements IIndex {
private EmptyCIndex() { private EmptyCIndex() {
} }
public IIndexBinding findBinding(ICElement element) {
return null;
}
public IIndexName[] findDeclarations(IBinding binding) { public IIndexName[] findDeclarations(IBinding binding) {
return IIndexFragmentName.EMPTY_NAME_ARRAY; 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 { public IIndexBinding[] findBindings(Pattern[] pattern, boolean isFullyQualified, IndexFilter filter, IProgressMonitor monitor) throws CoreException {
return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY; return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
} }
public IIndexBinding adaptBinding(IBinding binding) throws CoreException {
return null;
}
} }

View file

@ -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.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.index.IIndexInclude; import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro; 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.IIndexFragment;
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile; import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
import org.eclipse.cdt.internal.core.index.IWritableIndexFragment; import org.eclipse.cdt.internal.core.index.IWritableIndexFragment;
@ -321,4 +322,25 @@ public class PDOMFile implements IIndexFragmentFile {
public IIndexFragment getIndexFragment() { public IIndexFragment getIndexFragment() {
return pdom; 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()]);
}
} }