Search in sources :

Example 6 with OtpErlangBinary

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

the class ErlideScanner method lightScanString.

@Override
public List<ErlToken> lightScanString(final String string, final int offset) throws ScannerException {
    OtpErlangObject r1 = null;
    try {
        r1 = backend.call("erlide_scanner", "light_scan_string", "ba", string, ErlideScanner.ENCODING);
    } catch (final Exception e) {
        throw new ScannerException("Could not parse string \"" + string + "\": " + e.getMessage());
    }
    if (r1 == null) {
        return null;
    }
    if (!(r1 instanceof OtpErlangTuple)) {
        throw new ScannerException("Could not parse string \"" + string + "\": weird return value " + r1);
    }
    final OtpErlangTuple t1 = (OtpErlangTuple) r1;
    List<ErlToken> toks = null;
    if (Util.isOk(t1)) {
        if (t1.elementAt(1) instanceof OtpErlangBinary) {
            final OtpErlangBinary b = (OtpErlangBinary) t1.elementAt(1);
            final byte[] bytes = b.binaryValue();
            toks = new ArrayList<>(bytes.length / 10);
            for (int i = 0; i < bytes.length; i += 10) {
                final ErlToken tk = new ErlToken(bytes, i, offset);
                toks.add(tk);
            }
            return toks;
        }
        throw new ScannerException("unexpected token format");
    }
    throw new ScannerException("Could not parse string \"" + string + "\": " + t1.toString());
}
Also used : ScannerException(org.erlide.engine.services.parsing.ScannerException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) ErlToken(org.erlide.engine.services.parsing.ErlToken) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) ScannerException(org.erlide.engine.services.parsing.ScannerException) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary)

Example 7 with OtpErlangBinary

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

the class UtilTest method stringValue_4.

@Test
public void stringValue_4() {
    final OtpErlangObject input = new OtpErlangBinary(new byte[] { 51, 52, 53 });
    final String expected = "345";
    final String actual = Util.stringValue(input);
    Assert.assertEquals(expected, actual);
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) Test(org.junit.Test)

Example 8 with OtpErlangBinary

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

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

the class UtilTest method stringValue_6.

@Test
public void stringValue_6() {
    final byte[] bytes = { (byte) 0xE8, (byte) 0x8F, (byte) 0xAF };
    final OtpErlangObject input = new OtpErlangBinary(bytes);
    final byte[] expected = bytes;
    final String actual = Util.stringValue(input);
    assertThat(actual.getBytes(Charsets.UTF_8)).isEqualTo(expected);
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) Test(org.junit.Test)

Example 10 with OtpErlangBinary

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

the class UtilTest method stringValue_5.

@Test
public void stringValue_5() {
    final byte[] bytes = { 197 - 256, 246 - 256 };
    final OtpErlangObject input = new OtpErlangBinary(bytes);
    final byte[] expected = bytes;
    final String actual = Util.stringValue(input);
    assertThat(actual.getBytes(Charsets.ISO_8859_1)).isEqualTo(expected);
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) Test(org.junit.Test)

Aggregations

OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)13 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)8 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)8 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)5 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)5 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)4 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)4 Test (org.junit.Test)3 RpcException (org.erlide.runtime.rpc.RpcException)2 OtpErlangChar (com.ericsson.otp.erlang.OtpErlangChar)1 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)1 OtpErlangMap (com.ericsson.otp.erlang.OtpErlangMap)1 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangRef (com.ericsson.otp.erlang.OtpErlangRef)1 Subscribe (com.google.common.eventbus.Subscribe)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1