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;
}
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;
}
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);
}
Aggregations