mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Include matches via polymorphic calls in search, bug 261484
This commit is contained in:
parent
5522695e6e
commit
cc06277186
9 changed files with 154 additions and 25 deletions
|
@ -79,6 +79,9 @@ public final class CSearchMessages extends NLS {
|
|||
public static String PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat;
|
||||
public static String PDOMSearchListContentProvider_ProjectClosedMessageFormat;
|
||||
public static String CSearchMessages_IndexRunningIncompleteWarning;
|
||||
public static String HidePolymorphicCalls_actionLabel;
|
||||
public static String HidePolymorphicCalls_description;
|
||||
public static String HidePolymorphicCalls_name;
|
||||
public static String PDOMSearchTreeContentProvider_IndexerNotEnabledWarning;
|
||||
public static String PDOMSearchTreeContentProvider_ProjectClosedWarning;
|
||||
public static String PDOMSearchUnresolvedIncludesQuery_title;
|
||||
|
|
|
@ -73,6 +73,9 @@ PDOMSearchTreeContentProvider_ProjectClosedWarning=(unknown results: project is
|
|||
PDOMSearchListContentProvider_IndexerNotEnabledMessageFormat=(project ''{0}'' - unknown results: indexer is not enabled)
|
||||
PDOMSearchListContentProvider_ProjectClosedMessageFormat=(project ''{0}'' - unknown results: project is closed)
|
||||
CSearchMessages_IndexRunningIncompleteWarning=(incomplete or inaccurate results: indexer was busy during search)
|
||||
HidePolymorphicCalls_actionLabel=Hide Potential Method Calls
|
||||
HidePolymorphicCalls_description=Hides potential method calls to virtual overriders
|
||||
HidePolymorphicCalls_name=Potential Method Calls
|
||||
PDOMSearch_query_pattern_error = Illegal Search String
|
||||
PDOMSearchUnresolvedIncludesQuery_title=Unresolved inclusions in {0}
|
||||
SelectionParseAction_FileOpenFailure_format=Could not open file ''{0}'', verify index is up-to-date
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import org.eclipse.search.ui.text.Match;
|
||||
import org.eclipse.search.ui.text.MatchFilter;
|
||||
|
||||
public class HidePolymorphicCalls extends MatchFilter {
|
||||
|
||||
public static final MatchFilter FILTER = new HidePolymorphicCalls();
|
||||
|
||||
@Override
|
||||
public boolean filters(Match match) {
|
||||
return match instanceof PDOMSearchMatch && ((PDOMSearchMatch) match).isPolymorphicCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionLabel() {
|
||||
return CSearchMessages.HidePolymorphicCalls_actionLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return CSearchMessages.HidePolymorphicCalls_description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "HidePolymorphicCalls"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return CSearchMessages.HidePolymorphicCalls_name;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,6 @@
|
|||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -40,6 +39,11 @@ public class PDOMSearchListContentProvider implements
|
|||
|
||||
private TableViewer viewer;
|
||||
private PDOMSearchResult result;
|
||||
private final PDOMSearchViewPage fPage;
|
||||
|
||||
PDOMSearchListContentProvider(PDOMSearchViewPage page) {
|
||||
fPage= page;
|
||||
}
|
||||
|
||||
public Object[] getElements(Object inputElement) {
|
||||
Set<String> uncoveredProjects = new HashSet<String>();
|
||||
|
@ -47,12 +51,7 @@ public class PDOMSearchListContentProvider implements
|
|||
PDOMSearchResult result = (PDOMSearchResult) inputElement;
|
||||
|
||||
Object[] results = result.getElements();
|
||||
List<Object> resultList = new ArrayList<Object>(Arrays.asList(results));
|
||||
|
||||
// see if indexer was busy
|
||||
if (result.wasIndexerBusy()) {
|
||||
resultList.add(IPDOMSearchContentProvider.INCOMPLETE_RESULTS_NODE);
|
||||
}
|
||||
List<Object> resultList = new ArrayList<Object>();
|
||||
|
||||
// see which projects returned results
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
|
@ -62,9 +61,17 @@ public class PDOMSearchListContentProvider implements
|
|||
if (path != null) {
|
||||
uncoveredProjects.add(new Path(path).segment(0));
|
||||
}
|
||||
if (fPage.getDisplayedMatchCount(searchElement) > 0) {
|
||||
resultList.add(searchElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// see if indexer was busy
|
||||
if (result.wasIndexerBusy()) {
|
||||
resultList.add(IPDOMSearchContentProvider.INCOMPLETE_RESULTS_NODE);
|
||||
}
|
||||
|
||||
// add message for all the projects which have no results
|
||||
ICProject[] projects = ((PDOMSearchQuery)result.getQuery()).getProjects();
|
||||
for (int i = 0; i < projects.length; ++i) {
|
||||
|
@ -112,7 +119,7 @@ public class PDOMSearchListContentProvider implements
|
|||
return;
|
||||
|
||||
for (int i= 0; i < elements.length; i++) {
|
||||
if (result.getMatchCount(elements[i]) > 0) {
|
||||
if (fPage.getDisplayedMatchCount(elements[i]) > 0) {
|
||||
if (viewer.testFindItem(elements[i]) != null)
|
||||
viewer.refresh(elements[i]);
|
||||
else
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
|
|||
*/
|
||||
public class PDOMSearchMatch extends Match {
|
||||
|
||||
private boolean fIsPolymorphicCall;
|
||||
|
||||
public PDOMSearchMatch(PDOMSearchElement elem, int offset, int length) {
|
||||
super(elem, offset, length);
|
||||
}
|
||||
|
@ -39,4 +41,12 @@ public class PDOMSearchMatch extends Match {
|
|||
&& getOffset() == other.getOffset()
|
||||
&& getLength() == other.getLength();
|
||||
}
|
||||
|
||||
public void setIsPolymorphicCall() {
|
||||
fIsPolymorphicCall= true;
|
||||
}
|
||||
|
||||
public boolean isPolymorphicCall() {
|
||||
return fIsPolymorphicCall;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,12 @@ import org.eclipse.search.ui.ISearchResult;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
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.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
|
@ -42,6 +44,7 @@ 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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -49,9 +52,9 @@ import org.eclipse.cdt.internal.core.browser.ASTTypeInfo;
|
|||
*
|
||||
*/
|
||||
public abstract class PDOMSearchQuery implements ISearchQuery {
|
||||
public static final int FIND_DECLARATIONS = 0x1;
|
||||
public static final int FIND_DEFINITIONS = 0x2;
|
||||
public static final int FIND_REFERENCES = 0x4;
|
||||
public static final int FIND_DECLARATIONS = IIndex.FIND_DECLARATIONS;
|
||||
public static final int FIND_DEFINITIONS = IIndex.FIND_DEFINITIONS;
|
||||
public static final int FIND_REFERENCES = IIndex.FIND_REFERENCES;
|
||||
public static final int FIND_DECLARATIONS_DEFINITIONS = FIND_DECLARATIONS | FIND_DEFINITIONS;
|
||||
public static final int FIND_ALL_OCCURANCES = FIND_DECLARATIONS | FIND_DEFINITIONS | FIND_REFERENCES;
|
||||
|
||||
|
@ -127,14 +130,20 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
return false; // i.e. keep it
|
||||
}
|
||||
|
||||
private void collectNames(IIndex index, IIndexName[] names) throws CoreException {
|
||||
private void collectNames(IIndex index, IIndexName[] names, boolean polymorphicCallsOnly) throws CoreException {
|
||||
for (IIndexName name : names) {
|
||||
if (!filterName(name)) {
|
||||
IASTFileLocation loc = name.getFileLocation();
|
||||
IIndexBinding binding= index.findBinding(name);
|
||||
result.addMatch(new PDOMSearchMatch(
|
||||
new TypeInfoSearchElement(index, name, binding),
|
||||
loc.getNodeOffset(), loc.getNodeLength()));
|
||||
if (!polymorphicCallsOnly || name.couldBePolymorphicMethodCall()) {
|
||||
IASTFileLocation loc = name.getFileLocation();
|
||||
IIndexBinding binding= index.findBinding(name);
|
||||
final PDOMSearchMatch match = new PDOMSearchMatch(
|
||||
new TypeInfoSearchElement(index, name, binding),
|
||||
loc.getNodeOffset(), loc.getNodeLength());
|
||||
if (polymorphicCallsOnly)
|
||||
match.setIsPolymorphicCall();
|
||||
|
||||
result.addMatch(match);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +151,21 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
|
|||
protected void createMatches(IIndex index, IBinding binding) throws CoreException {
|
||||
if (binding != null) {
|
||||
IIndexName[] names= index.findNames(binding, flags);
|
||||
collectNames(index, names);
|
||||
collectNames(index, names, false);
|
||||
if ((flags & FIND_REFERENCES) != 0) {
|
||||
if (binding instanceof ICPPMethod) {
|
||||
ICPPMethod m= (ICPPMethod) binding;
|
||||
try {
|
||||
ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m);
|
||||
for (ICPPMethod mInBase : msInBases) {
|
||||
names= index.findNames(mInBase, FIND_REFERENCES);
|
||||
collectNames(index, names, true);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.search.ui.text.AbstractTextSearchResult;
|
|||
import org.eclipse.search.ui.text.IEditorMatchAdapter;
|
||||
import org.eclipse.search.ui.text.IFileMatchAdapter;
|
||||
import org.eclipse.search.ui.text.Match;
|
||||
import org.eclipse.search.ui.text.MatchFilter;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IPathEditorInput;
|
||||
|
@ -47,6 +48,9 @@ import org.eclipse.cdt.internal.ui.util.Messages;
|
|||
*
|
||||
*/
|
||||
public class PDOMSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
|
||||
private static final String KEY_SHOW_POLYMORPHIC_CALLS = "ShowPolymorphicCalls"; //$NON-NLS-1$
|
||||
final static MatchFilter[] ALL_FILTERS = new MatchFilter[] {HidePolymorphicCalls.FILTER};
|
||||
final static MatchFilter[] NO_FILTERS = {};
|
||||
|
||||
private PDOMSearchQuery query;
|
||||
private boolean indexerBusy;
|
||||
|
@ -190,4 +194,32 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
|
|||
return indexerBusy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatchFilter[] getAllMatchFilters() {
|
||||
return ALL_FILTERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MatchFilter[] getActiveMatchFilters() {
|
||||
MatchFilter[] result = super.getActiveMatchFilters();
|
||||
if (result == null) {
|
||||
if (CUIPlugin.getDefault().getDialogSettings().getBoolean(KEY_SHOW_POLYMORPHIC_CALLS)) {
|
||||
return ALL_FILTERS;
|
||||
}
|
||||
return NO_FILTERS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveMatchFilters(MatchFilter[] filters) {
|
||||
boolean showPoly= false;
|
||||
for (int i = 0; i < filters.length; i++) {
|
||||
if (filters[i] == HidePolymorphicCalls.FILTER) {
|
||||
showPoly= true;
|
||||
}
|
||||
}
|
||||
CUIPlugin.getDefault().getDialogSettings().put(KEY_SHOW_POLYMORPHIC_CALLS, showPoly);
|
||||
super.setActiveMatchFilters(filters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,11 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
|||
private TreeViewer viewer;
|
||||
private PDOMSearchResult result;
|
||||
private Map<Object, Set<Object>> tree = new HashMap<Object, Set<Object>>();
|
||||
private final PDOMSearchViewPage fPage;
|
||||
|
||||
PDOMSearchTreeContentProvider(PDOMSearchViewPage page) {
|
||||
fPage= page;
|
||||
}
|
||||
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
Set<Object> children = tree.get(parentElement);
|
||||
|
@ -170,7 +175,7 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
|||
if (elements != null) {
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
PDOMSearchElement element = (PDOMSearchElement)elements[i];
|
||||
if (result.getMatchCount(element) > 0) {
|
||||
if (fPage.getDisplayedMatchCount(element) > 0) {
|
||||
insertSearchElement(element);
|
||||
} else {
|
||||
boolean remove = true;
|
||||
|
@ -217,7 +222,9 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
|
|||
|
||||
Object[] elements = result.getElements();
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
insertSearchElement((PDOMSearchElement)elements[i]);
|
||||
final PDOMSearchElement element = (PDOMSearchElement)elements[i];
|
||||
if (fPage.getDisplayedMatchCount(element) > 0)
|
||||
insertSearchElement(element);
|
||||
}
|
||||
|
||||
// add all the projects which have no results
|
||||
|
|
|
@ -125,7 +125,7 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
|||
|
||||
@Override
|
||||
protected void configureTreeViewer(TreeViewer viewer) {
|
||||
contentProvider = new PDOMSearchTreeContentProvider();
|
||||
contentProvider = new PDOMSearchTreeContentProvider(this);
|
||||
viewer.setComparator(new SearchViewerComparator());
|
||||
viewer.setContentProvider((PDOMSearchTreeContentProvider)contentProvider);
|
||||
viewer.setLabelProvider(new PDOMSearchTreeLabelProvider(this));
|
||||
|
@ -133,7 +133,7 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
|
|||
|
||||
@Override
|
||||
protected void configureTableViewer(TableViewer viewer) {
|
||||
contentProvider = new PDOMSearchListContentProvider();
|
||||
contentProvider = new PDOMSearchListContentProvider(this);
|
||||
viewer.setComparator(new SearchViewerComparator());
|
||||
viewer.setContentProvider((PDOMSearchListContentProvider)contentProvider);
|
||||
viewer.setLabelProvider(new PDOMSearchListLabelProvider(this));
|
||||
|
|
Loading…
Add table
Reference in a new issue