Search in sources :

Example 96 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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 97 with IErlModule

use of org.erlide.engine.model.root.IErlModule 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)

Example 98 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class GlobalParameters method setSelection.

/**
 * Stores a selection marked 'current'
 *
 * @param selection
 *            Erlang selection
 */
public static void setSelection(final ISelection selection) throws WranglerException {
    // TODO:: if the module is selected it is not handled
    try {
        if (GlobalParameters.editor == null) {
            final IWorkbench instance = PlatformUI.getWorkbench();
            final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
            GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
        }
        if (selection instanceof ITextSelection) {
            final IWorkbench instance = PlatformUI.getWorkbench();
            final IWorkbenchWindow activeWorkbenchWindow = instance.getActiveWorkbenchWindow();
            GlobalParameters.editor = activeWorkbenchWindow.getActivePage().getActiveEditor();
            GlobalParameters.wranglerSelection = new ErlTextMemberSelection((ITextSelection) selection, (ITextEditor) GlobalParameters.editor);
        } else if (selection instanceof ITreeSelection) {
            final Object firstElement = ((ITreeSelection) selection).getFirstElement();
            if (firstElement instanceof IErlElement) {
                final IErlElement element = (IErlElement) firstElement;
                final IFile file = (IFile) element.getResource();
                GlobalParameters.wranglerSelection = new ErlMemberSelection(element, file, WranglerUtils.getDocument(file));
            } else if (firstElement instanceof IFile) {
                final IFile file = (IFile) firstElement;
                final IErlModule module = ErlangEngine.getInstance().getModel().findModule(file);
                GlobalParameters.wranglerSelection = new ErlModuleSelection(module, file);
            } else {
                GlobalParameters.wranglerSelection = null;
                throw new WranglerException("Please select an Erlang element!");
            }
        } else {
            GlobalParameters.wranglerSelection = null;
            throw new WranglerException("Please select an Erlang element!");
        }
    } catch (final ClassCastException e) {
        ErlLogger.error(e);
    }
/*
         * System.out.println(wranglerSelection.getStartLine() + "," +
         * wranglerSelection.getStartCol() + ";" +
         * wranglerSelection.getEndLine() + "," +
         * wranglerSelection.getEndCol());
         */
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) ErlTextMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlTextMemberSelection) ErlModuleSelection(org.erlide.wrangler.refactoring.selection.internal.ErlModuleSelection) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) ITextSelection(org.eclipse.jface.text.ITextSelection) IWorkbench(org.eclipse.ui.IWorkbench) IErlElement(org.erlide.engine.model.IErlElement) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ErlMemberSelection(org.erlide.wrangler.refactoring.selection.internal.ErlMemberSelection) IErlModule(org.erlide.engine.model.root.IErlModule)

Example 99 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class WranglerUtils method highlightSelection.

/**
 * Highlights the given function clause
 *
 * @param clause
 *            erlang function clause
 */
public static void highlightSelection(final IErlFunctionClause clause) {
    int offset;
    int length;
    offset = clause.getNameRange().getOffset();
    length = clause.getNameRange().getLength();
    final IErlModule module = ErlangEngine.getInstance().getModelUtilService().getModule(clause);
    final IEditorPart editor = WranglerUtils.openFile((IFile) module.getResource());
    WranglerUtils.highlightSelection(offset, length, (ITextEditor) editor);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) IEditorPart(org.eclipse.ui.IEditorPart)

Example 100 with IErlModule

use of org.erlide.engine.model.root.IErlModule in project erlide_eclipse by erlang.

the class SimpleCodeInspectionHandler method extractModule.

private IErlModule extractModule(final OtpErlangObject m) throws ErlModelException {
    String name = "";
    if (m instanceof OtpErlangString) {
        final OtpErlangString element = (OtpErlangString) m;
        name = element.stringValue();
    } else if (m instanceof OtpErlangAtom) {
        final OtpErlangAtom atom = (OtpErlangAtom) m;
        name = atom.atomValue();
    }
    final String[] modNameParts = name.split("/");
    final IErlModule mod = ErlangEngine.getInstance().getModel().findModule(modNameParts[modNameParts.length - 1]);
    return mod;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Aggregations

IErlModule (org.erlide.engine.model.root.IErlModule)191 Test (org.junit.Test)66 IErlProject (org.erlide.engine.model.root.IErlProject)57 IErlElement (org.erlide.engine.model.IErlElement)35 IFile (org.eclipse.core.resources.IFile)26 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)26 ErlModelException (org.erlide.engine.model.ErlModelException)22 IPath (org.eclipse.core.runtime.IPath)21 ErlProject (org.erlide.engine.internal.model.root.ErlProject)21 File (java.io.File)20 IErlModel (org.erlide.engine.model.root.IErlModel)18 Path (org.eclipse.core.runtime.Path)17 IProject (org.eclipse.core.resources.IProject)16 IResource (org.eclipse.core.resources.IResource)14 ArrayList (java.util.ArrayList)13 CoreException (org.eclipse.core.runtime.CoreException)10 IEditorPart (org.eclipse.ui.IEditorPart)10 IParent (org.erlide.engine.model.IParent)10 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)9