Search in sources :

Example 11 with IErlFunction

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

the class ModelUtilsTest method findExternalFunctionModuleTest.

@Test
public void findExternalFunctionModuleTest() throws Exception {
    // given
    // a module with functions and functions
    final IErlModule moduleD = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "d.erl", "-module(d).\n-export([f/0]).\nf() ->\n    ok.\ng() ->\n    ?MODULE:f().\n");
    moduleD.open(null);
    // when
    // looking for it with ?MODULE
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    final IErlElement element1 = modelFindService.findFunction(model, ModelUtilsTest.projects[0], moduleD, "?MODULE", null, new ErlangFunction("f", 0), IErlElementLocator.Scope.PROJECT_ONLY);
    // then
    // it should be found
    assertTrue(element1 instanceof IErlFunction);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) Test(org.junit.Test)

Example 12 with IErlFunction

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

the class ErlangCompareUtilities method getErlElementID.

/**
 * Returns a name for the given Erlang element
 */
static String getErlElementID(final IErlElement e) {
    final StringBuilder sb = new StringBuilder();
    final ErlElementKind kind = e.getKind();
    sb.append(kind);
    if (kind == ErlElementKind.FUNCTION) {
        final IErlFunction f = (IErlFunction) e;
        sb.append(f.getNameWithArity());
    } else if (kind == ErlElementKind.CLAUSE) {
        final IErlFunctionClause fc = (IErlFunctionClause) e;
        sb.append(fc.getHead());
    } else if (kind == ErlElementKind.ATTRIBUTE) {
        final IErlAttribute a = (IErlAttribute) e;
        sb.append(a.getName());
        if (a.getValue() != null) {
            sb.append(a.getValue().toString());
        }
    } else if (kind == ErlElementKind.RECORD_DEF || kind == ErlElementKind.MACRO_DEF) {
        final IErlPreprocessorDef pd = (IErlPreprocessorDef) e;
        sb.append(pd.getDefinedName());
    }
    return sb.toString();
}
Also used : ErlElementKind(org.erlide.engine.model.ErlElementKind) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) IErlPreprocessorDef(org.erlide.engine.model.erlang.IErlPreprocessorDef) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 13 with IErlFunction

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

the class OpenItemAction method run.

@Override
public void run() {
    log.info("Open item!");
    final ISelection selection = viewer.getSelection();
    if (!(selection instanceof ITreeSelection)) {
        final IStatus executionStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Internall error occured: bad sellection type", null);
        StatusManager.getManager().handle(executionStatus, StatusManager.SHOW);
        return;
    }
    final ITreeSelection treeSelection = (ITreeSelection) selection;
    final StatsTreeObject obj = (StatsTreeObject) treeSelection.getFirstElement();
    if (obj.getClass().equals(ModuleStats.class)) {
        openInEditor(obj.getLabel() + ".erl");
    } else if (obj.getClass().equals(FunctionStats.class)) {
        final FunctionStats fs = (FunctionStats) obj;
        final String moduleName = ((StatsTreeObject) fs.getParent()).getLabel();
        final IEditorPart p = openInEditor(moduleName + ".erl");
        if (p == null || !(p instanceof ErlangEditor)) {
            return;
        }
        final ErlangEditor editor = (ErlangEditor) p;
        IErlModule module;
        try {
            module = ErlangEngine.getInstance().getModel().findModule(moduleName);
            final IErlFunction f = module.findFunction(new ErlangFunction(fs.getLabel(), fs.getArity()));
            editor.setSelection(f);
        } catch (final ErlModelException e) {
            ErlLogger.error(e);
        }
    } else {
    // disabled
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) IEditorPart(org.eclipse.ui.IEditorPart) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ErlModelException(org.erlide.engine.model.ErlModelException) ISelection(org.eclipse.jface.viewers.ISelection) IErlModule(org.erlide.engine.model.root.IErlModule) FunctionStats(org.erlide.cover.views.model.FunctionStats) StatsTreeObject(org.erlide.cover.views.model.StatsTreeObject) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor)

Example 14 with IErlFunction

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

the class FunctionStats method getLineStart.

/**
 * First line of the function
 *
 * @return
 */
public int getLineStart() {
    if (lineStart != 0) {
        return lineStart;
    }
    final String mName = ((StatsTreeObject) getParent()).getLabel();
    IErlModule m;
    try {
        m = ErlangEngine.getInstance().getModel().findModule(mName);
        final IErlFunction f = m.findFunction(new ErlangFunction(getLabel(), getArity()));
        lineStart = f.getLineStart();
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
    }
    return lineStart;
}
Also used : ErlModelException(org.erlide.engine.model.ErlModelException) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction)

Example 15 with IErlFunction

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

the class ModelFindUtil method findFunction.

@Override
public IErlFunction findFunction(final IErlElementLocator model, final IErlProject project, final IErlModule module, final String moduleName0, final String modulePath, final ErlangFunction erlangFunction, final IErlElementLocator.Scope scope) throws CoreException {
    if (moduleName0 != null) {
        final String moduleName = resolveMacroValue(moduleName0, module);
        final IErlModule module2 = findModule(model, project, moduleName, modulePath, scope);
        if (module2 != null) {
            module2.open(null);
            final IErlFunction function = module2.findFunction(erlangFunction);
            if (function != null) {
                return function;
            }
            return null;
        }
    }
    return null;
}
Also used : IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule)

Aggregations

IErlFunction (org.erlide.engine.model.erlang.IErlFunction)22 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlElement (org.erlide.engine.model.IErlElement)6 ISelection (org.eclipse.jface.viewers.ISelection)5 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)3 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)3 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 PartInitException (org.eclipse.ui.PartInitException)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1