Search in sources :

Example 6 with OtpErlangException

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

the class TestCaseData method parseReason.

private FailReason parseReason(final OtpErlangObject reason) {
    OtpBindings b;
    try {
        b = OtpErlang.match("{Cause, Stack}", reason);
        if (b == null) {
            return new FailReason("internal error: " + reason.toString(), TestCaseData.NO_STACK);
        }
        final Collection<OtpErlangObject> stack = b.getList("Stack");
        return new FailReason(b.get("Cause").toString(), stack);
    } catch (final OtpParserException e) {
        ErlLogger.warn(e);
    } catch (final OtpErlangException e) {
        ErlLogger.warn(e);
    }
    return null;
}
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)

Example 7 with OtpErlangException

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

the class Util method stringValue.

/**
 * Get the string value of an Erlang string, empty if empty list
 *
 * @param o
 *            Erlang string or list
 * @return string value
 */
public static String stringValue(final OtpErlangObject o) {
    if (o instanceof OtpErlangString) {
        final OtpErlangString s = (OtpErlangString) o;
        return s.stringValue();
    } else if (o instanceof OtpErlangList) {
        final OtpErlangList l = (OtpErlangList) o;
        if (l.arity() == 0) {
            return "";
        }
        try {
            return l.stringValue();
        } catch (final OtpErlangException e) {
            ErlLogger.error(e);
            return null;
        }
    } else if (o instanceof OtpErlangBinary) {
        final OtpErlangBinary b = (OtpErlangBinary) o;
        String result;
        result = Util.decode(b.binaryValue(), Charsets.UTF_8);
        if (result == null) {
            result = Util.decode(b.binaryValue(), Charsets.ISO_8859_1);
        }
        if (result == null) {
            ErlLogger.error("bad binary value in stringValue" + " (can't decode): " + o);
        }
        return result;
    }
    // ErlLogger.warn("bad value in stringValue: " + o);
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 8 with OtpErlangException

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

the class OtpParser method parseList.

private static OtpErlangObject parseList(final List<Token> tokens, final Stack<OtpErlangObject> stack, final OtpErlangObject tail) throws OtpParserException {
    if (tokens.isEmpty()) {
        return null;
    }
    final Token t = tokens.get(0);
    if (t.kind == TokenKind.LISTEND) {
        tokens.remove(0);
        try {
            return new OtpErlangList(stack.toArray(new OtpErlangObject[stack.size()]), tail);
        } catch (final OtpErlangException e) {
            ErlLogger.error(e);
            // can't happen
            return null;
        }
    }
    OtpErlangObject atail = tail;
    if (t.kind == TokenKind.CONS) {
        tokens.remove(0);
        atail = OtpParser.parse(tokens);
    } else {
        stack.push(OtpParser.parse(tokens));
        if (tokens.get(0).kind == TokenKind.COMMA) {
            tokens.remove(0);
        } else if (tokens.get(0).kind != TokenKind.LISTEND && tokens.get(0).kind != TokenKind.CONS) {
            throw new OtpParserException("missing comma in list");
        }
    }
    return OtpParser.parseList(tokens, stack, atail);
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException)

Aggregations

OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)8 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)5 OtpBindings (org.erlide.util.erlang.OtpBindings)5 OtpParserException (org.erlide.util.erlang.OtpParserException)5 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)3 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)1 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)1 ErlRange (org.erlide.wrangler.refactoring.util.ErlRange)1 IErlRange (org.erlide.wrangler.refactoring.util.IErlRange)1 Range (org.erlide.wrangler.refactoring.util.Range)1