Search in sources :

Example 6 with ErlSearchScope

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;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) IParent(org.erlide.engine.model.IParent) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IWorkingSet(org.eclipse.ui.IWorkingSet) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 7 with ErlSearchScope

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;
}
Also used : IParent(org.erlide.engine.model.IParent) IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlSearchScope(org.erlide.engine.services.search.ErlSearchScope) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 8 with ErlSearchScope

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

Example 9 with ErlSearchScope

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

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