Search in sources :

Example 6 with ErlangFunction

use of org.erlide.engine.model.erlang.ErlangFunction 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 7 with ErlangFunction

use of org.erlide.engine.model.erlang.ErlangFunction 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 8 with ErlangFunction

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

the class ModelInternalUtils method getImportsAsList.

@Override
public List<OtpErlangObject> getImportsAsList(final IErlModule mod) {
    if (mod == null) {
        return ModelInternalUtils.NO_IMPORTS;
    }
    final Collection<IErlImport> imports = mod.getImports();
    if (imports.isEmpty()) {
        return ModelInternalUtils.NO_IMPORTS;
    }
    final List<OtpErlangObject> result = new ArrayList<>(imports.size());
    for (final IErlImport i : imports) {
        final Collection<ErlangFunction> functions = i.getFunctions();
        final OtpErlangObject[] funsT = new OtpErlangObject[functions.size()];
        int j = 0;
        for (final ErlangFunction f : functions) {
            funsT[j] = f.getNameArityTuple();
            j++;
        }
        final OtpErlangTuple modFunsT = new OtpErlangTuple(new OtpErlangObject[] { new OtpErlangAtom(i.getImportModule()), new OtpErlangList(funsT) });
        result.add(modFunsT);
    }
    return result;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 9 with ErlangFunction

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

the class OpenUtils method findExternalCallOrType.

private IErlElement findExternalCallOrType(final IErlModule module, final OpenResult res, final IErlProject project, final IErlElement element, final IErlElementLocator.Scope scope) throws CoreException {
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    if (isTypeDefOrRecordDef(element, res)) {
        return modelFindService.findTypeDef(model, project, module, res.getName(), res.getFun(), res.getPath(), scope);
    }
    final IErlFunction result = modelFindService.findFunction(model, project, module, res.getName(), res.getPath(), res.getFunction(), scope);
    if (result != null) {
        return result;
    }
    return modelFindService.findFunction(model, project, module, res.getName(), res.getPath(), new ErlangFunction(res.getFun(), ErlangFunction.ANY_ARITY), scope);
}
Also used : IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator)

Aggregations

ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)9 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ErlModelException (org.erlide.engine.model.ErlModelException)2 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)2 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 ArrayList (java.util.ArrayList)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1 IEditorPart (org.eclipse.ui.IEditorPart)1 FunctionStats (org.erlide.cover.views.model.FunctionStats)1 StatsTreeObject (org.erlide.cover.views.model.StatsTreeObject)1