Search in sources :

Example 76 with OtpErlangAtom

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

the class ErlangLogEventHandler method handleEvent.

@Subscribe
public void handleEvent(final ErlEvent event) {
    if (!event.getTopic().equals(getTopic())) {
        return;
    }
    final OtpErlangTuple t = (OtpErlangTuple) event.getEvent();
    final OtpErlangAtom module = (OtpErlangAtom) t.elementAt(0);
    final OtpErlangLong line = (OtpErlangLong) t.elementAt(1);
    final OtpErlangAtom level = (OtpErlangAtom) t.elementAt(2);
    final OtpErlangObject logEvent = t.elementAt(3);
    String ss = "";
    if (t.arity() == 5) {
        final OtpErlangTuple backtrace_0 = (OtpErlangTuple) t.elementAt(4);
        final OtpErlangBinary backtrace = (OtpErlangBinary) backtrace_0.elementAt(1);
        ss = new String(backtrace.binaryValue());
    }
    try {
        ErlLogger.getInstance().erlangLog(module.atomValue() + ".erl", line.uIntValue(), level.atomValue().toUpperCase(), "%s %s", logEvent.toString(), ss);
    } catch (final Exception e) {
        ErlLogger.warn(e);
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) Subscribe(com.google.common.eventbus.Subscribe)

Example 77 with OtpErlangAtom

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

the class IOServer method processRequest.

private OtpErlangObject processRequest(final OtpErlangPid from, final OtpErlangObject arequest) {
    if (callback == null) {
        return error;
    }
    OtpBindings b;
    try {
        if (arequest instanceof OtpErlangTuple) {
            final OtpErlangTuple request = (OtpErlangTuple) arequest;
            final String tag = ((OtpErlangAtom) request.elementAt(0)).atomValue();
            if ("put_chars".equals(tag)) {
                b = OtpErlang.match("{put_chars, Chars}", request);
                if (b != null) {
                    return callback.putChars(from, IOEncoding.latin1, b.get("Chars"));
                }
                b = OtpErlang.match("{put_chars, Enc:a, Chars}", request);
                if (b != null) {
                    final String enc = b.getAtom("Enc");
                    return callback.putChars(from, IOEncoding.valueOf(enc), b.get("Chars"));
                }
                b = OtpErlang.match("{put_chars, M:a, F:a, A}", request);
                if (b != null) {
                    final String m = b.getAtom("M");
                    final String f = b.getAtom("F");
                    final Collection<OtpErlangObject> a = b.getList("A");
                    return callback.putChars(from, IOEncoding.latin1, m, f, a);
                }
                b = OtpErlang.match("{put_chars, Enc:a, M:a, F:a, A}", request);
                if (b != null) {
                    final String enc = b.getAtom("Enc");
                    final String m = b.getAtom("M");
                    final String f = b.getAtom("F");
                    final Collection<OtpErlangObject> a = b.getList("A");
                    return callback.putChars(from, IOEncoding.valueOf(enc), m, f, a);
                }
                return error;
            } else if ("get_until".equals(tag)) {
                b = OtpErlang.match("{get_until, Prompt}", request);
                if (b != null) {
                    return callback.getUntil(IOEncoding.latin1, b.get("Prompt"));
                }
                b = OtpErlang.match("{get_until, Prompt, N:i}", request);
                if (b != null) {
                    final long n = b.getLong("N");
                    return callback.getUntil(IOEncoding.latin1, b.get("Prompt"), n);
                }
                b = OtpErlang.match("{get_until, Enc:a, Prompt}", request);
                if (b != null) {
                    final String enc = b.getAtom("Enc");
                    return callback.getUntil(IOEncoding.valueOf(enc), b.get("Prompt"));
                }
                b = OtpErlang.match("{get_until, Enc:a, Prompt, N:i}", request);
                if (b != null) {
                    final String enc = b.getAtom("Enc");
                    final long n = b.getLong("N");
                    return callback.getUntil(IOEncoding.valueOf(enc), b.get("Prompt"), n);
                }
                b = OtpErlang.match("{get_until, Prompt, M:a, F:a, A}", request);
                if (b != null) {
                    final String m = b.getAtom("M");
                    final String f = b.getAtom("F");
                    final Collection<OtpErlangObject> a = b.getList("A");
                    return callback.getUntil(IOEncoding.latin1, b.get("Prompt"), m, f, a);
                }
                b = OtpErlang.match("{get_until, Enc: a, Prompt, M:a, F:a, A}", request);
                if (b != null) {
                    final String enc = b.getAtom("Enc");
                    final String m = b.getAtom("M");
                    final String f = b.getAtom("F");
                    final Collection<OtpErlangObject> a = b.getList("A");
                    return callback.getUntil(IOEncoding.valueOf(enc), b.get("Prompt"), m, f, a);
                }
            } else if ("requests".equals(tag)) {
                b = OtpErlang.match("{requests, Reqs:lx}", request);
                if (b != null) {
                    final Collection<OtpErlangObject> reqs = b.getList("Reqs");
                    OtpErlangObject val = null;
                    for (final OtpErlangObject r : reqs) {
                        val = processRequest(from, r);
                        if (val.equals(error)) {
                            return error;
                        }
                    }
                    return val == null ? error : val;
                }
            } else if ("setopts".equals(tag)) {
                b = OtpErlang.match("{setopts, Opts:lx}", request);
                if (b != null) {
                    final Collection<OtpErlangObject> opts = b.getList("Opts");
                    return callback.setOpts(opts);
                }
            } else if ("get_geometry".equals(tag)) {
                return OtpErlang.mkTuple(new OtpErlangAtom("error"), new OtpErlangAtom("enotsup"));
            } else {
                return error;
            }
        } else if (arequest instanceof OtpErlangAtom) {
            final OtpErlangAtom tag = (OtpErlangAtom) arequest;
            if ("getopts".equals(tag.atomValue())) {
                return callback.getOpts();
            }
            return error;
        } else {
            return error;
        }
    } catch (final OtpParserException e) {
        ErlLogger.error(e);
    } catch (final OtpErlangException e) {
        ErlLogger.error(e);
    }
    return error;
}
Also used : OtpParserException(org.erlide.util.erlang.OtpParserException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) OtpBindings(org.erlide.util.erlang.OtpBindings) Collection(java.util.Collection) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 78 with OtpErlangAtom

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

the class LogEventHandler method handleEvent.

@Subscribe
public void handleEvent(final ErlEvent event) {
    if (!event.getTopic().equals(getTopic())) {
        return;
    }
    final OtpErlangObject data = event.getEvent();
    try {
        final OtpBindings b = OtpErlang.match("{K:a,M}", data);
        final String kind = ((OtpErlangAtom) b.get("K")).atomValue();
        final OtpErlangObject amsg = b.get("M");
        ErlLogger.debug("%s: %s", kind, OtpErlang.asString(amsg));
    } catch (final Exception e) {
        ErlLogger.error("erroneous log msg: %s", data);
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpBindings(org.erlide.util.erlang.OtpBindings) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) Subscribe(com.google.common.eventbus.Subscribe)

Example 79 with OtpErlangAtom

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

the class IErlAttributeTest method getValue.

@Test
public void getValue() throws Exception {
    module.open(null);
    final IErlElement element = module.getElementAtLine(0);
    final IErlAttribute attribute = (IErlAttribute) element;
    final IErlElement element2 = module.getElementAtLine(1);
    final IErlAttribute attribute2 = (IErlAttribute) element2;
    final OtpErlangAtom xx = new OtpErlangAtom("xx");
    final OtpErlangString yyHrl = new OtpErlangString("yy.hrl");
    assertEquals(xx, attribute.getValue());
    assertEquals(yyHrl, attribute2.getValue());
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Test(org.junit.Test)

Example 80 with OtpErlangAtom

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

the class SimpleParserTest method parse_1.

@Test
public void parse_1() {
    final String input = "a. 1. [c].";
    final List<@NonNull OtpErlangObject> expected = Lists.newArrayList(new OtpErlangAtom("a"), new OtpErlangLong(1), new OtpErlangList(new OtpErlangAtom("c")));
    final List<OtpErlangObject> actual = parser.parse(input);
    assertThat(actual).containsAtLeastElementsIn(expected).inOrder();
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) 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)16 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