Search in sources :

Example 41 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class ProcessHelper method getProcsOnTracedNodes.

/**
 * Returns list of processes on all traced nodes.
 *
 * @return list of processes
 */
public static TracedProcess[] getProcsOnTracedNodes() {
    try {
        final IOtpRpc backend = TraceBackend.getInstance().getBackend(true).getOtpRpc();
        final List<OtpErlangAtom> nodeAtoms = new ArrayList<>();
        for (final Object o : TraceBackend.getInstance().getTracedNodesArray()) {
            final TracedNode tracedNode = (TracedNode) o;
            if (tracedNode.isEnabled()) {
                nodeAtoms.add(new OtpErlangAtom(tracedNode.getNodeName()));
            }
        }
        final OtpErlangList nodesList = new OtpErlangList(nodeAtoms.toArray(new OtpErlangAtom[nodeAtoms.size()]));
        final OtpErlangList procList = (OtpErlangList) backend.call(ProcessHelper.MODULE_NAME, ProcessHelper.FUNCTION_NAME, "x", nodesList);
        final TracedProcess[] processes = new TracedProcess[procList.arity()];
        for (int i = 0; i < procList.arity(); i++) {
            final OtpErlangTuple tuple = (OtpErlangTuple) procList.elementAt(i);
            processes[i] = new TracedProcess(tuple);
        }
        return processes;
    } catch (final RpcException e) {
        ErlLogger.error(e);
    }
    return null;
}
Also used : TracedProcess(org.erlide.tracing.core.mvc.model.TracedProcess) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcException(org.erlide.runtime.rpc.RpcException) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) IOtpRpc(org.erlide.runtime.rpc.IOtpRpc)

Example 42 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom 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 43 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class ModelUtilsTest method getImportsAsListTest.

@Test
public void getImportsAsListTest() throws Exception {
    // given
    // an Erlang module with imports
    final IErlModule moduleA = ErlideTestUtils.createModule(ModelUtilsTest.projects[0], "ax.erl", "-module(ax).\n-import(lists, [reverse/1, foldl/3].\n");
    moduleA.open(null);
    // when
    // fetching imports as list of OtpErlangTuple
    final Collection<IErlElement> children = moduleA.getChildren();
    final Collection<IErlImport> imports2 = moduleA.getImports();
    final List<OtpErlangObject> imports = modelUtilService.getImportsAsList(moduleA);
    // then
    // they should be returned
    assertEquals(2, children.size());
    assertEquals(1, imports2.size());
    assertEquals(1, imports.size());
    final OtpErlangAtom listAtom = new OtpErlangAtom("lists");
    assertEquals(new OtpErlangTuple(new OtpErlangObject[] { listAtom, new OtpErlangList(new OtpErlangObject[] { makeTuple2("reverse", 1), makeTuple2("foldl", 3) }) }), imports.get(0));
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlModule(org.erlide.engine.model.root.IErlModule) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) Test(org.junit.Test)

Example 44 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class PatternMatchTest method testMatch_sig_a.

@Test
public void testMatch_sig_a() throws Exception {
    final OtpBindings r = OtpErlang.match("W:a", "zzz");
    Assert.assertEquals(r.get("W"), new OtpErlangAtom("zzz"));
}
Also used : OtpBindings(org.erlide.util.erlang.OtpBindings) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) Test(org.junit.Test)

Example 45 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom in project erlide_eclipse by erlang.

the class PatternMatchTest method testMatch_same.

@Test
public void testMatch_same() throws Exception {
    final OtpBindings r = OtpErlang.match("[W, {V}]", "[a, {a}]");
    Assert.assertEquals(r.get("W"), new OtpErlangAtom("a"));
}
Also used : OtpBindings(org.erlide.util.erlang.OtpBindings) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) Test(org.junit.Test)

Aggregations

OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)87 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)56 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)48 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)32 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)24 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)17 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)11 RpcException (org.erlide.runtime.rpc.RpcException)11 OtpBindings (org.erlide.util.erlang.OtpBindings)9 IErlElement (org.erlide.engine.model.IErlElement)6 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)4 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)3 OtpErlangMap (com.ericsson.otp.erlang.OtpErlangMap)3 Subscribe (com.google.common.eventbus.Subscribe)3 Collection (java.util.Collection)3 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)2