mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Index: Add method to find names by position
This commit is contained in:
parent
dd464d51a3
commit
399fa8e60a
5 changed files with 45 additions and 17 deletions
|
@ -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;
|
||||
|
@ -184,14 +183,6 @@ public interface IIndex {
|
|||
*/
|
||||
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
|
||||
* an AST or by a search in an index. May return <code>null</code>.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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()]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue