diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java index 12cf7ec1a6b..f513e18fe18 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java @@ -26,6 +26,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.ast.IASTName; 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.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -143,28 +144,31 @@ public class CallHierarchyUI { try { IASTName name= getSelectedName(editorInput, sel); if (name != null) { - if (name.isDefinition()) { - 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}; - } + IBinding binding= name.resolveBinding(); + if (index.isRelevantForCallHierarchy(binding)) { + if (name.isDefinition()) { + ICElement elem= index.findDefinition(project, name); + if (elem != null) { + return 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; } - private static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException { int selectionStart = selection.getOffset(); int selectionLength = selection.getLength(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java index e4da868d7eb..fb4e5f32960 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/missingapi/CIndexQueries.java @@ -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.IASTTranslationUnit; 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.ICElement; import org.eclipse.cdt.core.model.ICProject; @@ -375,16 +379,19 @@ public class CIndexQueries { IASTName[] refs = refVisitor.getReferences(); for (int i = 0; i < refs.length; i++) { IASTName name = refs[i]; - ICElement[] defs = findAllDefinitions(scope, name); - if (defs.length == 0) { - ICElement elem = findAnyDeclaration(scope, name); - if (elem != null) { - defs = new ICElement[] { elem }; + IBinding binding= name.resolveBinding(); + if (isRelevantForCallHierarchy(binding)) { + ICElement[] defs = findAllDefinitions(scope, name); + if (defs.length == 0) { + 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) { ArrayList result= new ArrayList(); for (int i = 0; i < projectsToSearch.length; i++) {