use of org.erlide.engine.services.search.ErlangSearchPattern 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.ErlangSearchPattern in project erlide_eclipse by erlang.
the class ErlangSearchPage method determineInitValuesFrom.
private SearchPatternData determineInitValuesFrom(final IErlModule module, final int offset, final OpenResult res) throws ErlModelException {
if (res == null) {
return null;
}
final ErlangSearchPattern pattern = SearchUtil.getSearchPatternFromOpenResultAndLimitTo(module, offset, res, LimitTo.REFERENCES, true);
final String patternString = pattern == null ? "" : pattern.patternString();
final SearchFor searchFor = pattern == null ? SearchFor.FUNCTION : pattern.getSearchFor();
final SearchPatternData searchPatternData = new SearchPatternData(patternString, ISearchPageContainer.WORKSPACE_SCOPE, LimitTo.REFERENCES, searchFor, null, SearchUtil.SEARCH_IN_SOURCES);
return searchPatternData;
}
use of org.erlide.engine.services.search.ErlangSearchPattern in project erlide_eclipse by erlang.
the class FindAction method run.
/*
* Method declared on SelectionChangedAction.
*/
@Override
public void run(final ITextSelection selection) {
try {
final IErlModule module = fEditor.getModule();
if (module == null) {
return;
}
final ISelection sel = getSelection();
final ITextSelection textSel = (ITextSelection) sel;
final int offset = textSel.getOffset();
final OpenResult res = ErlangEngine.getInstance().getOpenService().open(module.getScannerName(), offset, ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module), "", ErlangEngine.getInstance().getModel().getPathVars());
ErlLogger.debug("find " + res);
final ErlangSearchPattern ref = SearchUtil.getSearchPatternFromOpenResultAndLimitTo(module, offset, res, getLimitTo(), true);
if (ref != null) {
SearchUtil.runQuery(ref, getScope(), getScopeDescription(), getShell());
}
} catch (final Exception e) {
handleException(e);
}
}
use of org.erlide.engine.services.search.ErlangSearchPattern 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);
}
}
use of org.erlide.engine.services.search.ErlangSearchPattern 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));
}
Aggregations