Search in sources :

Example 1 with TextSearchEngine

use of org.eclipse.search.core.text.TextSearchEngine in project che by eclipse.

the class QualifiedNameFinder method process.

public static void process(QualifiedNameSearchResult result, String pattern, String newValue, String filePatterns, IProject root, IProgressMonitor monitor) {
    Assert.isNotNull(pattern);
    Assert.isNotNull(newValue);
    Assert.isNotNull(root);
    if (monitor == null)
        monitor = new NullProgressMonitor();
    if (filePatterns == null || filePatterns.length() == 0) {
        // Eat progress.
        //$NON-NLS-1$
        monitor.beginTask("", 1);
        monitor.worked(1);
        return;
    }
    ResultCollector collector = new ResultCollector(result, newValue);
    TextSearchEngine engine = TextSearchEngine.create();
    Pattern searchPattern = PatternConstructor.createPattern(pattern, true, false);
    engine.search(createScope(filePatterns, root), collector, searchPattern, monitor);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Pattern(java.util.regex.Pattern) TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine)

Example 2 with TextSearchEngine

use of org.eclipse.search.core.text.TextSearchEngine in project eclipse.platform.text by eclipse.

the class TextSearchEngineRegistry method createFromExtension.

private TextSearchEngine createFromExtension(final String id) {
    final TextSearchEngine[] res = new TextSearchEngine[] { null };
    SafeRunnable safe = new SafeRunnable() {

        @Override
        public void run() throws Exception {
            IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID);
            for (IConfigurationElement curr : extensions) {
                if (ENGINE_NODE_NAME.equals(curr.getName()) && id.equals(curr.getAttribute(ATTRIB_ID))) {
                    res[0] = (TextSearchEngine) curr.createExecutableExtension(ATTRIB_CLASS);
                    return;
                }
            }
        }

        @Override
        public void handleException(Throwable e) {
            SearchPlugin.log(e);
        }
    };
    SafeRunnable.run(safe);
    return res[0];
}
Also used : SafeRunnable(org.eclipse.jface.util.SafeRunnable) TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with TextSearchEngine

use of org.eclipse.search.core.text.TextSearchEngine in project eclipse.platform.text by eclipse.

the class FileSearchTests method testDerivedFiles.

private void testDerivedFiles(TestResultCollector collector) throws Exception {
    StringBuilder buf = new StringBuilder();
    buf.append("hello\n");
    IFolder folder1 = ResourceHelper.createFolder(fProject.getFolder("folder1"));
    ResourceHelper.createFile(folder1, "file1", buf.toString());
    IFile file2 = ResourceHelper.createFile(folder1, "file2", buf.toString());
    file2.setDerived(true, null);
    IFolder folder2 = ResourceHelper.createFolder(folder1.getFolder("folder2"));
    folder2.setDerived(true, null);
    ResourceHelper.createFile(folder2, "file3", buf.toString());
    IFolder folder3 = ResourceHelper.createFolder(folder2.getFolder("folder3"));
    ResourceHelper.createFile(folder3, "file4", buf.toString());
    IFolder folder4 = ResourceHelper.createFolder(folder1.getFolder("folder4"));
    ResourceHelper.createFile(folder4, "file5", buf.toString());
    /**
     * folder1
     *     file1
     *     file2*
     *     folder2*
     *       file3
     *       folder3
     *         file4
     *     folder4
     *       file5
     */
    Pattern searchPattern = PatternConstructor.createPattern("hello", false, true);
    Pattern fileNamePattern = PatternConstructor.createPattern("*", false, false);
    TextSearchEngine engine = TextSearchEngine.create();
    {
        // visit all
        TextSearchScope scope = TextSearchScope.newSearchScope(new IResource[] { fProject }, fileNamePattern, true);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals(5, collector.getNumberOfResults());
    }
    {
        // visit non-derived
        TextSearchScope scope = TextSearchScope.newSearchScope(new IResource[] { fProject }, fileNamePattern, false);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals(2, collector.getNumberOfResults());
    }
    {
        // visit all in folder2
        TextSearchScope scope = TextSearchScope.newSearchScope(new IResource[] { folder2 }, fileNamePattern, true);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals(2, collector.getNumberOfResults());
    }
    {
        // visit non-derived in folder2
        TextSearchScope scope = TextSearchScope.newSearchScope(new IResource[] { folder2 }, fileNamePattern, false);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals(0, collector.getNumberOfResults());
    }
    {
        // visit all in folder3
        TextSearchScope scope = TextSearchScope.newSearchScope(new IResource[] { folder3 }, fileNamePattern, true);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals(1, collector.getNumberOfResults());
    }
    {
        // visit non-derived in folder3
        TextSearchScope scope = TextSearchScope.newSearchScope(new IResource[] { folder3 }, fileNamePattern, false);
        collector.reset();
        engine.search(scope, collector, searchPattern, null);
        assertEquals(0, collector.getNumberOfResults());
    }
}
Also used : Pattern(java.util.regex.Pattern) TextSearchScope(org.eclipse.search.core.text.TextSearchScope) FileTextSearchScope(org.eclipse.search.ui.text.FileTextSearchScope) IFile(org.eclipse.core.resources.IFile) TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with TextSearchEngine

use of org.eclipse.search.core.text.TextSearchEngine 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 5 with TextSearchEngine

use of org.eclipse.search.core.text.TextSearchEngine in project eclipse.platform.text by eclipse.

the class TextSearchEngineRegistry method updateEngine.

private void updateEngine(String preferredId) {
    if (preferredId.length() != 0) {
        // empty string: default engine
        TextSearchEngine engine = createFromExtension(preferredId);
        if (engine != null) {
            fPreferredEngineId = preferredId;
            fPreferredEngine = engine;
            return;
        }
        // creation failed, clear preference
        // set to default //$NON-NLS-1$
        setPreferredEngineID("");
    }
    // $NON-NLS-1$
    fPreferredEngineId = "";
    fPreferredEngine = TextSearchEngine.createDefault();
}
Also used : TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine)

Aggregations

TextSearchEngine (org.eclipse.search.core.text.TextSearchEngine)5 Pattern (java.util.regex.Pattern)3 IFolder (org.eclipse.core.resources.IFolder)2 FileTextSearchScope (org.eclipse.search.ui.text.FileTextSearchScope)2 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SafeRunnable (org.eclipse.jface.util.SafeRunnable)1 TextSearchScope (org.eclipse.search.core.text.TextSearchScope)1