Search in sources :

Example 1 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class ErlangCode method isEmbedded.

public static boolean isEmbedded(final IOtpRpc backend) {
    try {
        final OtpErlangObject r = backend.call(ErlangCode.CODE, "ensure_loaded", "a", "funny_module_name_that_nobody_would_use");
        final OtpBindings b = OtpErlang.match("{error, What}", r);
        if ("embedded".equals(b.getAtom("What"))) {
            return true;
        }
    } catch (final Exception e) {
    // ignore errors
    }
    return false;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) RpcException(org.erlide.runtime.rpc.RpcException)

Example 2 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class ErlangProcess method addStackTrace.

private void addStackTrace(final OtpErlangTuple savedStackTrace) {
    try {
        final OtpBindings bind = OtpErlang.match("{saved_stacktrace, _,STrace}", savedStackTrace);
        if (bind != null) {
            final Collection<OtpErlangObject> trace = bind.getList("STrace");
            for (final OtpErlangObject oframe : trace) {
                final OtpErlangTuple frame = (OtpErlangTuple) oframe;
                final OtpErlangAtom m = (OtpErlangAtom) frame.elementAt(0);
                final OtpErlangAtom f = (OtpErlangAtom) frame.elementAt(1);
                final OtpErlangLong a = (OtpErlangLong) frame.elementAt(2);
                try {
                    stackFrames.add(new ErlangUninterpretedStackFrame(m.atomValue(), new ErlangFunction(f.atomValue(), a.intValue()), this, getDebugTarget()));
                } catch (final OtpErlangRangeException e) {
                    ErlLogger.error(e);
                }
            }
        }
    } catch (final OtpParserException e1) {
        // ignore
        ErlLogger.error(e1);
    } catch (final OtpErlangException e1) {
        ErlLogger.error(e1);
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpParserException(org.erlide.util.erlang.OtpParserException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) OtpBindings(org.erlide.util.erlang.OtpBindings) ErlangFunction(org.erlide.engine.model.erlang.ErlangFunction) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 3 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class ErlangXref method functionUse.

@SuppressWarnings("boxing")
public FunctionRef[] functionUse(final String mod, final String fun, final int arity) {
    try {
        final OtpErlangObject r = backend.call(ErlangXref.ERLIDE_XREF, "function_use", "aai", mod.substring(0, mod.length() - 4), fun, arity);
        final OtpBindings bind = OtpErlang.match("{ok, L}", r);
        if (bind == null) {
            return new FunctionRef[0];
        }
        final OtpErlangList l = (OtpErlangList) bind.get("L");
        final List<FunctionRef> result = new ArrayList<>();
        for (final OtpErlangObject e : l) {
            result.add(new FunctionRef(e));
        }
        return result.toArray(new FunctionRef[result.size()]);
    } catch (final Exception e) {
        ErlLogger.debug(e);
    }
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) ArrayList(java.util.ArrayList) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 4 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class TestResultsView method handleEvent.

private void handleEvent(final OtpErlangObject msg) throws OtpParserException, OtpErlangException {
    final OtpErlangTuple tuple = (OtpErlangTuple) msg;
    final String tag = ((OtpErlangAtom) tuple.elementAt(0)).atomValue();
    final OtpErlangObject value = tuple.elementAt(1);
    TestCaseData test;
    if ("init".equals(tag)) {
        // value = {Dir, Suite, Case}
        label.setText("Started: " + formatTitle(value) + ". Compiling files, please wait...");
        treeViewer.getTree().setCursor(treeViewer.getTree().getShell().getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
    } else if ("start_failed".equals(tag)) {
    // value = ?
    } else if ("log_started".equals(tag)) {
        // value = Dir
        treeViewer.getTree().setCursor(treeViewer.getTree().getShell().getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
    } else if ("start".equals(tag)) {
        // value = {Module, Function}
        final OtpBindings bindings = OtpErlang.match("{M:a,F:a}", value);
        final String mod = bindings.getAtom("M");
        final String fun = bindings.getAtom("F");
        test = findCase(mod, fun);
        test.setRunning();
    } else if ("result".equals(tag)) {
        // value = {Module, Function, Result}
        final OtpBindings bindings = OtpErlang.match("{M:a,F:a,R}", value);
        final String mod = bindings.getAtom("M");
        final String fun = bindings.getAtom("F");
        final OtpErlangObject result = bindings.get("R");
        test = findCase(mod, fun);
        if (result instanceof OtpErlangAtom) {
            test.setSuccesful();
        // } else {
        // final BindingsImpl bindings =
        // OtpErlang.match("{failure,{M:a,F:a},L,R}", result);
        // final OtpErlangObject locations = bindings.get("L");
        // final OtpErlangObject reason = bindings.get("R");
        // test.setFailed(reason, locations);
        }
    } else if ("fail".equals(tag)) {
        // value = {{Module, Function}, [Locations], Reason
        final OtpBindings bindings = OtpErlang.match("{{M:a,F:a},L,R}", value);
        final String mod = bindings.getAtom("M");
        final String fun = bindings.getAtom("F");
        final Collection<OtpErlangObject> locations = bindings.getList("L");
        final OtpErlangObject reason = bindings.get("R");
        test = findCase(mod, fun);
        test.setFailed(reason, locations);
    } else if ("skip".equals(tag)) {
        // value = {Module, Function, Comment
        final OtpBindings bindings = OtpErlang.match("{M:a,F:a,C}", value);
        final String mod = bindings.getAtom("M");
        final String fun = bindings.getAtom("F");
        final OtpErlangObject reason = bindings.get("C");
        test = findCase(mod, fun);
        test.setSkipped(reason);
    } else if ("done".equals(tag)) {
        // value = Module, Log, {Successful,Failed,Skipped}, [Results]}
        final OtpBindings bindings = OtpErlang.match("{M,L,{S:i,F:i,K:i},R}", value);
        final int successful = bindings.getInt("S");
        final int failed = bindings.getInt("F");
        final int skipped = bindings.getInt("K");
        label.setText(label.getText() + " -- Done! Successful: " + successful + ", Failed: " + failed + ", Skipped: " + skipped);
    }
    control.redraw();
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) Collection(java.util.Collection) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 5 with OtpBindings

use of org.erlide.util.erlang.OtpBindings in project erlide_eclipse by erlang.

the class TestResultsView method formatTitle.

private String formatTitle(final OtpErlangObject value) {
    try {
        final OtpBindings b = OtpErlang.match("{D,S,C}", value);
        final String suite = b.getAtom("S");
        final String tcase = b.getAtom("C");
        if (tcase.isEmpty()) {
            return "suite " + suite;
        }
        return "suite " + suite + "; case " + tcase;
    } catch (final OtpParserException e) {
    } catch (final OtpErlangException e) {
    }
    return value.toString();
}
Also used : OtpParserException(org.erlide.util.erlang.OtpParserException) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) OtpBindings(org.erlide.util.erlang.OtpBindings)

Aggregations

OtpBindings (org.erlide.util.erlang.OtpBindings)24 Test (org.junit.Test)13 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)9 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)9 OtpParserException (org.erlide.util.erlang.OtpParserException)7 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)6 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)3 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)2 Collection (java.util.Collection)2 RpcException (org.erlide.runtime.rpc.RpcException)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 Subscribe (com.google.common.eventbus.Subscribe)1 ArrayList (java.util.ArrayList)1 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)1 FunctionRef (org.erlide.engine.model.erlang.FunctionRef)1