Search in sources :

Example 1 with SearchPatternFactory

use of org.erlide.engine.services.search.SearchPatternFactory in project erlide_eclipse by erlang.

the class FindAction method run.

/**
 * Executes this action for the given java element.
 *
 * @param element
 *            The erlang element to be found.
 * @throws CoreException
 */
public void run(final IErlElement element) {
    try {
        final ErlangSearchPattern pattern = new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPatternFromErlElementAndLimitTo(element, getLimitTo());
        SearchUtil.runQuery(pattern, getScope(), getScopeDescription(), getShell());
    } catch (final CoreException e) {
        handleException(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) SearchPatternFactory(org.erlide.engine.services.search.SearchPatternFactory) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern)

Example 2 with SearchPatternFactory

use of org.erlide.engine.services.search.SearchPatternFactory in project erlide_eclipse by erlang.

the class SearchTest method findCallAfterRecordRef.

@Test
public void findCallAfterRecordRef() throws Exception {
    // given
    // a module a with an exported function f
    // and a module b which calls a:f()
    final IErlModule moduleA = ErlideTestUtils.createModule(SearchTest.projects[0], "a.erl", "-module(a).\n-export([f/0]).\nf() ->\n    ok.\n");
    final IErlModule moduleB = ErlideTestUtils.createModule(SearchTest.projects[0], "b.erl", "-module(b).\n-export([f/0]).\nf() ->\n    #a.b,\n    a:f().\n");
    moduleA.open(null);
    moduleB.open(null);
    // when
    // searching for the call to a:f
    final ErlangSearchPattern ref = new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPattern(SearchFor.FUNCTION, "a", "f", 0, LimitTo.REFERENCES, moduleA);
    final ErlSearchScope scope = new ErlSearchScope(moduleA);
    scope.addModule(moduleB);
    final ErlSearchQuery query = new ErlSearchQuery(ref, scope, "");
    query.run(new NullProgressMonitor());
    // then
    // it should be found in module b
    final ErlangSearchResult searchResult = (ErlangSearchResult) query.getSearchResult();
    assertEquals(1, searchResult.getMatchCount());
    final List<ErlangSearchElement> result = searchResult.getResult();
    assertTrue(hasModule(moduleB, result));
    assertFalse(hasModule(moduleA, result));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ErlSearchQuery(org.erlide.ui.internal.search.ErlSearchQuery) ErlangSearchElement(org.erlide.ui.internal.search.ErlangSearchElement) SearchPatternFactory(org.erlide.engine.services.search.SearchPatternFactory) ErlangSearchResult(org.erlide.ui.internal.search.ErlangSearchResult) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) Test(org.junit.Test)

Example 3 with SearchPatternFactory

use of org.erlide.engine.services.search.SearchPatternFactory in project erlide_eclipse by erlang.

the class SearchTest method findExternalCallsTestAux.

private void findExternalCallsTestAux(final LimitTo limitTo, final int nFoundExpected) throws CoreException, ErlModelException, OperationCanceledException {
    // given
    // a module a with an exported function f
    // and a module b which calls a:f()
    final IErlModule moduleA = ErlideTestUtils.createModule(SearchTest.projects[0], "a.erl", "-module(a).\n-export([f/0]).\nf() ->\n    ok.\n");
    final IErlModule moduleB = ErlideTestUtils.createModule(SearchTest.projects[0], "b.erl", "-module(b).\n-export([f/0]).\nf() ->\n    a:f().\n");
    moduleA.open(null);
    moduleB.open(null);
    // when
    // searching for the call to a:f
    final ErlangSearchPattern ref = new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPattern(SearchFor.FUNCTION, "a", "f", 0, limitTo, moduleA);
    final ErlSearchScope scope = new ErlSearchScope(moduleA);
    scope.addModule(moduleB);
    final ErlSearchQuery query = new ErlSearchQuery(ref, scope, "");
    query.run(new NullProgressMonitor());
    // then
    // it should be found in module b
    final ErlangSearchResult searchResult = (ErlangSearchResult) query.getSearchResult();
    assertEquals(nFoundExpected, searchResult.getMatchCount());
    final List<ErlangSearchElement> result = searchResult.getResult();
    if (limitTo == LimitTo.REFERENCES) {
        // f is only referred in moduleB, but declarations matches in any
        // module as long as arity and name are equal
        assertFalse(hasModule(moduleA, result));
    } else {
        assertTrue(hasModule(moduleA, result));
    }
    assertTrue(hasModule(moduleB, result));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ErlSearchQuery(org.erlide.ui.internal.search.ErlSearchQuery) ErlangSearchElement(org.erlide.ui.internal.search.ErlangSearchElement) SearchPatternFactory(org.erlide.engine.services.search.SearchPatternFactory) ErlangSearchResult(org.erlide.ui.internal.search.ErlangSearchResult) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope)

Example 4 with SearchPatternFactory

use of org.erlide.engine.services.search.SearchPatternFactory in project erlide_eclipse by erlang.

the class SearchUtil method getSearchPattern.

public static ErlangSearchPattern getSearchPattern(final IErlModule module, final SearchFor searchFor, final String pattern, final LimitTo limitTo) {
    String moduleName = "";
    String name = pattern;
    int arity = -1;
    int p = pattern.indexOf(':');
    if (p != -1) {
        moduleName = pattern.substring(0, p);
        name = pattern.substring(p + 1);
    }
    p = name.indexOf('/');
    if (p != -1) {
        arity = Integer.valueOf(name.substring(p + 1));
        name = name.substring(0, p);
    }
    return new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPattern(searchFor, moduleName, name, arity, limitTo, module);
}
Also used : SearchPatternFactory(org.erlide.engine.services.search.SearchPatternFactory)

Example 5 with SearchPatternFactory

use of org.erlide.engine.services.search.SearchPatternFactory in project erlide_eclipse by erlang.

the class SearchTest method findVariableRef.

@Test
public void findVariableRef() throws Exception {
    // given
    // a module a with an exported function f
    // and a module b which calls a:f()
    final IErlModule moduleA = ErlideTestUtils.createModule(SearchTest.projects[0], "a.erl", "-module(a).\n-export([f/1]).\nf(A) ->\n    {A}.\n");
    final IErlModule moduleB = ErlideTestUtils.createModule(SearchTest.projects[0], "b.erl", "-module(b).\n-export([f/0]).\nf(A) ->\n    [A].\n");
    moduleA.open(null);
    moduleB.open(null);
    // when
    // searching for the variable A from module a
    final ErlangSearchPattern pattern = new SearchPatternFactory(ErlangEngine.getInstance().getModelUtilService()).getSearchPattern(SearchFor.VARIABLE, null, "A", 0, LimitTo.ALL_OCCURRENCES, moduleA);
    final ErlSearchScope scope = new ErlSearchScope(moduleA);
    scope.addModule(moduleB);
    final ErlSearchScope reducedScope = pattern.reduceScope(scope);
    final ErlSearchQuery query = new ErlSearchQuery(pattern, reducedScope, "");
    query.run(new NullProgressMonitor());
    // then
    // it should be found in module a
    final ErlangSearchResult searchResult = (ErlangSearchResult) query.getSearchResult();
    assertEquals(2, searchResult.getMatchCount());
    final List<ErlangSearchElement> result = searchResult.getResult();
    assertTrue(hasModule(moduleA, result));
    assertFalse(hasModule(moduleB, result));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ErlSearchQuery(org.erlide.ui.internal.search.ErlSearchQuery) ErlangSearchElement(org.erlide.ui.internal.search.ErlangSearchElement) SearchPatternFactory(org.erlide.engine.services.search.SearchPatternFactory) ErlangSearchResult(org.erlide.ui.internal.search.ErlangSearchResult) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) Test(org.junit.Test)

Aggregations

SearchPatternFactory (org.erlide.engine.services.search.SearchPatternFactory)5 ErlangSearchPattern (org.erlide.engine.services.search.ErlangSearchPattern)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IErlModule (org.erlide.engine.model.root.IErlModule)3 ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)3 ErlSearchQuery (org.erlide.ui.internal.search.ErlSearchQuery)3 ErlangSearchElement (org.erlide.ui.internal.search.ErlangSearchElement)3 ErlangSearchResult (org.erlide.ui.internal.search.ErlangSearchResult)3 Test (org.junit.Test)2 CoreException (org.eclipse.core.runtime.CoreException)1