diff options
author | Thomas Maeder | 2004-05-21 10:05:22 +0000 |
---|---|---|
committer | Thomas Maeder | 2004-05-21 10:05:22 +0000 |
commit | 119c549d121df1d8ea78653187b31a73a001e749 (patch) | |
tree | 74f9dd721ecc23104351a6f3e0f7baca6d5ccf2a /org.eclipse.search.tests/src | |
parent | 3d4fcd459de67b8f4d22bcffb291d161de727a3a (diff) | |
download | eclipse.platform.text-119c549d121df1d8ea78653187b31a73a001e749.tar.gz eclipse.platform.text-119c549d121df1d8ea78653187b31a73a001e749.tar.xz eclipse.platform.text-119c549d121df1d8ea78653187b31a73a001e749.zip |
fix for bug 63379
Diffstat (limited to 'org.eclipse.search.tests/src')
5 files changed, 163 insertions, 0 deletions
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java index 62761da7e05..d9aab2fa43d 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/SearchTestPlugin.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.util.zip.ZipFile; + import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.IProgressMonitor; diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java index d9ca5e723be..05e85884d7b 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AllFileSearchTests.java @@ -21,6 +21,7 @@ public class AllFileSearchTests extends TestSuite { public AllFileSearchTests() { addTest(AnnotationManagerTest.allTests()); + addTest(LineAnnotationManagerTest.allTests()); addTest(SearchResultPageTest.allTests()); addTest(ResultUpdaterTest.allTests()); addTest(SortingTest.allTests()); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java index 04b84e526d4..0cafbeaa1a7 100644 --- a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/AnnotationManagerTest.java @@ -17,6 +17,7 @@ import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; +import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; @@ -31,6 +32,7 @@ import org.eclipse.search.ui.text.AbstractTextSearchResult; import org.eclipse.search.ui.text.Match; import org.eclipse.search2.internal.ui.InternalSearchUI; import org.eclipse.search2.internal.ui.text.AnnotationManager; +import org.eclipse.search2.internal.ui.text.PositionTracker; import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.ide.IDE; import org.eclipse.ui.texteditor.AnnotationTypeLookup; @@ -39,6 +41,8 @@ import org.eclipse.ui.texteditor.ITextEditor; public class AnnotationManagerTest extends TestCase { FileSearchQuery fQuery1; FileSearchQuery fQuery2; + + LineBasedFileSearch fLineQuery; private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup(); @@ -65,12 +69,15 @@ public class AnnotationManagerTest extends TestCase { scope.addExtension("*.java"); fQuery1= new FileSearchQuery(scope, "", "Test"); fQuery2= new FileSearchQuery(scope, "", "TestCase"); + + fLineQuery= new LineBasedFileSearch(scope, "", "Test"); } protected void tearDown() throws Exception { InternalSearchUI.getInstance().removeAllQueries(); fQuery1= null; fQuery2= null; + fLineQuery= null; super.tearDown(); } @@ -102,6 +109,11 @@ public class AnnotationManagerTest extends TestCase { } } + private Position computeDocumentPositionFromLineMatch(IDocument document, Match match) throws BadLocationException { + Position p= new Position(match.getOffset(), match.getLength()); + return PositionTracker.convertToCharacterPosition(p, document); + } + public void testBogusAnnotation() throws Exception { NewSearchUI.activateSearchResultView(); NewSearchUI.runQueryInForeground(null, fQuery1); diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java new file mode 100644 index 00000000000..4783246dc93 --- /dev/null +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineAnnotationManagerTest.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.search.tests.filesearch; + +import java.util.HashSet; +import java.util.Iterator; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.search.internal.core.text.TextSearchScope; +import org.eclipse.search.tests.SearchTestPlugin; +import org.eclipse.search.ui.NewSearchUI; +import org.eclipse.search.ui.SearchUI; +import org.eclipse.search.ui.text.AbstractTextSearchResult; +import org.eclipse.search.ui.text.Match; +import org.eclipse.search2.internal.ui.InternalSearchUI; +import org.eclipse.search2.internal.ui.text.AnnotationManager; +import org.eclipse.search2.internal.ui.text.PositionTracker; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.texteditor.AnnotationTypeLookup; +import org.eclipse.ui.texteditor.ITextEditor; + +public class LineAnnotationManagerTest extends TestCase { + LineBasedFileSearch fLineQuery; + + private AnnotationTypeLookup fAnnotationTypeLookup= EditorsUI.getAnnotationTypeLookup(); + + public LineAnnotationManagerTest(String name) { + super(name); + } + + public static Test allTests() { + TestSuite suite= new TestSuite(); + + suite.addTest(new JUnitSetup(new AnnotationManagerSetup(new TestSuite(LineAnnotationManagerTest.class), AnnotationManager.HIGHLIGHTER_ANNOTATION))); + return suite; + } + + public static Test suite() { + return allTests(); + } + + protected void setUp() throws Exception { + super.setUp(); + + TextSearchScope scope= TextSearchScope.newWorkspaceScope(); + scope.addExtension("*.java"); + + fLineQuery= new LineBasedFileSearch(scope, "", "Test"); + } + + protected void tearDown() throws Exception { + InternalSearchUI.getInstance().removeAllQueries(); + fLineQuery= null; + super.tearDown(); + } + + public void testLineBasedQuery() throws Exception { + NewSearchUI.activateSearchResultView(); + NewSearchUI.runQueryInForeground(null, fLineQuery); + AbstractTextSearchResult result= (AbstractTextSearchResult) fLineQuery.getSearchResult(); + Object[] files= result.getElements(); + for (int i= 0; i < files.length; i++) { + IFile file= (IFile) files[0]; + ITextEditor editor= (ITextEditor)IDE.openEditor(SearchTestPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, true); + IAnnotationModel annotationModel= editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput()); + IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput()); + annotationModel.getAnnotationIterator(); + HashSet positions= new HashSet(); + for (Iterator iter= annotationModel.getAnnotationIterator(); iter.hasNext();) { + Annotation annotation= (Annotation) iter.next(); + if (annotation.getType().equals(fAnnotationTypeLookup.getAnnotationType(SearchUI.SEARCH_MARKER, IMarker.SEVERITY_INFO))) { + positions.add(annotationModel.getPosition(annotation)); + } + } + + Match[] matches= result.getMatches(file); + for (int j= 0; j < matches.length; j++) { + + Position position= computeDocumentPositionFromLineMatch(document, matches[j]); + assertTrue("position not found at: "+j, positions.remove(position)); + } + assertEquals(0, positions.size()); + + } + } + + private Position computeDocumentPositionFromLineMatch(IDocument document, Match match) throws BadLocationException { + Position p= new Position(match.getOffset(), match.getLength()); + return PositionTracker.convertToCharacterPosition(p, document); + } + +} diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java new file mode 100644 index 00000000000..bd36289e6e9 --- /dev/null +++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/filesearch/LineBasedFileSearch.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.search.tests.filesearch; + +import org.eclipse.core.resources.IFile; +import org.eclipse.search.internal.core.text.TextSearchScope; +import org.eclipse.search.internal.ui.text.FileMatch; +import org.eclipse.search.internal.ui.text.FileSearchQuery; +import org.eclipse.search.ui.text.Match; + +/** + */ +public class LineBasedFileSearch extends FileSearchQuery { + public LineBasedFileSearch(TextSearchScope scope, String options, String searchString) { + super(scope, options, searchString); + } + + protected FileMatch createMatch(IFile file, int start, int length, int lineNumber) { + return new FileMatch(file, lineNumber, 1) { + /* (non-Javadoc) + * @see org.eclipse.search.ui.text.Match#getBaseUnit() + */ + public int getBaseUnit() { + return Match.UNIT_LINE; + } + }; + } + +}
\ No newline at end of file |