use of org.erlide.engine.services.search.ErlSearchScope in project erlide_eclipse by erlang.
the class SearchCoreUtil method getWorkspaceScope.
public static ErlSearchScope getWorkspaceScope(final boolean addExternals, final boolean addOtp) throws ErlModelException {
final ErlSearchScope result = new ErlSearchScope();
final Collection<IErlProject> erlangProjects = ErlangEngine.getInstance().getModel().getErlangProjects();
for (final IErlProject i : erlangProjects) {
final Collection<IErlModule> modules = i.getModulesAndIncludes();
for (final IErlModule j : modules) {
result.addModule(j);
}
// addProjectEbin(i, result);
}
final Set<String> externalModulePaths = new HashSet<>();
for (final IErlProject project : erlangProjects) {
SearchCoreUtil.addExternalModules(project, result, externalModulePaths, addExternals, addOtp);
}
return result;
}
use of org.erlide.engine.services.search.ErlSearchScope in project erlide_eclipse by erlang.
the class ErlangSearchPage method performNewSearch.
private boolean performNewSearch() throws CoreException {
final SearchPatternData data = getPatternData();
final int includeMask = getIncludeMask();
// Setup search scope
ErlSearchScope scope = ErlangSearchPage.EMPTY_SCOPE;
String scopeDescription = null;
final boolean searchSources = (includeMask & SearchUtil.SEARCH_IN_SOURCES) != 0;
final boolean searchExternals = (includeMask & SearchUtil.SEARCH_IN_EXTERNALS) != 0;
final boolean searchOtp = (includeMask & SearchUtil.SEARCH_IN_OTP_LIBRARIES) != 0;
final int selectedScope = getContainer().getSelectedScope();
switch(selectedScope) {
case ISearchPageContainer.WORKSPACE_SCOPE:
if (searchSources) {
scope = SearchCoreUtil.getWorkspaceScope(searchExternals, searchOtp);
}
scopeDescription = SearchUtil.getWorkspaceScopeDescription();
break;
case ISearchPageContainer.SELECTED_PROJECTS_SCOPE:
final String[] projectNames = getContainer().getSelectedProjectNames();
if (searchSources) {
scope = SearchCoreUtil.getProjectsScope(SearchCoreUtil.getProjects(projectNames), searchExternals, searchOtp);
}
scopeDescription = SearchUtil.getProjectScopeDescription(SearchCoreUtil.getProjects(projectNames));
break;
case ISearchPageContainer.SELECTION_SCOPE:
if (searchSources) {
scope = SearchUtil.getSelectionScope(getContainer().getSelection(), searchExternals, searchOtp);
}
scopeDescription = SearchUtil.getSelectionScopeDescription(getContainer().getSelection());
break;
case ISearchPageContainer.WORKING_SET_SCOPE:
{
final IWorkingSet[] workingSets = getContainer().getSelectedWorkingSets();
// should not happen - just to be sure
if (workingSets == null || workingSets.length < 1) {
return false;
}
scopeDescription = SearchUtil.getWorkingSetsScopeDescription(workingSets);
if (searchSources) {
scope = SearchUtil.getWorkingSetsScope(workingSets, searchExternals, searchOtp);
}
SearchUtil.updateLRUWorkingSets(workingSets);
}
break;
default:
break;
}
final ErlangSearchPattern searchPattern = SearchUtil.getSearchPattern(null, data.getSearchFor(), data.getPattern(), data.getLimitTo());
SearchUtil.runQuery(searchPattern, scope, scopeDescription, getShell());
return true;
}
use of org.erlide.engine.services.search.ErlSearchScope in project erlide_eclipse by erlang.
the class ErlSearchQuery method run.
@Override
public IStatus run(final IProgressMonitor monitor) throws OperationCanceledException {
final Object locker = new Object();
final IRpcResultCallback callback = new IRpcResultCallback() {
@Override
public void start(final OtpErlangObject msg) {
if (fSearchResult != null) {
fSearchResult.removeAll();
}
final OtpErlangLong progressMaxL = (OtpErlangLong) msg;
int progressMax;
try {
progressMax = progressMaxL.intValue();
} catch (final OtpErlangRangeException e) {
progressMax = 10;
}
monitor.beginTask("Searching", progressMax);
}
@Override
public void stop(final OtpErlangObject msg) {
monitor.done();
stopped = true;
synchronized (locker) {
locker.notifyAll();
}
}
@Override
public void progress(final OtpErlangObject msg) {
final OtpErlangTuple t = (OtpErlangTuple) msg;
final OtpErlangPid backgroundSearchPid = (OtpErlangPid) t.elementAt(0);
final OtpErlangLong progressL = (OtpErlangLong) t.elementAt(1);
final OtpErlangObject resultO = t.elementAt(2);
int progress = 1;
try {
progress = progressL.intValue();
final List<ModuleLineFunctionArityRef> result = Lists.newArrayList();
SearchUtil.addSearchResult(result, resultO);
addMatches(result);
} catch (final OtpErlangRangeException e) {
}
monitor.worked(progress);
if (monitor.isCanceled()) {
try {
ErlangEngine.getInstance().getSearchServerService().cancelSearch(backgroundSearchPid);
} catch (final RpcException e) {
}
}
}
};
try {
final ErlSearchScope reducedScope = pattern.reduceScope(scope);
ErlangEngine.getInstance().getSearchServerService().startFindRefs(pattern, reducedScope, ErlangEngine.getInstance().getStateDir(), callback, false);
} catch (final RpcException e) {
return new Status(IStatus.ERROR, ErlideUIPlugin.PLUGIN_ID, "Search error", e);
}
while (!stopped) {
synchronized (locker) {
try {
if (!stopped) {
locker.wait();
}
} catch (final InterruptedException e) {
}
}
}
return Status.OK_STATUS;
}
use of org.erlide.engine.services.search.ErlSearchScope 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));
}
use of org.erlide.engine.services.search.ErlSearchScope 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));
}
Aggregations