mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Proper template support in search for references, bug 268726.
This commit is contained in:
parent
614dd157e9
commit
1558c3a6e8
7 changed files with 143 additions and 101 deletions
|
@ -27,6 +27,7 @@ public class CHHistoryAction extends Action {
|
|||
final static int LABEL_OPTIONS=
|
||||
CElementBaseLabels.M_PARAMETER_TYPES |
|
||||
CElementBaseLabels.ALL_FULLY_QUALIFIED |
|
||||
CElementBaseLabels.TEMPLATE_ARGUMENTS |
|
||||
CElementBaseLabels.MF_POST_FILE_QUALIFIED;
|
||||
|
||||
private CHViewPart fViewPart;
|
||||
|
|
|
@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.ui.callhierarchy;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -22,19 +21,15 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
|
||||
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
@ -98,52 +93,12 @@ public class CHQueries {
|
|||
private static void findCalledBy1(IIndex index, IBinding callee, boolean includeOrdinaryCalls,
|
||||
ICProject project, CalledByResult result) throws CoreException {
|
||||
findCalledBy2(index, callee, includeOrdinaryCalls, project, result);
|
||||
List<? extends IBinding> specializations = findSpecializations(callee);
|
||||
List<? extends IBinding> specializations = IndexUI.findSpecializations(callee);
|
||||
for (IBinding spec : specializations) {
|
||||
findCalledBy2(index, spec, includeOrdinaryCalls, project, result);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<? extends IBinding> findSpecializations(IBinding callee) throws CoreException {
|
||||
try {
|
||||
List<IBinding> result= null;
|
||||
|
||||
IBinding owner = callee.getOwner();
|
||||
if (owner != null) {
|
||||
List<? extends IBinding> specializedOwners= findSpecializations(owner);
|
||||
if (!specializedOwners.isEmpty()) {
|
||||
result= new ArrayList<IBinding>(specializedOwners.size());
|
||||
|
||||
for (IBinding specOwner : specializedOwners) {
|
||||
if (specOwner instanceof ICPPClassSpecialization) {
|
||||
result.add(((ICPPClassSpecialization) specOwner).specializeMember(callee));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callee instanceof ICPPInstanceCache) {
|
||||
final List<ICPPTemplateInstance> instances= Arrays.asList(((ICPPInstanceCache) callee).getAllInstances());
|
||||
if (!instances.isEmpty()) {
|
||||
if (result == null)
|
||||
result= new ArrayList<IBinding>(instances.size());
|
||||
|
||||
|
||||
for (ICPPTemplateInstance inst : instances) {
|
||||
if (!IndexFilter.ALL_DECLARED.acceptBinding(inst)) {
|
||||
result.add(inst);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static void findCalledBy2(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
|
||||
throws CoreException {
|
||||
|
|
|
@ -92,7 +92,6 @@ public class CHViewPart extends ViewPart {
|
|||
private static final String TRUE = String.valueOf(true);
|
||||
private static final String KEY_WORKING_SET_FILTER = "workingSetFilter"; //$NON-NLS-1$
|
||||
private static final String KEY_FILTER_VARIABLES = "variableFilter"; //$NON-NLS-1$
|
||||
// private static final String KEY_FILTER_MACROS = "macroFilter"; //$NON-NLS-1$
|
||||
private static final String KEY_SHOW_FILES= "showFilesInLabels"; //$NON-NLS-1$
|
||||
|
||||
private IMemento fMemento;
|
||||
|
@ -114,7 +113,6 @@ public class CHViewPart extends ViewPart {
|
|||
|
||||
// filters, sorter
|
||||
private ViewerFilter fVariableFilter;
|
||||
// private ViewerFilter fMacroFilter;
|
||||
private ViewerComparator fSorterAlphaNumeric;
|
||||
private ViewerComparator fSorterReferencePosition;
|
||||
private WorkingSetFilterUI fWorkingSetFilterUI;
|
||||
|
@ -123,7 +121,6 @@ public class CHViewPart extends ViewPart {
|
|||
private Action fReferencedByAction;
|
||||
private Action fMakesReferenceToAction;
|
||||
private Action fFilterVariablesAction;
|
||||
// private Action fFilterMacrosAction;
|
||||
private Action fShowFilesInLabelsAction;
|
||||
private Action fNextAction;
|
||||
private Action fPreviousAction;
|
||||
|
@ -252,12 +249,10 @@ public class CHViewPart extends ViewPart {
|
|||
private void initializeActionStates() {
|
||||
boolean referencedBy= true;
|
||||
boolean filterVariables= false;
|
||||
// boolean filterMacros= false;
|
||||
boolean showFiles= false;
|
||||
|
||||
if (fMemento != null) {
|
||||
filterVariables= TRUE.equals(fMemento.getString(KEY_FILTER_VARIABLES));
|
||||
// filterMacros= TRUE.equals(fMemento.getString(KEY_FILTER_MACROS));
|
||||
showFiles= TRUE.equals(fMemento.getString(KEY_SHOW_FILES));
|
||||
}
|
||||
|
||||
|
@ -268,8 +263,6 @@ public class CHViewPart extends ViewPart {
|
|||
fMakesReferenceToAction.setChecked(!referencedBy);
|
||||
fContentProvider.setComputeReferencedBy(referencedBy);
|
||||
|
||||
// fFilterMacrosAction.setChecked(filterMacros);
|
||||
// fFilterMacrosAction.run();
|
||||
fFilterVariablesAction.setChecked(filterVariables);
|
||||
fFilterVariablesAction.run();
|
||||
updateSorter();
|
||||
|
@ -287,7 +280,6 @@ public class CHViewPart extends ViewPart {
|
|||
if (fWorkingSetFilterUI != null) {
|
||||
fWorkingSetFilterUI.saveState(memento, KEY_WORKING_SET_FILTER);
|
||||
}
|
||||
// memento.putString(KEY_FILTER_MACROS, String.valueOf(fFilterMacrosAction.isChecked()));
|
||||
memento.putString(KEY_FILTER_VARIABLES, String.valueOf(fFilterVariablesAction.isChecked()));
|
||||
memento.putString(KEY_SHOW_FILES, String.valueOf(fShowFilesInLabelsAction.isChecked()));
|
||||
super.saveState(memento);
|
||||
|
@ -507,7 +499,6 @@ public class CHViewPart extends ViewPart {
|
|||
tm.add(fNextAction);
|
||||
tm.add(fPreviousAction);
|
||||
tm.add(new Separator());
|
||||
// tm.add(fFilterMacrosAction);
|
||||
tm.add(fFilterVariablesAction);
|
||||
tm.add(new Separator());
|
||||
tm.add(fReferencedByAction);
|
||||
|
@ -518,16 +509,12 @@ public class CHViewPart extends ViewPart {
|
|||
// local menu
|
||||
IMenuManager mm = actionBars.getMenuManager();
|
||||
|
||||
// tm.add(fNext);
|
||||
// tm.add(fPrevious);
|
||||
// tm.add(new Separator());
|
||||
fWorkingSetFilterUI.fillActionBars(actionBars);
|
||||
mm.add(fReferencedByAction);
|
||||
mm.add(fMakesReferenceToAction);
|
||||
mm.add(new Separator());
|
||||
mm.add(fShowFilesInLabelsAction);
|
||||
mm.add(new Separator());
|
||||
// mm.add(fFilterMacrosAction);
|
||||
mm.add(fFilterVariablesAction);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,13 @@ import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
|||
public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
||||
|
||||
private ISourceReference element;
|
||||
private String label;
|
||||
|
||||
public PDOMSearchElementQuery(ICElement[] scope, ISourceReference element, int flags) {
|
||||
super(scope, flags | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
|
||||
this.element = element;
|
||||
this.label= (element instanceof ICElement) ?
|
||||
((ICElement) element).getElementName() : CSearchMessages.PDOMSearchElementQuery_something;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,6 +47,7 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
|||
if (element instanceof ICElement) {
|
||||
IBinding binding= IndexUI.elementToBinding(index, (ICElement) element);
|
||||
if (binding != null) {
|
||||
label= labelForBinding(index, binding, label);
|
||||
createMatches(index, binding);
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +59,6 @@ public class PDOMSearchElementQuery extends PDOMSearchQuery {
|
|||
|
||||
@Override
|
||||
public String getResultLabel(int numMatches) {
|
||||
String pattern = (element instanceof ICElement) ?
|
||||
((ICElement) element).getElementName() : CSearchMessages.PDOMSearchElementQuery_something;
|
||||
return getResultLabel(pattern, numMatches);
|
||||
return getResultLabel(label, numMatches);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,12 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -30,6 +33,7 @@ import org.eclipse.core.runtime.Status;
|
|||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.search.ui.ISearchQuery;
|
||||
import org.eclipse.search.ui.ISearchResult;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
|
@ -54,11 +58,13 @@ import org.eclipse.cdt.core.index.IndexLocationFactory;
|
|||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.util.CElementBaseLabels;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.browser.ASTTypeInfo;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.search.LineSearchElement.Match;
|
||||
import org.eclipse.cdt.internal.ui.util.Messages;
|
||||
|
@ -72,6 +78,12 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
public static final int FIND_DECLARATIONS_DEFINITIONS = FIND_DECLARATIONS | FIND_DEFINITIONS;
|
||||
public static final int FIND_ALL_OCCURANCES = FIND_DECLARATIONS | FIND_DEFINITIONS | FIND_REFERENCES;
|
||||
|
||||
protected final static int LABEL_FLAGS=
|
||||
CElementBaseLabels.M_PARAMETER_TYPES |
|
||||
CElementBaseLabels.ALL_FULLY_QUALIFIED |
|
||||
CElementBaseLabels.TEMPLATE_ARGUMENTS;
|
||||
|
||||
|
||||
protected PDOMSearchResult result = new PDOMSearchResult(this);
|
||||
protected int flags;
|
||||
|
||||
|
@ -111,6 +123,18 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
}
|
||||
}
|
||||
|
||||
protected String labelForBinding(final IIndex index, IBinding binding, String defaultLabel) throws CoreException {
|
||||
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS_DEFINITIONS);
|
||||
if (names.length > 0) {
|
||||
ICElementHandle elem= IndexUI.getCElementForName((ICProject) null, index, names[0]);
|
||||
if (elem != null) {
|
||||
return CElementBaseLabels.getElementLabel(elem, LABEL_FLAGS);
|
||||
}
|
||||
}
|
||||
return defaultLabel;
|
||||
}
|
||||
|
||||
|
||||
public String getLabel() {
|
||||
String type;
|
||||
if ((flags & FIND_REFERENCES) != 0)
|
||||
|
@ -128,12 +152,13 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
// Report pattern and number of matches
|
||||
String label;
|
||||
if ((flags & FIND_REFERENCES) != 0)
|
||||
label = CSearchMessages.bind(CSearchMessages.PDOMSearchQuery_refs_result_label, pattern);
|
||||
label = NLS.bind(CSearchMessages.PDOMSearchQuery_refs_result_label, pattern);
|
||||
else if ((flags & FIND_DECLARATIONS) != 0)
|
||||
label =CSearchMessages.bind(CSearchMessages.PDOMSearchQuery_decls_result_label, pattern);
|
||||
label = NLS.bind(CSearchMessages.PDOMSearchQuery_decls_result_label, pattern);
|
||||
else
|
||||
label = CSearchMessages.bind(CSearchMessages.PDOMSearchQuery_defs_result_label, pattern);
|
||||
String countLabel = Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(matchCount));
|
||||
label = NLS.bind(CSearchMessages.PDOMSearchQuery_defs_result_label, pattern);
|
||||
String countLabel = Messages.format(CSearchMessages.CSearchResultCollector_matches, new Integer(
|
||||
matchCount));
|
||||
return label + " " + countLabel; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
@ -159,7 +184,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
return false; // i.e. keep it
|
||||
}
|
||||
|
||||
private void createMatchesFromNames(IIndex index, Map<IIndexFile, Set<Match>> fileMatches, IIndexName[] names, boolean isPolymorphicOnly)
|
||||
private void createMatchesFromNames(IIndex index, Map<IIndexFile, Set<Match>> fileMatches, Collection<IIndexName> names, boolean isPolymorphicOnly)
|
||||
throws CoreException {
|
||||
if (names == null)
|
||||
return;
|
||||
|
@ -212,7 +237,7 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
return matches;
|
||||
}
|
||||
|
||||
private void collectNames(IIndex index, IIndexName[] names, IIndexName[] polymorphicNames) throws CoreException {
|
||||
private void collectNames(IIndex index, Collection<IIndexName> names, Collection<IIndexName> polymorphicNames) throws CoreException {
|
||||
// group all matched names by files
|
||||
Map<IIndexFile, Set<Match>> fileMatches = new HashMap<IIndexFile, Set<Match>>();
|
||||
createMatchesFromNames(index, fileMatches, names, false);
|
||||
|
@ -271,27 +296,30 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
protected void createMatches(IIndex index, IBinding[] bindings) throws CoreException {
|
||||
if (bindings == null)
|
||||
return;
|
||||
IIndexName[] names= null;
|
||||
IIndexName[] polymorphicNames= null;
|
||||
List<IIndexName> names= new ArrayList<IIndexName>();
|
||||
List<IIndexName> polymorphicNames= null;
|
||||
for (IBinding binding : bindings) {
|
||||
if (binding != null) {
|
||||
IIndexName[] bindingNames= index.findNames(binding, flags);
|
||||
if (names == null) {
|
||||
names = bindingNames;
|
||||
} else {
|
||||
names= (IIndexName[]) ArrayUtil.addAll(IIndexName.class, names, bindingNames);
|
||||
}
|
||||
createMatches1(index, binding, names);
|
||||
|
||||
if ((flags & FIND_REFERENCES) != 0) {
|
||||
List<? extends IBinding> specializations = IndexUI.findSpecializations(binding);
|
||||
if (!specializations.isEmpty()) {
|
||||
for (IBinding spec : specializations) {
|
||||
createMatches1(index, spec, names);
|
||||
}
|
||||
}
|
||||
|
||||
if (binding instanceof ICPPMethod) {
|
||||
ICPPMethod m= (ICPPMethod) binding;
|
||||
try {
|
||||
ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m);
|
||||
for (ICPPMethod mInBase : msInBases) {
|
||||
bindingNames= index.findNames(mInBase, FIND_REFERENCES);
|
||||
if (msInBases.length > 0) {
|
||||
if (polymorphicNames == null) {
|
||||
polymorphicNames = bindingNames;
|
||||
} else {
|
||||
polymorphicNames= (IIndexName[]) ArrayUtil.addAll(IIndexName.class, names, bindingNames);
|
||||
polymorphicNames= new ArrayList<IIndexName>();
|
||||
}
|
||||
for (ICPPMethod mInBase : msInBases) {
|
||||
createMatches1(index, mInBase, polymorphicNames);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
|
@ -301,11 +329,16 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (names != null) {
|
||||
if (!names.isEmpty()) {
|
||||
collectNames(index, names, polymorphicNames);
|
||||
}
|
||||
}
|
||||
|
||||
private void createMatches1(IIndex index, IBinding binding, List<IIndexName> names) throws CoreException {
|
||||
IIndexName[] bindingNames= index.findNames(binding, flags);
|
||||
names.addAll(Arrays.asList(bindingNames));
|
||||
}
|
||||
|
||||
protected void createLocalMatches(IASTTranslationUnit ast, IBinding binding) {
|
||||
if (binding != null) {
|
||||
Set<IASTName> names= new HashSet<IASTName>();
|
||||
|
|
|
@ -25,7 +25,9 @@ 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;
|
||||
|
@ -38,16 +40,15 @@ import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
|||
* Query for searching the index based on a text selection.
|
||||
*/
|
||||
public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
||||
|
||||
private ITranslationUnit tu;
|
||||
private ITextSelection selection;
|
||||
private String searchText;
|
||||
private String label;
|
||||
|
||||
public PDOMSearchTextSelectionQuery(ICElement[] scope, ITranslationUnit tu, ITextSelection selection, int flags) {
|
||||
super(scope, flags | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
|
||||
this.tu = tu;
|
||||
this.selection = selection;
|
||||
this.searchText= selection.getText();
|
||||
this.label= selection.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +58,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
|||
if (ast != null) {
|
||||
IASTName searchName= ast.getNodeSelector(null).findEnclosingName(selection.getOffset(), selection.getLength());
|
||||
if (searchName != null) {
|
||||
searchText= searchName.toString();
|
||||
label= searchName.toString();
|
||||
IBinding binding= searchName.resolveBinding();
|
||||
if (binding instanceof IProblemBinding == false) {
|
||||
if (binding != null) {
|
||||
|
@ -72,7 +73,9 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
|
|||
}
|
||||
}
|
||||
binding = index.findBinding(searchName);
|
||||
binding= findDeclarationForSpecialization(binding);
|
||||
if (binding != null) {
|
||||
label= labelForBinding(index, binding, label);
|
||||
createMatches(index, binding);
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
@ -81,11 +84,27 @@ 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResultLabel(int numMatches) {
|
||||
return getResultLabel(searchText, numMatches);
|
||||
return getResultLabel(label, numMatches);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -51,12 +54,14 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
|||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
|
@ -80,6 +85,7 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
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;
|
||||
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
|
||||
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
|
||||
|
@ -108,8 +114,7 @@ public class IndexUI {
|
|||
String name= element.getElementName();
|
||||
name= name.substring(name.lastIndexOf(':')+1);
|
||||
IIndexBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.ALL, new NullProgressMonitor());
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
IIndexBinding binding = bindings[i];
|
||||
for (IIndexBinding binding : bindings) {
|
||||
if (checkBinding(binding, element)) {
|
||||
return binding;
|
||||
}
|
||||
|
@ -187,16 +192,15 @@ public class IndexUI {
|
|||
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
|
||||
if (location != null) {
|
||||
IIndexFile[] files= index.getFiles(location);
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
IIndexFile file = files[i];
|
||||
for (IIndexFile file : files) {
|
||||
if (linkageID == -1 || file.getLinkageID() == linkageID) {
|
||||
String elementName= element.getElementName();
|
||||
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
||||
ISourceRange pos= sf.getSourceRange();
|
||||
IRegion region = getConvertedRegion(tu, file, pos.getIdStartPos()+idx, pos.getIdLength()-idx);
|
||||
IIndexName[] names= file.findNames(region.getOffset(), region.getLength());
|
||||
for (int j = 0; j < names.length; j++) {
|
||||
IIndexName name = names[j];
|
||||
for (IIndexName name2 : names) {
|
||||
IIndexName name = name2;
|
||||
if (!name.isReference() && elementName.endsWith(new String(name.getSimpleID()))) {
|
||||
return name;
|
||||
}
|
||||
|
@ -240,8 +244,7 @@ public class IndexUI {
|
|||
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
|
||||
if (location != null) {
|
||||
IIndexFile[] files= index.getFiles(location);
|
||||
for (int j=0; j<files.length; j++) {
|
||||
IIndexFile file= files[j];
|
||||
for (IIndexFile file : files) {
|
||||
String elementName= include.getElementName();
|
||||
ISourceRange pos= include.getSourceRange();
|
||||
IRegion region= getConvertedRegion(tu, file, pos.getIdStartPos(), pos.getIdLength());
|
||||
|
@ -249,8 +252,7 @@ public class IndexUI {
|
|||
IIndexInclude[] includes= index.findIncludes(file);
|
||||
int bestDiff= Integer.MAX_VALUE;
|
||||
IIndexInclude best= null;
|
||||
for (int i = 0; i < includes.length; i++) {
|
||||
IIndexInclude candidate = includes[i];
|
||||
for (IIndexInclude candidate : includes) {
|
||||
int diff= Math.abs(candidate.getNameOffset()- region.getOffset());
|
||||
if (diff > bestDiff) {
|
||||
break;
|
||||
|
@ -286,8 +288,7 @@ public class IndexUI {
|
|||
IIndexName[] defs= index.findNames(binding, IIndex.FIND_DEFINITIONS | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
|
||||
|
||||
ArrayList<ICElementHandle> result= new ArrayList<ICElementHandle>();
|
||||
for (int i = 0; i < defs.length; i++) {
|
||||
IIndexName in = defs[i];
|
||||
for (IIndexName in : defs) {
|
||||
ICElementHandle definition= getCElementForName((ICProject) null, index, in);
|
||||
if (definition != null) {
|
||||
result.add(definition);
|
||||
|
@ -379,8 +380,8 @@ public class IndexUI {
|
|||
throws CoreException {
|
||||
if (binding != null) {
|
||||
IIndexName[] names= index.findNames(binding, IIndex.FIND_DECLARATIONS);
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
ICElementHandle elem= getCElementForName(preferProject, index, names[i]);
|
||||
for (IIndexName name : names) {
|
||||
ICElementHandle elem= getCElementForName(preferProject, index, name);
|
||||
if (elem != null) {
|
||||
return elem;
|
||||
}
|
||||
|
@ -478,4 +479,48 @@ public class IndexUI {
|
|||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for all specializations that depend on the definition of the given binding.
|
||||
*/
|
||||
public static List<? extends IBinding> findSpecializations(IBinding binding) throws CoreException {
|
||||
try {
|
||||
List<IBinding> result= null;
|
||||
|
||||
IBinding owner = binding.getOwner();
|
||||
if (owner != null) {
|
||||
List<? extends IBinding> specializedOwners= findSpecializations(owner);
|
||||
if (!specializedOwners.isEmpty()) {
|
||||
result= new ArrayList<IBinding>(specializedOwners.size());
|
||||
|
||||
for (IBinding specOwner : specializedOwners) {
|
||||
if (specOwner instanceof ICPPClassSpecialization) {
|
||||
result.add(((ICPPClassSpecialization) specOwner).specializeMember(binding));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (binding instanceof ICPPInstanceCache) {
|
||||
final List<ICPPTemplateInstance> instances= Arrays.asList(((ICPPInstanceCache) binding).getAllInstances());
|
||||
if (!instances.isEmpty()) {
|
||||
if (result == null)
|
||||
result= new ArrayList<IBinding>(instances.size());
|
||||
|
||||
|
||||
for (ICPPTemplateInstance inst : instances) {
|
||||
if (!IndexFilter.ALL_DECLARED.acceptBinding(inst)) {
|
||||
result.add(inst);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue