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,6 +144,8 @@ public class CallHierarchyUI {
try { try {
IASTName name= getSelectedName(editorInput, sel); IASTName name= getSelectedName(editorInput, sel);
if (name != null) { if (name != null) {
IBinding binding= name.resolveBinding();
if (index.isRelevantForCallHierarchy(binding)) {
if (name.isDefinition()) { if (name.isDefinition()) {
ICElement elem= index.findDefinition(project, name); ICElement elem= index.findDefinition(project, name);
if (elem != null) { if (elem != null) {
@ -168,6 +171,7 @@ public class CallHierarchyUI {
} }
} }
} }
}
finally { finally {
if (pdom != null) { if (pdom != null) {
pdom.releaseReadLock(); pdom.releaseReadLock();
@ -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,6 +379,8 @@ 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];
IBinding binding= name.resolveBinding();
if (isRelevantForCallHierarchy(binding)) {
ICElement[] defs = findAllDefinitions(scope, name); ICElement[] defs = findAllDefinitions(scope, name);
if (defs.length == 0) { if (defs.length == 0) {
ICElement elem = findAnyDeclaration(scope, name); ICElement elem = findAnyDeclaration(scope, name);
@ -389,6 +395,7 @@ public class CIndexQueries {
} }
} }
} }
}
finally { finally {
if (pdom != null) { if (pdom != null) {
pdom.releaseReadLock(); pdom.releaseReadLock();
@ -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++) {