Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2004-06-28 05:16:32 +0000
committerBogdan Gheorghe2004-06-28 05:16:32 +0000
commitc95ad28dcb1bee02394baba20fef98ca279bebd6 (patch)
treef57b18cb692c818cb000a9a1f6c929e591363d6e
parentebd877b1da7f0a6aca51d6e5f46b530a10014cb3 (diff)
downloadorg.eclipse.cdt-c95ad28dcb1bee02394baba20fef98ca279bebd6.tar.gz
org.eclipse.cdt-c95ad28dcb1bee02394baba20fef98ca279bebd6.tar.xz
org.eclipse.cdt-c95ad28dcb1bee02394baba20fef98ca279bebd6.zip
Fix for Bug 67987: [Search] C Search results do no show up as editor annotations
-rw-r--r--core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java8
-rw-r--r--core/org.eclipse.cdt.ui/ChangeLog3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java81
3 files changed, 79 insertions, 13 deletions
diff --git a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
index 7d988ad9187..1ec06cbbdca 100644
--- a/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
+++ b/core/org.eclipse.cdt.core.tests/indexer/org/eclipse/cdt/core/indexer/tests/IndexManagerTests.java
@@ -167,7 +167,7 @@ public class IndexManagerTests extends TestCase {
assertTrue("Entry Results exist", eresults != null);
String [] queryResultModel = {"IndexedFile(1: /IndexerTestProject/mail.cpp)"};
- String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 1 }", "EntryResult: word=typeDecl/C/container, refs={ 1 }", "EntryResult: word=typeDecl/C/first_class, refs={ 1 }", "EntryResult: word=typeDecl/C/postcard, refs={ 1 }","EntryResult: word=typeDecl/D/Mail, refs={ 1 }", "EntryResult: word=typeDecl/D/first_class, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard, refs={ 1 }","EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }", "EntryResult: word=typeDecl/V/size, refs={ 1 }", "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }"};
+ String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 1 }", "EntryResult: word=typeDecl/C/container, refs={ 1 }", "EntryResult: word=typeDecl/C/first_class, refs={ 1 }", "EntryResult: word=typeDecl/C/postcard, refs={ 1 }","EntryResult: word=typeDecl/D/Mail, refs={ 1 }", "EntryResult: word=typeDecl/D/first_class, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard, refs={ 1 }","EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }", "EntryResult: word=typeDecl/V/index, refs={ 1 }", "EntryResult: word=typeDecl/V/mail, refs={ 1 }","EntryResult: word=typeDecl/V/size, refs={ 1 }", "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }"};
if (qresults.length != queryResultModel.length)
@@ -271,7 +271,7 @@ public class IndexManagerTests extends TestCase {
IEntryResult[] eresults = ind.queryEntries(prefix);
assertTrue("Entry result found for typdeDecl/", eresults != null);
- String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }", "EntryResult: word=typeDecl/C/Mail, refs={ 2 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 2 }", "EntryResult: word=typeDecl/C/container, refs={ 2 }", "EntryResult: word=typeDecl/C/first_class, refs={ 2 }", "EntryResult: word=typeDecl/C/postcard, refs={ 2 }", "EntryResult: word=typeDecl/D/Mail, refs={ 2 }", "EntryResult: word=typeDecl/D/first_class, refs={ 2 }", "EntryResult: word=typeDecl/D/postcard, refs={ 2 }","EntryResult: word=typeDecl/V/PO_Box, refs={ 2 }", "EntryResult: word=typeDecl/V/size, refs={ 2 }", "EntryResult: word=typeDecl/V/temp, refs={ 2 }", "EntryResult: word=typeDecl/V/x, refs={ 2 }"};
+ String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }", "EntryResult: word=typeDecl/C/Mail, refs={ 2 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 2 }", "EntryResult: word=typeDecl/C/container, refs={ 2 }", "EntryResult: word=typeDecl/C/first_class, refs={ 2 }", "EntryResult: word=typeDecl/C/postcard, refs={ 2 }", "EntryResult: word=typeDecl/D/Mail, refs={ 2 }", "EntryResult: word=typeDecl/D/first_class, refs={ 2 }", "EntryResult: word=typeDecl/D/postcard, refs={ 2 }", "EntryResult: word=typeDecl/V/, refs={ 1 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 2 }", "EntryResult: word=typeDecl/V/index, refs={ 2 }", "EntryResult: word=typeDecl/V/mail, refs={ 2 }", "EntryResult: word=typeDecl/V/size, refs={ 2 }", "EntryResult: word=typeDecl/V/temp, refs={ 2 }", "EntryResult: word=typeDecl/V/x, refs={ 2 }"};
if (eresults.length != entryResultBeforeModel.length)
fail("Entry Result length different from model");
@@ -291,7 +291,7 @@ public class IndexManagerTests extends TestCase {
eresults = ind.queryEntries(prefix);
assertTrue("Entry exists", eresults != null);
- String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }"};
+ String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }", "EntryResult: word=typeDecl/V/, refs={ 1 }"};
if (eresults.length != entryResultAfterModel.length)
fail("Entry Result length different from model");
@@ -314,7 +314,7 @@ public class IndexManagerTests extends TestCase {
IEntryResult[] typerefreesults = ind.queryEntries(IIndexConstants.TYPE_REF);
assertTrue("Type Ref Results exist", typerefreesults != null);
- String [] typeDeclEntryResultModel ={"EntryResult: word=typeDecl/C/Mail/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/Unknown/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/container/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/first_class/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/D/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/first_class/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/E/test/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/T/int32, refs={ 1 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }", "EntryResult: word=typeDecl/V/size, refs={ 1 }", "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }", "EntryResult: word=typeDecl/V/x/Z, refs={ 1 }"};
+ String [] typeDeclEntryResultModel ={"EntryResult: word=typeDecl/C/Mail/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/Unknown/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/container/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/first_class/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/C/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/D/Mail/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/first_class/Y/X/Z, refs={ 1 }", "EntryResult: word=typeDecl/D/postcard/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/E/test/Y/X/Z, refs={ 1 }","EntryResult: word=typeDecl/T/int32, refs={ 1 }", "EntryResult: word=typeDecl/V/PO_Box, refs={ 1 }","EntryResult: word=typeDecl/V/index, refs={ 1 }", "EntryResult: word=typeDecl/V/mail, refs={ 1 }", "EntryResult: word=typeDecl/V/size, refs={ 1 }", "EntryResult: word=typeDecl/V/temp, refs={ 1 }", "EntryResult: word=typeDecl/V/x, refs={ 1 }", "EntryResult: word=typeDecl/V/x/Z, refs={ 1 }"};
IEntryResult[] typedeclresults =ind.queryEntries(IIndexConstants.TYPE_DECL);
assertTrue("Type Decl Results exist", typedeclresults != null);
diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog
index 069cae7d53e..382f18400a0 100644
--- a/core/org.eclipse.cdt.ui/ChangeLog
+++ b/core/org.eclipse.cdt.ui/ChangeLog
@@ -1,3 +1,6 @@
+2004-06-27 Bogdan Gheorghe
+ Fix for Bug 67987: [Search] C Search results do no show up as editor annotations
+
2004-06-24 Hoda Amer
Changing Refactoring name collision from Error to FatalError
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java
index 4d1c29c0ecf..b5f64d13acc 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResult.java
@@ -22,11 +22,15 @@ import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
+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.IParent;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
@@ -42,8 +46,9 @@ import org.eclipse.ui.IFileEditorInput;
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
-public class CSearchResult extends AbstractTextSearchResult {
+public class CSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
CSearchQuery cQuery;
+ private static final Match[] NO_MATCHES= new Match[0];
public CSearchResult(CSearchQuery query){
cQuery = query;
@@ -101,7 +106,22 @@ public class CSearchResult extends AbstractTextSearchResult {
* @see org.eclipse.search.ui.text.AbstractTextSearchResult#isShownInEditor(org.eclipse.search.ui.text.Match, org.eclipse.ui.IEditorPart)
*/
public boolean isShownInEditor(Match match, IEditorPart editor) {
- // TODO Auto-generated method stub
+ IEditorInput editorInput= editor.getEditorInput();
+ if (match.getElement() instanceof BasicSearchMatch) {
+ BasicSearchMatch searchMatch = (BasicSearchMatch) match.getElement();
+ if (editorInput instanceof IFileEditorInput){
+ IFile inputFile= ((IFileEditorInput)editorInput).getFile();
+ IResource matchFile = searchMatch.getResource();
+ if (matchFile != null)
+ return inputFile.equals(matchFile);
+ else
+ return false;
+ }
+ } else if (match.getElement() instanceof IFile) {
+ if (editorInput instanceof IFileEditorInput) {
+ return ((IFileEditorInput)editorInput).getFile().equals(match.getElement());
+ }
+ }
return false;
}
/* (non-Javadoc)
@@ -112,12 +132,8 @@ public class CSearchResult extends AbstractTextSearchResult {
if (editorInput instanceof IFileEditorInput) {
IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput;
return findContainedMatches(fileEditorInput.getFile());
- } /*else if (editorInput instanceof IClassFileEditorInput) {
- IClassFileEditorInput classFileEditorInput= (IClassFileEditorInput) editorInput;
- Set matches= new HashSet();
- collectMatches(matches, classFileEditorInput.getClassFile());
- return (Match[]) matches.toArray(new Match[matches.size()]);
- }*/
+ }
+
return null;
}
/* (non-Javadoc)
@@ -171,7 +187,7 @@ public class CSearchResult extends AbstractTextSearchResult {
*/
public IEditorMatchAdapter getEditorMatchAdapter() {
// TODO Auto-generated method stub
- return null;
+ return this;
}
/* (non-Javadoc)
@@ -179,6 +195,53 @@ public class CSearchResult extends AbstractTextSearchResult {
*/
public IFileMatchAdapter getFileMatchAdapter() {
// TODO Auto-generated method stub
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.search.ui.text.IEditorMatchAdapter#computeContainedMatches(org.eclipse.search.ui.text.AbstractTextSearchResult, org.eclipse.ui.IEditorPart)
+ */
+ public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
+ IEditorInput editorInput= editor.getEditorInput();
+ if (editorInput instanceof IFileEditorInput) {
+ IFileEditorInput fileEditorInput= (IFileEditorInput) editorInput;
+ return computeContainedMatches(result, fileEditorInput.getFile());
+ }
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.search.ui.text.IFileMatchAdapter#computeContainedMatches(org.eclipse.search.ui.text.AbstractTextSearchResult, org.eclipse.core.resources.IFile)
+ */
+ public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
+ ICElement cElement= CoreModel.getDefault().create(file);
+ if (!(cElement instanceof ITranslationUnit))
+ return NO_MATCHES;
+ Set matches= new HashSet();
+ Object[] test=result.getElements();
+ collectMatches(matches, test, file);
+ return (Match[]) matches.toArray(new Match[matches.size()]);
+ }
+
+ /**
+ * @param matches
+ * @param test
+ * @param file
+ */
+ private void collectMatches(Set matches, Object[] test, IFile file) {
+
+ for (int i=0; i<test.length; i++){
+ BasicSearchMatch tempMatch = (BasicSearchMatch) test[i];
+ if (tempMatch.getResource().equals(file)){
+ Match[] m= getMatches(tempMatch);
+
+ if (m.length != 0) {
+ for (int j= 0; j < m.length; j++) {
+ matches.add(m[j]);
+ }
+ }
+ }
+ }
+ }
+
}

Back to the top