Search in sources :

Example 1 with ErlangSearchPattern

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;
}
Also used : ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope)

Example 2 with ErlangSearchPattern

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;
}
Also used : ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) SearchFor(org.erlide.engine.services.search.SearchFor)

Example 3 with ErlangSearchPattern

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);
    }
}
Also used : OpenResult(org.erlide.engine.services.search.OpenResult) IErlModule(org.erlide.engine.model.root.IErlModule) ISelection(org.eclipse.jface.viewers.ISelection) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern) ITextSelection(org.eclipse.jface.text.ITextSelection) CoreException(org.eclipse.core.runtime.CoreException) ErlModelException(org.erlide.engine.model.ErlModelException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ErlangSearchPattern

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) SearchPatternFactory(org.erlide.engine.services.search.SearchPatternFactory) ErlangSearchPattern(org.erlide.engine.services.search.ErlangSearchPattern)

Example 5 with ErlangSearchPattern

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));
}
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

ErlangSearchPattern (org.erlide.engine.services.search.ErlangSearchPattern)7 IErlModule (org.erlide.engine.model.root.IErlModule)4 ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)4 SearchPatternFactory (org.erlide.engine.services.search.SearchPatternFactory)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)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 CoreException (org.eclipse.core.runtime.CoreException)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 OpenResult (org.erlide.engine.services.search.OpenResult)1 SearchFor (org.erlide.engine.services.search.SearchFor)1