Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Ryall2008-01-18 17:13:23 -0500
committerKen Ryall2008-01-18 17:13:23 -0500
commit9e24550b25d13b85fb08a26813d22f515391edc2 (patch)
tree429240d11a708951000f8b7b11b63f6f1892aa9c
parent950ecfb8acdb7e9f29f0b36284b45cd88a1380bf (diff)
downloadorg.eclipse.cdt-9e24550b25d13b85fb08a26813d22f515391edc2.tar.gz
org.eclipse.cdt-9e24550b25d13b85fb08a26813d22f515391edc2.tar.xz
org.eclipse.cdt-9e24550b25d13b85fb08a26813d22f515391edc2.zip
Bug 212166, search bug fixes.
-rw-r--r--core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java4
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java147
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties10
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/IPDOMSearchContentProvider.java30
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java55
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListContentProvider.java72
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java1
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java22
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java22
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeContentProvider.java19
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java11
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java70
12 files changed, 441 insertions, 22 deletions
diff --git a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java
index fb7b880d10..84b7519994 100644
--- a/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java
+++ b/core/org.eclipse.cdt.core/browser/org/eclipse/cdt/internal/core/browser/util/IndexModelUtil.java
@@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration;
+import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.ITypedef;
@@ -132,6 +133,9 @@ public class IndexModelUtil {
if (binding instanceof IVariable) {
elementType = ICElement.C_VARIABLE;
}
+ if (binding instanceof IEnumerator) {
+ elementType = ICElement.C_ENUMERATOR;
+ }
return elementType;
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java
index a88633c8d7..cc89d7d6e3 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/search/BasicSearchTest.java
@@ -9,6 +9,7 @@
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
* IBM Corporation
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.search;
@@ -21,6 +22,7 @@ import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.operation.IRunnableContext;
@@ -38,6 +40,7 @@ import org.osgi.framework.Bundle;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
+import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
@@ -114,24 +117,148 @@ public class BasicSearchTest extends BaseUITestCase {
StructuredViewer viewer= pdomsvp.getViewer();
ILabelProvider labpv= (ILabelProvider) viewer.getLabelProvider();
IStructuredContentProvider scp= (IStructuredContentProvider) viewer.getContentProvider();
-
- String label0= labpv.getText(scp.getElements(result)[0]);
- String label1= labpv.getText(scp.getElements(result)[1]);
-
- // the content provider does not sort the result, so we have to do it:
- if (label0.compareTo(label1) < 0) {
- String h= label0; label0= label1; label1= h;
- }
+
+ // project results are in a project node, containing directories and files
+ Object[] resultElements = scp.getElements(result);
+ String label0= labpv.getText(resultElements[0]);
+ // external results are in a tree, directory containing files
+ Object externalResult = resultElements[1];
+ String path1= labpv.getText(externalResult);
+ String file1= labpv.getText(scp.getElements(externalResult)[0]);
// check the results are rendered
String expected0= fCProject.getProject().getName();
String expected1= new Path(externalFile.getAbsolutePath()).toString();
assertEquals(expected0,label0);
- assertEquals(expected1,label1);
+ assertEquals(expected1,new Path(path1).append(file1).toString());
}
+
+ // int x, y, xx, yy;
+ public void testNoIndexerEnabled_158955() throws Exception {
+ // rebuild the index with no indexer
+ CCorePlugin.getIndexManager().setIndexerId(fCProject, IIndexManager.ID_NO_INDEXER);
+ CCorePlugin.getIndexManager().reindex(fCProject);
+ assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
+
+ // open a query
+ PDOMSearchQuery query= makeProjectQuery("x");
+ PDOMSearchResult result= runQuery(query);
+ assertEquals(0, result.getElements().length);
+
+ ISearchResultViewPart vp= NewSearchUI.getSearchResultView();
+ ISearchResultPage page= vp.getActivePage();
+ assertTrue(""+page, page instanceof PDOMSearchViewPage);
+
+ PDOMSearchViewPage pdomsvp= (PDOMSearchViewPage) page;
+ StructuredViewer viewer= pdomsvp.getViewer();
+ ILabelProvider labpv= (ILabelProvider) viewer.getLabelProvider();
+ IStructuredContentProvider scp= (IStructuredContentProvider) viewer.getContentProvider();
+
+ // first result is a project node
+ Object firstRootNode = scp.getElements(result)[0];
+ String label0= labpv.getText(firstRootNode);
+ // ... containing a status message
+ IStatus firstRootChildNode= (IStatus) scp.getElements(firstRootNode)[0];
+
+ assertEquals(IStatus.WARNING, firstRootChildNode.getSeverity());
+ // can't really verify text in case message is localized...
+ }
+
+ final int INDEXER_IN_PROGRESS_FILE_COUNT = 10;
+ final int INDEXER_IN_PROGRESS_STRUCT_COUNT = 100;
+
+ // #include "hugeHeader0.h"
+
+ public void testIndexerInProgress() throws Exception {
+ // make an external file
+ File dir= CProjectHelper.freshDir();
+
+ // make other project files so we can get incomplete results during indexing
+ for (int i = 1; i < 10; i++) {
+ TestSourceReader.createFile(fCProject.getProject(), new Path("references" + i + ".cpp"),
+ "#include \"hugeHeader" + i + ".h\"\n");
+ }
+
+ for (int f = 0; f < INDEXER_IN_PROGRESS_FILE_COUNT; f++) {
+ File externalFile= new File(dir, "hugeHeader" + f + ".h");
+ externalFile.deleteOnExit();
+ FileWriter fw= new FileWriter(externalFile);
+ for (int i = 0; i < INDEXER_IN_PROGRESS_STRUCT_COUNT; i++) {
+ fw.write("typedef struct confusingType_" + f + "_" + i + " {\n");
+ if (i == 0)
+ fw.write(" void *data" + i + ";\n");
+ else
+ fw.write(" myConfusingType_" + f + "_" + (i-1) +" *data" + i + ";\n");
+ fw.write(" int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;\n");
+ fw.write("} myConfusingType_" + f + "_" + i + ";\n");
+ }
+ fw.close();
+ }
+
+ // rebuild the index and DO NOT JOIN
+ TestScannerProvider.sIncludes= new String[] {dir.getAbsolutePath()};
+ CCorePlugin.getIndexManager().reindex(fCProject);
+
+ // immediate test, likely 0 matches
+ coreTestIndexerInProgress(false);
+
+ // wait some amount of time to get non-zero and hopefully non-complete results
+ Thread.sleep(500);
+ if (!CCorePlugin.getIndexManager().isIndexerIdle())
+ coreTestIndexerInProgress(false);
+
+ // now join and test again to get the full results
+ assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
+
+ coreTestIndexerInProgress(true);
+ }
+ /**
+ *
+ */
+ private void coreTestIndexerInProgress(boolean expectComplete) {
+ // open a query
+ PDOMSearchQuery query= makeProjectQuery("data*");
+ PDOMSearchResult result= runQuery(query);
+
+ final int maximumHits = INDEXER_IN_PROGRESS_FILE_COUNT * INDEXER_IN_PROGRESS_STRUCT_COUNT;
+ Object[] elements = result.getElements();
+ if (expectComplete)
+ assertEquals(maximumHits, elements.length);
+ else
+ assertTrue(maximumHits >= elements.length); // >= because may still be done
+
+ ISearchResultViewPart vp= NewSearchUI.getSearchResultView();
+ ISearchResultPage page= vp.getActivePage();
+ assertTrue(""+page, page instanceof PDOMSearchViewPage);
+
+ PDOMSearchViewPage pdomsvp= (PDOMSearchViewPage) page;
+ StructuredViewer viewer= pdomsvp.getViewer();
+ ILabelProvider labpv= (ILabelProvider) viewer.getLabelProvider();
+ IStructuredContentProvider scp= (IStructuredContentProvider) viewer.getContentProvider();
+
+ if (!expectComplete) {
+ // even if we don't think the indexer is complete, we can't be 100% sure
+ // the indexer didn't finish before the query started, so don't fail here
+ // if all the hits were found
+ if (elements.length < maximumHits) {
+ // first result is an IStatus indicating indexer was busy
+ IStatus firstRootNode = (IStatus) scp.getElements(result)[0];
+
+ assertEquals(IStatus.WARNING, firstRootNode.getSeverity());
+ // can't really verify text in case message is localized...
+ }
+ } else {
+ // must NOT have the IStatus
+ Object firstRootNode = scp.getElements(result)[0];
+
+ assertFalse(firstRootNode instanceof IStatus);
+ }
+
+ }
+
/**
- * Run the specified query, and return the result. When this method returns the
+ * Run the specified query, and return the result. When tehis method returns the
* search page will have been opened.
* @param query
* @return
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties
index e0e7ce1712..6638eb0e3f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchMessages.properties
@@ -7,6 +7,7 @@
#
# Contributors:
# IBM Corporation - initial API and implementation
+# Ed Swartz (Nokia)
###############################################################################
group.search=S&earch For
@@ -19,7 +20,7 @@ Search.Error.search.message=An error occurred during the search operation
# Examples of the display for the following value are
# "(1 match)", where {0} is 1 and "(5 matches)", where {0} is 2 or more.
-CSearchResultCollector.matches= ({0} {0, choice, 1\#match|2\#matches})
+CSearchResultCollector.matches= ({0} {0, choice, 0\#matches|1\#match|2\#matches})
CSearchResultCollector.done= Search done: {0}.
CSearchResultCollector.searching= Searching...
@@ -146,8 +147,15 @@ PDOMSearch.query.refs.label = Find references to
PDOMSearch.query.defs.label = Find definitions of
PDOMSearch.query.decls.label = Find declarations of
PDOMSearchPatternQuery.PatternQuery_labelPatternInScope={0} {1} in {2}
+PDOMSearchTreeContentProvider.IndexerNotEnabledWarning=(unknown results: indexer is not enabled)
+PDOMSearchTreeContentProvider.ProjectClosedWarning=(unknown results: project is closed)
+PDOMSearchListContentProvider.IndexerNotEnabledMessageFormat=(project ''{0}'' - unknown results: indexer is not enabled)
+PDOMSearchListContentProvider.ProjectClosedMessageFormat=(project ''{0}'' - unknown results: project is closed)
+PDOMSearchTreeLabelProvider.URIContainerLabel=URIs
+CSearchMessages.IndexRunningIncompleteWarning=(incomplete or inaccurate results: indexer was busy during search)
PDOMSearch.query.pattern.error = Illegal Search String
SelectionParseAction.FileOpenFailure.format=Could not open file ''{0}'', verify index is up-to-date
SelectionParseAction.SelectedTextNotSymbol.message=Selected text cannot be mapped to a symbol name
SelectionParseAction.SymbolNotFoundInIndex.format=Could not find symbol ''{0}'' in index
SelectionParseAction.IncludeNotFound.format=Could not find include file ''{0}'' on include paths
+PDOMSearchLabelProvider.FileAndPathFormat={0} ({1})
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/IPDOMSearchContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/IPDOMSearchContentProvider.java
index b47d4307fe..5469a90f23 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/IPDOMSearchContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/IPDOMSearchContentProvider.java
@@ -7,16 +7,46 @@
*
* Contributors:
* QNX - Initial API and implementation
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+import org.eclipse.cdt.ui.CUIPlugin;
+
/**
+ * The content in the tree and list views may be either:
+ * <p>
+ * IStatus - warnings or errors from the search<br>
+ * ICElement - for C/C++ elements, including TUs, folders, projects<br>
+ * IPath - directory container, full path<br>
+ * IIndexFileLocation - for file entries inside IPath directory containers<br>
+ * {@link IPDOMSearchContentProvider#URI_CONTAINER} - container for URIs
+ * URI - from IIndexFileLocations not resolvable to the local filesystem, under URI_CONTAINER<br>
* @author Doug Schaefer
+ * @author Ed Swartz
*
*/
public interface IPDOMSearchContentProvider {
+ /** This node encapsulates results in the search tree for results not resolvable to files. */
+ static Object URI_CONTAINER = new Object();
+
+ /** This node appears in the tree when the indexer was running during the search
+ * to warn the user that the results are suspicious.
+ * <p>
+ * TODO: it would be better if IIndexManager told us which projects specifically
+ * were being indexed at the time, so we could annotate per-project whose results are suspicious
+ * (which may be none at all for a given search).
+ * See the handling of {@link PDOMSearchResult#wasIndexerBusy()}.
+ */
+ static IStatus INCOMPLETE_RESULTS_NODE =
+ new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
+ CSearchMessages.getString("CSearchMessages.IndexRunningIncompleteWarning")); //$NON-NLS-1$
+
public void elementsChanged(Object[] elements);
public void clear();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
index 1da1106041..9ab080db05 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchLabelProvider.java
@@ -7,14 +7,20 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
+import java.net.URI;
+
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
@@ -25,7 +31,16 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
/**
+ * The content in the tree and list views may be either:
+ * <p>
+ * IStatus - warnings or errors from the search<br>
+ * ICElement - for C/C++ elements, including TUs, folders, projects<br>
+ * IPath - directory container, full path<br>
+ * IIndexFileLocation - for file entries inside IPath directory containers<br>
+ * {@link IPDOMSearchContentProvider#URI_CONTAINER} - container for URIs<br>
+ * URI - for IIndexFileLocations not resolvable to the local filesystem, under URI_CONTAINER<br>
* @author Doug Schaefer
+ * @author Ed Swartz
*
*/
public class PDOMSearchLabelProvider extends LabelProvider {
@@ -44,10 +59,33 @@ public class PDOMSearchLabelProvider extends LabelProvider {
if (element instanceof PDOMSearchElement)
return fTypeInfoLabelProvider.getImage(((PDOMSearchElement)element).getTypeInfo());
- if (element instanceof IIndexFileLocation) {
+ if (element instanceof IIndexFileLocation
+ || element instanceof URI) {
return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDE);
}
+ if (element == IPDOMSearchContentProvider.URI_CONTAINER) {
+ // TODO: perhaps a better icon?
+ return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDES_CONTAINER);
+ }
+
+ if (element instanceof IPath) {
+ return CPluginImages.get(CPluginImages.IMG_OBJS_INCLUDES_FOLDER);
+ }
+
+ if (element instanceof IStatus) {
+ IStatus status = (IStatus) element;
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ switch (status.getSeverity()) {
+ case IStatus.WARNING:
+ return sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
+ case IStatus.ERROR:
+ return sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
+ default:
+ return sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
+ }
+ }
+
return fCElementLabelProvider.getImage(element);
}
@@ -56,13 +94,26 @@ public class PDOMSearchLabelProvider extends LabelProvider {
return fTypeInfoLabelProvider.getText(((PDOMSearchElement)element).getTypeInfo());
}
+ if (element instanceof IPath) {
+ return ((IPath) element).toString();
+ }
+
if (element instanceof IIndexFileLocation) {
IPath path= IndexLocationFactory.getPath((IIndexFileLocation)element);
if(path!=null) {
- return path.toString();
+ // these are categorized into directories already
+ return path.lastSegment();
}
}
+ if (element instanceof URI) {
+ return ((URI)element).toString();
+ }
+
+ if (element instanceof IStatus) {
+ return ((IStatus) element).getMessage();
+ }
+
return fCElementLabelProvider.getText(element);
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListContentProvider.java
index 41a3138a7c..f64cbd8f39 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListContentProvider.java
@@ -7,14 +7,30 @@
*
* Contributors:
* QNX - Initial API and implementation
+ * Ed Swartz (Nokia)
*******************************************************************************/
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;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
+import com.ibm.icu.text.MessageFormat;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.ui.CUIPlugin;
+
/**
* @author Doug Schaefer
*
@@ -26,7 +42,60 @@ public class PDOMSearchListContentProvider implements
private PDOMSearchResult result;
public Object[] getElements(Object inputElement) {
- return result.getElements();
+ Set uncoveredProjects = new HashSet();
+
+ PDOMSearchResult result = (PDOMSearchResult) inputElement;
+
+ Object[] results = result.getElements();
+ List resultList = new ArrayList(Arrays.asList(results));
+
+ // see if indexer was busy
+ if (result.wasIndexerBusy()) {
+ resultList.add(IPDOMSearchContentProvider.INCOMPLETE_RESULTS_NODE);
+ }
+
+ // see which projects returned results
+ for (int i = 0; i < results.length; i++) {
+ if (results[i] instanceof PDOMSearchElement) {
+ PDOMSearchElement searchElement = (PDOMSearchElement) results[i];
+ String path = searchElement.getLocation().getFullPath();
+ if (path != null) {
+ uncoveredProjects.add(new Path(path).segment(0));
+ }
+ }
+ }
+
+ // add message for all the projects which have no results
+ ICProject[] projects = ((PDOMSearchQuery)result.getQuery()).getProjects();
+ for (int i = 0; i < projects.length; ++i) {
+ ICProject project = projects[i];
+ boolean foundProject = uncoveredProjects.contains(project.getProject().getName());
+ if (!foundProject) {
+ if (project.isOpen()) {
+ if (!CCorePlugin.getIndexManager().isProjectIndexed(project)) {
+ resultList.add(createUnindexedProjectWarningElement(project));
+ }
+ } else {
+ resultList.add(createClosedProjectWarningElement(project));
+ }
+ }
+ }
+
+ return resultList.toArray();
+ }
+
+ private Status createUnindexedProjectWarningElement(ICProject project) {
+ return new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
+ MessageFormat.format(
+ CSearchMessages.getString("PDOMSearchListContentProvider.IndexerNotEnabledMessageFormat"), //$NON-NLS-1$
+ new Object[] { project.getProject().getName() }));
+ }
+
+ private Status createClosedProjectWarningElement(ICProject project) {
+ return new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID,
+ MessageFormat.format(
+ CSearchMessages.getString("PDOMSearchListContentProvider.ProjectClosedMessageFormat"), //$NON-NLS-1$
+ new Object[] { project.getProject().getName() }));
}
public void dispose() {
@@ -35,6 +104,7 @@ public class PDOMSearchListContentProvider implements
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
this.viewer = (TableViewer)viewer;
result = (PDOMSearchResult)newInput;
+ viewer.refresh();
}
public void elementsChanged(Object[] elements) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java
index a74af57fe6..cc5a419f1c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchListLabelProvider.java
@@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
index b58b349d0e..5937ac4bb8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchQuery.java
@@ -32,6 +32,7 @@ import org.eclipse.cdt.core.index.IIndexName;
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.parser.util.ArrayUtil;
import org.eclipse.cdt.ui.CUIPlugin;
/**
@@ -59,7 +60,16 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
try {
if (scope == null) {
// All CDT projects in workspace
- projects = CoreModel.getDefault().getCModel().getCProjects();
+ ICProject[] allProjects = CoreModel.getDefault().getCModel().getCProjects();
+
+ // Filter out closed projects for this case
+ for (int i = 0; i < allProjects.length; i++) {
+ if (!allProjects[i].isOpen()) {
+ allProjects[i] = null;
+ }
+ }
+
+ projects = (ICProject[]) ArrayUtil.removeNulls(ICProject.class, allProjects);
} else {
Map projectMap = new HashMap();
@@ -131,6 +141,8 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
PDOMSearchResult result= (PDOMSearchResult) getSearchResult();
result.removeAll();
+ result.setIndexerBusy(!CCorePlugin.getIndexManager().isIndexerIdle());
+
try {
IIndex index= CCorePlugin.getIndexManager().getIndex(projects, 0);
try {
@@ -150,4 +162,12 @@ public abstract class PDOMSearchQuery implements ISearchQuery {
}
abstract protected IStatus runWithIndex(IIndex index, IProgressMonitor monitor);
+
+ /**
+ * Get the projects involved in the search.
+ * @return array, never <code>null</code>
+ */
+ public ICProject[] getProjects() {
+ return projects;
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java
index 9f6ddca18e..b6b97f8dc2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchResult.java
@@ -48,6 +48,7 @@ import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
public class PDOMSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
private PDOMSearchQuery query;
+ private boolean indexerBusy;
public PDOMSearchResult(PDOMSearchQuery query) {
super();
@@ -152,7 +153,11 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
}
public String getLabel() {
- return query.getLabel();
+ // report pattern and number of matches
+ String label = query.getLabel();
+ String countLabel = CSearchMessages.getFormattedString("CSearchResultCollector.matches", //$NON-NLS-1$
+ new Integer(getElements().length));
+ return label + " " + countLabel; //$NON-NLS-1$
}
public String getTooltip() {
@@ -167,4 +172,19 @@ public class PDOMSearchResult extends AbstractTextSearchResult implements IEdito
return query;
}
+ /**
+ * Remember whether the indexer was busy when the search was performed.
+ * @param b
+ */
+ public void setIndexerBusy(boolean b) {
+ this.indexerBusy = b;
+ }
+
+ /**
+ * Tell if the indexer was busy when search results were gathered.
+ */
+ public boolean wasIndexerBusy() {
+ return indexerBusy;
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeContentProvider.java
index a1e9e0537d..82150ccb9b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeContentProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeContentProvider.java
@@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -45,7 +46,7 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
private TreeViewer viewer;
private PDOMSearchResult result;
private Map tree = new HashMap();
-
+
public Object[] getChildren(Object parentElement) {
Set children = (Set)tree.get(parentElement);
if (children == null)
@@ -69,7 +70,7 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
}
public Object[] getElements(Object inputElement) {
- return getChildren(result);
+ return getChildren(inputElement);
}
public void dispose() {
@@ -117,8 +118,18 @@ public class PDOMSearchTreeContentProvider implements ITreeContentProvider, IPDO
}
}
if (!handled) {
- insertChild(element.getLocation(), element);
- insertChild(result, element.getLocation());
+ // insert a folder and then the file under that
+ IPath path = IndexLocationFactory.getAbsolutePath(location);
+ if (path != null) {
+ IPath directory = path.removeLastSegments(1);
+ insertChild(location, element);
+ insertChild(directory, location);
+ insertChild(result, directory);
+ } else {
+ // URI not representable as a file
+ insertChild(IPDOMSearchContentProvider.URI_CONTAINER, location.getURI());
+ insertChild(result, IPDOMSearchContentProvider.URI_CONTAINER);
+ }
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java
index 876861068a..b398b7db90 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchTreeLabelProvider.java
@@ -8,6 +8,7 @@
* Contributors:
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
@@ -25,8 +26,14 @@ public class PDOMSearchTreeLabelProvider extends PDOMSearchLabelProvider {
}
public String getText(Object element) {
- final String text= super.getText(element);
- final int count= getMatchCount(element);
+ String text;
+
+ if (element == IPDOMSearchContentProvider.URI_CONTAINER) {
+ text= CSearchMessages.getString("PDOMSearchTreeLabelProvider.URIContainerLabel"); //$NON-NLS-1$
+ } else {
+ text= super.getText(element);
+ }
+ int count= getMatchCount(element);
if (count == 0) {
return text;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java
index f558086b39..18805df10e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/PDOMSearchViewPage.java
@@ -7,15 +7,20 @@
*
* Contributors:
* QNX - Initial API and implementation
+ * Ed Swartz (Nokia)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
import org.eclipse.search.ui.text.Match;
import org.eclipse.ui.IEditorPart;
@@ -24,6 +29,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IndexLocationFactory;
+import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
@@ -54,14 +60,78 @@ public class PDOMSearchViewPage extends AbstractTextSearchViewPage {
contentProvider.clear();
}
+ /**
+ * Supply a sorter for the list and tree content providers to supply some order to the
+ * large numbers of matches that may result.
+ * <p>
+ * This sorter categorizes the different kinds of ICElement matches (as well as IStatus
+ * messages and External Files groups) to place them in groups. The items within a
+ * category are sorted in the default way {@link ViewerSorter#compare(Viewer, Object, Object)} works,
+ * by comparing text labels.
+ * <p>
+ * A potential concern here is that, in sorting the elements by name, the user may
+ * find himself randomly jumping around a file when navigating search results in order.
+ * As this only happens when a search matches different identifiers or identifiers of
+ * different types, and since the user can use a textual search within a file to navigate
+ * the same results (ignoring extraneous hits in comments or disabled code), I argue it's not
+ * a big deal. Furthermore, usually it would be a wildcard search that would result in
+ * this situation -- indicating the user doesn't know the identifier and wants to find it using
+ * search. In such a case, a sorted list of results in much more friendly to navigate.
+ * @author eswartz
+ *
+ */
+ private class SearchViewerComparator extends ViewerComparator {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
+ */
+ public int category(Object element) {
+ // place status messages first
+ if (element instanceof IStatus) {
+ return -1000;
+ }
+
+ // keep elements of the same type together
+ if (element instanceof PDOMSearchElement) {
+ PDOMSearchElement searchElement = (PDOMSearchElement)element;
+ int type = searchElement.getTypeInfo().getCElementType();
+ // handle unknown types
+ if (type < 0) {
+ type = 0;
+ }
+ return type;
+ } else if (element instanceof ICElement) {
+ int type = ((ICElement) element).getElementType();
+ // handle unknown types
+ if (type < 0) {
+ type = 0;
+ }
+ return Math.min(Math.max(0, type), 900);
+ }
+
+ // place external folders next to last
+ if (element instanceof IPath || element instanceof IIndexFileLocation) {
+ return 999;
+ }
+
+ // place external file matches last
+ if (element == IPDOMSearchContentProvider.URI_CONTAINER) {
+ return 1000;
+ }
+
+ return 2000;
+ }
+ }
+
protected void configureTreeViewer(TreeViewer viewer) {
contentProvider = new PDOMSearchTreeContentProvider();
+ viewer.setComparator(new SearchViewerComparator());
viewer.setContentProvider((PDOMSearchTreeContentProvider)contentProvider);
viewer.setLabelProvider(new PDOMSearchTreeLabelProvider(this));
}
protected void configureTableViewer(TableViewer viewer) {
contentProvider = new PDOMSearchListContentProvider();
+ viewer.setComparator(new SearchViewerComparator());
viewer.setContentProvider((PDOMSearchListContentProvider)contentProvider);
viewer.setLabelProvider(new PDOMSearchListLabelProvider(this));
}

Back to the top