use of org.erlide.engine.services.search.ErlangSearchPattern 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));
}
use of org.erlide.engine.services.search.ErlangSearchPattern 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));
}
Aggregations