Search in sources :

Example 6 with FileTextSearchScope

use of org.eclipse.search.ui.text.FileTextSearchScope in project eclipse.platform.text by eclipse.

the class FileSearchTests method testFileOpenInEditor.

private void testFileOpenInEditor(TestResultCollector collector) throws Exception {
    StringBuilder buf = new StringBuilder();
    buf.append("File1\n");
    buf.append("hello\n");
    buf.append("more hello\n");
    buf.append("world\n");
    IFolder folder = ResourceHelper.createFolder(fProject.getFolder("folder1"));
    IFile file1 = ResourceHelper.createFile(folder, "file1", buf.toString());
    IFile file2 = ResourceHelper.createFile(folder, "file2", buf.toString());
    try {
        SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file2);
        Pattern searchPattern = PatternConstructor.createPattern("hello", false, true);
        FileTextSearchScope scope = FileTextSearchScope.newSearchScope(new IResource[] { fProject }, (String[]) null, false);
        TextSearchEngine.create().search(scope, collector, searchPattern, null);
        TestResult[] results = collector.getResults();
        assertEquals("Number of total results", 4, results.length);
        assertMatches(results, 2, file1, buf.toString(), "hello");
        assertMatches(results, 2, file2, buf.toString(), "hello");
    } finally {
        SearchPlugin.getActivePage().closeAllEditors(false);
    }
}
Also used : Pattern(java.util.regex.Pattern) IFile(org.eclipse.core.resources.IFile) FileTextSearchScope(org.eclipse.search.ui.text.FileTextSearchScope) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with FileTextSearchScope

use of org.eclipse.search.ui.text.FileTextSearchScope in project eclipse.platform.text by eclipse.

the class FileSearchTests method testWholeWord.

private void testWholeWord(TestResultCollector collector) throws Exception {
    StringBuilder buf = new StringBuilder();
    // nothing after
    // nothing before
    buf.append("hell\n");
    // nothing before
    buf.append("hill\n");
    // non-word char before
    buf.append("$hell\n");
    // word char before
    buf.append("shell\n");
    // non-word char after
    // nothing before
    buf.append("hell.freeze()\n");
    // non-word char before
    buf.append("freeze(hell)\n");
    // word char before
    buf.append("shell-script\n");
    // word char after
    // nothing before
    buf.append("hello\n");
    // non-word char before
    buf.append("world.hello()\n");
    // word char before
    buf.append("shilling\n");
    // nothing before
    buf.append("holler\n");
    IFolder folder = ResourceHelper.createFolder(fProject.getFolder("folder1"));
    ResourceHelper.createFile(folder, "file1", buf.toString());
    ResourceHelper.createFile(folder, "file2", buf.toString());
    TextSearchEngine engine = TextSearchEngine.create();
    FileTextSearchScope scope = FileTextSearchScope.newSearchScope(new IResource[] { fProject }, (String[]) null, false);
    {
        // wildcards, whole word = false: match all lines
        Pattern searchPattern = PatternConstructor.createPattern("h?ll", false, true, false, false);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
    }
    {
        // wildcards, whole word = true: match only nothing and non-word chars before and after
        Pattern searchPattern = PatternConstructor.createPattern("h?ll", false, true, false, true);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals("Number of whole-word results", 10, collector.getNumberOfResults());
    }
    {
        // regexp, whole word = false: match all lines
        Pattern searchPattern = PatternConstructor.createPattern("h[eio]ll", true, true, false, false);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals("Number of partial-word results", 22, collector.getNumberOfResults());
    }
}
Also used : Pattern(java.util.regex.Pattern) FileTextSearchScope(org.eclipse.search.ui.text.FileTextSearchScope) TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with FileTextSearchScope

use of org.eclipse.search.ui.text.FileTextSearchScope in project eclipse.platform.text by eclipse.

the class FileSearchTests method testWildCards1.

private void testWildCards1(TestResultCollector collector) throws Exception {
    StringBuilder buf = new StringBuilder();
    buf.append("File1\n");
    buf.append("no more\n");
    buf.append("mornings\n");
    buf.append("more hello\n");
    buf.append("world\n");
    IFolder folder = ResourceHelper.createFolder(fProject.getFolder("folder1"));
    ResourceHelper.createFile(folder, "file1", buf.toString());
    ResourceHelper.createFile(folder, "file2", buf.toString());
    Pattern searchPattern = PatternConstructor.createPattern("mor*", false, false);
    FileTextSearchScope scope = FileTextSearchScope.newSearchScope(new IResource[] { fProject }, (String[]) null, false);
    TextSearchEngine.create().search(scope, collector, searchPattern, null);
    TestResult[] results = collector.getResults();
    assertEquals("Number of total results", 6, results.length);
}
Also used : Pattern(java.util.regex.Pattern) FileTextSearchScope(org.eclipse.search.ui.text.FileTextSearchScope) IFolder(org.eclipse.core.resources.IFolder)

Example 9 with FileTextSearchScope

use of org.eclipse.search.ui.text.FileTextSearchScope in project eclipse.platform.text by eclipse.

the class PositionTrackerTest method setUp.

@Before
public void setUp() throws Exception {
    String[] fileNamePatterns = { "*.java" };
    FileTextSearchScope scope = FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false);
    fQuery1 = new FileSearchQuery("Test", false, true, scope);
}
Also used : FileSearchQuery(org.eclipse.search.internal.ui.text.FileSearchQuery) FileTextSearchScope(org.eclipse.search.ui.text.FileTextSearchScope) Before(org.junit.Before)

Example 10 with FileTextSearchScope

use of org.eclipse.search.ui.text.FileTextSearchScope in project eclipse.platform.text by eclipse.

the class SortingTest method setUp.

@Before
public void setUp() throws Exception {
    String[] fileNamePatterns = { "*.java" };
    FileTextSearchScope scope = FileTextSearchScope.newWorkspaceScope(fileNamePatterns, false);
    fQuery1 = new FileSearchQuery("Test", false, true, scope);
}
Also used : FileSearchQuery(org.eclipse.search.internal.ui.text.FileSearchQuery) FileTextSearchScope(org.eclipse.search.ui.text.FileTextSearchScope) Before(org.junit.Before)

Aggregations

FileTextSearchScope (org.eclipse.search.ui.text.FileTextSearchScope)16 Pattern (java.util.regex.Pattern)7 FileSearchQuery (org.eclipse.search.internal.ui.text.FileSearchQuery)7 Before (org.junit.Before)6 IFolder (org.eclipse.core.resources.IFolder)5 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)1 TextSearchEngine (org.eclipse.search.core.text.TextSearchEngine)1 FileSearchResult (org.eclipse.search.internal.ui.text.FileSearchResult)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1