1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-01 05:15:43 +02:00

Ignore type references in Call Hierarchy

This commit is contained in:
Markus Schorn 2006-09-07 08:46:57 +00:00
parent c09be87a9b
commit 1203c80cde
2 changed files with 50 additions and 30 deletions

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOM;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -143,28 +144,31 @@ public class CallHierarchyUI {
try { try {
IASTName name= getSelectedName(editorInput, sel); IASTName name= getSelectedName(editorInput, sel);
if (name != null) { if (name != null) {
if (name.isDefinition()) { IBinding binding= name.resolveBinding();
ICElement elem= index.findDefinition(project, name); if (index.isRelevantForCallHierarchy(binding)) {
if (elem != null) { if (name.isDefinition()) {
return new ICElement[]{elem}; ICElement elem= index.findDefinition(project, name);
} if (elem != null) {
} return new ICElement[]{elem};
else {
ICElement[] elems= index.findAllDefinitions(project, name);
if (elems.length == 0) {
ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects();
elems= index.findAllDefinitions(allProjects, name);
if (elems.length == 0) {
ICElement elem= index.findAnyDeclaration(project, name);
if (elem == null) {
elem= index.findAnyDeclaration(allProjects, name);
}
if (elem != null) {
elems= new ICElement[] {elem};
}
} }
} }
return elems; else {
ICElement[] elems= index.findAllDefinitions(project, name);
if (elems.length == 0) {
ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects();
elems= index.findAllDefinitions(allProjects, name);
if (elems.length == 0) {
ICElement elem= index.findAnyDeclaration(project, name);
if (elem == null) {
elem= index.findAnyDeclaration(allProjects, name);
}
if (elem != null) {
elems= new ICElement[] {elem};
}
}
}
return elems;
}
} }
} }
} }
@ -176,7 +180,6 @@ public class CallHierarchyUI {
return null; return null;
} }
private static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException { private static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException {
int selectionStart = selection.getOffset(); int selectionStart = selection.getOffset();
int selectionLength = selection.getLength(); int selectionLength = selection.getLength();

View file

@ -32,6 +32,10 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -375,16 +379,19 @@ public class CIndexQueries {
IASTName[] refs = refVisitor.getReferences(); IASTName[] refs = refVisitor.getReferences();
for (int i = 0; i < refs.length; i++) { for (int i = 0; i < refs.length; i++) {
IASTName name = refs[i]; IASTName name = refs[i];
ICElement[] defs = findAllDefinitions(scope, name); IBinding binding= name.resolveBinding();
if (defs.length == 0) { if (isRelevantForCallHierarchy(binding)) {
ICElement elem = findAnyDeclaration(scope, name); ICElement[] defs = findAllDefinitions(scope, name);
if (elem != null) { if (defs.length == 0) {
defs = new ICElement[] { elem }; ICElement elem = findAnyDeclaration(scope, name);
if (elem != null) {
defs = new ICElement[] { elem };
}
}
if (defs != null && defs.length > 0) {
CIndexReference ref = new CIndexReference(tu, name);
result.add(defs, ref);
} }
}
if (defs != null && defs.length > 0) {
CIndexReference ref = new CIndexReference(tu, name);
result.add(defs, ref);
} }
} }
} }
@ -396,6 +403,16 @@ public class CIndexQueries {
} }
} }
public boolean isRelevantForCallHierarchy(IBinding binding) {
if (binding instanceof ICExternalBinding ||
binding instanceof IEnumerator ||
binding instanceof IFunction ||
binding instanceof IVariable) {
return true;
}
return false;
}
public ICElement[] findAllDefinitions(ICProject[] projectsToSearch, IASTName name) { public ICElement[] findAllDefinitions(ICProject[] projectsToSearch, IASTName name) {
ArrayList result= new ArrayList(); ArrayList result= new ArrayList();
for (int i = 0; i < projectsToSearch.length; i++) { for (int i = 0; i < projectsToSearch.length; i++) {