mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 03:45:35 +02:00
Bug 311164: Follow up on fix to improve mark occurrences feature.
This commit is contained in:
parent
43e33bc736
commit
8b7a529a11
6 changed files with 42 additions and 33 deletions
|
@ -416,6 +416,8 @@ public class ASTTypeUtil {
|
|||
needSpace= appendCVQ(result, needSpace, qt.isConst(), qt.isVolatile());
|
||||
} else if (type instanceof ITypedef) {
|
||||
result.append(((ITypedef) type).getNameCharArray());
|
||||
} else if (type instanceof IProblemBinding) {
|
||||
result.append('?');
|
||||
} else if (type != null) {
|
||||
result.append('@').append(type.hashCode());
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.ICInternalFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
|
||||
|
@ -172,4 +174,22 @@ public class ASTInternal {
|
|||
((ICPPInternalBinding) b).addDefinition(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasDeclaration(IBinding binding) {
|
||||
if (binding instanceof ICPPInternalBinding) {
|
||||
ICPPInternalBinding internal= (ICPPInternalBinding) binding;
|
||||
if (internal.getDefinition() != null)
|
||||
return true;
|
||||
IASTNode[] decls= internal.getDeclarations();
|
||||
return decls != null && decls.length > 0 && decls[0] != null;
|
||||
}
|
||||
if (binding instanceof IIndexBinding) {
|
||||
try {
|
||||
return IndexFilter.ALL_DECLARED.acceptBinding(binding);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return binding != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2314,4 +2314,17 @@ public class CPPTemplates {
|
|||
}
|
||||
return ObjectMap.EMPTY_MAP;
|
||||
}
|
||||
|
||||
public static IBinding findDeclarationForSpecialization(IBinding binding) {
|
||||
while (binding instanceof ICPPSpecialization) {
|
||||
if (ASTInternal.hasDeclaration(binding))
|
||||
return binding;
|
||||
|
||||
IBinding original= ((ICPPSpecialization) binding).getSpecializedBinding();
|
||||
if (original == null)
|
||||
return binding;
|
||||
binding= original;
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1264,6 +1264,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
|
||||
|
||||
public CollectDeclarationsAction(IBinding binding) {
|
||||
binding = CPPTemplates.findDeclarationForSpecialization(binding);
|
||||
shouldVisitNames = true;
|
||||
this.decls = new IASTName[DEFAULT_LIST_SIZE];
|
||||
|
||||
|
@ -1410,17 +1411,6 @@ public class CPPVisitor extends ASTQueries {
|
|||
|
||||
}
|
||||
|
||||
protected static IBinding unwindBinding(IBinding binding) {
|
||||
while (true) {
|
||||
if (binding instanceof ICPPSpecialization) {
|
||||
binding= ((ICPPSpecialization) binding).getSpecializedBinding();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
|
||||
public static class CollectReferencesAction extends ASTVisitor {
|
||||
private static final int DEFAULT_LIST_SIZE = 8;
|
||||
private IASTName[] refs;
|
||||
|
@ -1438,7 +1428,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
shouldVisitNames = true;
|
||||
this.refs = new IASTName[DEFAULT_LIST_SIZE];
|
||||
|
||||
binding = unwindBinding(binding);
|
||||
binding = CPPTemplates.findDeclarationForSpecialization(binding);
|
||||
this.bindings = new IBinding[] {binding};
|
||||
|
||||
if (binding instanceof ICPPUsingDeclaration) {
|
||||
|
@ -1536,7 +1526,7 @@ public class CPPVisitor extends ASTQueries {
|
|||
}
|
||||
|
||||
private boolean isReferenceBinding(IBinding nameBinding) {
|
||||
nameBinding= unwindBinding(nameBinding);
|
||||
nameBinding = CPPTemplates.findDeclarationForSpecialization(nameBinding);
|
||||
if (nameBinding != null) {
|
||||
for (IBinding binding : bindings) {
|
||||
if (nameBinding.equals(binding)) {
|
||||
|
|
|
@ -25,13 +25,12 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
|
||||
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||
|
@ -73,7 +72,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
|||
}
|
||||
}
|
||||
binding = index.findBinding(searchName);
|
||||
binding= findDeclarationForSpecialization(binding);
|
||||
binding= CPPTemplates.findDeclarationForSpecialization(binding);
|
||||
if (binding != null) {
|
||||
label= labelForBinding(index, binding, label);
|
||||
createMatches(index, binding);
|
||||
|
@ -84,22 +83,6 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
|||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
private IBinding findDeclarationForSpecialization(IBinding binding) {
|
||||
while (binding instanceof ICPPSpecialization) {
|
||||
try {
|
||||
if (IndexFilter.ALL_DECLARED.acceptBinding(binding))
|
||||
return binding;
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
|
||||
IBinding original= ((ICPPSpecialization) binding).getSpecializedBinding();
|
||||
if (original == null)
|
||||
return binding;
|
||||
binding= original;
|
||||
}
|
||||
return binding;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
|||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
|
||||
|
@ -514,7 +515,7 @@ public class IndexUI {
|
|||
|
||||
|
||||
for (ICPPTemplateInstance inst : instances) {
|
||||
if (!IndexFilter.ALL_DECLARED.acceptBinding(inst)) {
|
||||
if (!ASTInternal.hasDeclaration(inst)) {
|
||||
result.add(inst);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue