use of org.erlide.engine.services.search.ErlSearchScope in project erlide_eclipse by erlang.
the class SearchUtil method getWorkingSetsScope.
public static ErlSearchScope getWorkingSetsScope(final IWorkingSet[] workingSets, final boolean addExternals, final boolean addOTP) throws CoreException {
final ErlSearchScope result = new ErlSearchScope();
final Set<String> externalModulePaths = new HashSet<>();
if (workingSets == null) {
return result;
}
for (final IWorkingSet ws : workingSets) {
final IAdaptable[] elements = ws.getElements();
for (final IAdaptable a : elements) {
final IResource r = a.getAdapter(IResource.class);
SearchCoreUtil.addResourceToScope(result, r);
IParent parent = null;
Object o = a.getAdapter(IErlElement.class);
if (o instanceof IParent) {
parent = (IParent) o;
} else {
o = a.getAdapter(IResource.class);
if (o != null) {
final IResource resource = (IResource) o;
final IErlElement element = ErlangEngine.getInstance().getModel().findElement(resource);
if (element instanceof IParent) {
parent = (IParent) element;
}
}
}
if (parent != null) {
SearchCoreUtil.addExternalModules(parent, result, externalModulePaths, addExternals, addOTP);
}
}
}
return result;
}
use of org.erlide.engine.services.search.ErlSearchScope in project erlide_eclipse by erlang.
the class SearchUtil method getSelectionScope.
public static ErlSearchScope getSelectionScope(final ISelection selection, final boolean addExternals, final boolean addOtp) throws CoreException {
final ErlSearchScope result = new ErlSearchScope();
final Set<String> externalModulePaths = new HashSet<>();
if (selection instanceof IStructuredSelection) {
final IStructuredSelection ss = (IStructuredSelection) selection;
for (final Object i : ss.toList()) {
if (i instanceof IResource) {
final IResource r = (IResource) i;
SearchCoreUtil.addResourceToScope(result, r);
} else if (i instanceof IErlModule) {
final IErlModule module = (IErlModule) i;
result.addModule(module);
} else if (i instanceof IParent) {
final IParent parent = (IParent) i;
SearchCoreUtil.addExternalModules(parent, result, externalModulePaths, addExternals, addOtp);
}
}
}
return result;
}
use of org.erlide.engine.services.search.ErlSearchScope in project erlide_eclipse by erlang.
the class SearchCoreUtil method getProjectsScope.
public static ErlSearchScope getProjectsScope(final Collection<IProject> projects, final boolean addExternals, final boolean addOtp) throws CoreException {
final ErlSearchScope result = new ErlSearchScope();
final Set<String> externalModulePaths = new HashSet<>();
final IErlModel model = ErlangEngine.getInstance().getModel();
for (final IProject project : projects) {
SearchCoreUtil.addProjectToScope(project, result);
if (NatureUtil.hasErlangNature(project)) {
final IErlProject erlProject = model.getErlangProject(project);
SearchCoreUtil.addExternalModules(erlProject, result, externalModulePaths, addExternals, addOtp);
}
}
return result;
}
use of org.erlide.engine.services.search.ErlSearchScope 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