Search in sources :

Example 1 with ErlSearchScope

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;
}
Also used : IErlProject(org.erlide.engine.model.root.IErlProject) IErlModule(org.erlide.engine.model.root.IErlModule) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) HashSet(java.util.HashSet)

Example 2 with ErlSearchScope

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

Example 3 with ErlSearchScope

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;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IRpcResultCallback(org.erlide.runtime.rpc.IRpcResultCallback) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 4 with ErlSearchScope

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

Example 5 with ErlSearchScope

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

Aggregations

ErlSearchScope (org.erlide.engine.services.search.ErlSearchScope)9 IErlModule (org.erlide.engine.model.root.IErlModule)5 HashSet (java.util.HashSet)4 ErlangSearchPattern (org.erlide.engine.services.search.ErlangSearchPattern)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 SearchPatternFactory (org.erlide.engine.services.search.SearchPatternFactory)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 IResource (org.eclipse.core.resources.IResource)2 IParent (org.erlide.engine.model.IParent)2 IErlProject (org.erlide.engine.model.root.IErlProject)2 Test (org.junit.Test)2 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 IProject (org.eclipse.core.resources.IProject)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1