use of com.ericsson.otp.erlang.OtpErlangRangeException in project erlide_eclipse by erlang.
the class Util method ioListToStringBuilder.
private static StringBuilder ioListToStringBuilder(final OtpErlangObject o, final StringBuilder sb0, final int maxLength) {
StringBuilder sb = sb0;
if (sb.length() >= maxLength) {
return sb;
}
if (o instanceof OtpErlangLong) {
final OtpErlangLong l = (OtpErlangLong) o;
try {
sb.append(l.charValue());
} catch (final OtpErlangRangeException e) {
}
} else if (o instanceof OtpErlangString) {
final OtpErlangString s = (OtpErlangString) o;
sb.append(s.stringValue());
} else if (o instanceof OtpErlangList) {
final OtpErlangList l = (OtpErlangList) o;
for (final OtpErlangObject i : l) {
if (sb.length() < maxLength) {
Util.ioListToStringBuilder(i, sb, maxLength);
}
}
if (sb.length() < maxLength) {
Util.ioListToStringBuilder(l.getLastTail(), sb, maxLength);
}
} else if (o instanceof OtpErlangBinary) {
final OtpErlangBinary b = (OtpErlangBinary) o;
String s = Util.decode(b.binaryValue(), Charsets.UTF_8);
if (s == null) {
s = new String(b.binaryValue(), Charsets.ISO_8859_1);
}
sb.append(s);
} else if (o != null) {
sb.append(o.toString());
}
if (sb.length() > maxLength) {
sb = new StringBuilder(sb.substring(0, maxLength));
sb.append("... <truncated>");
}
return sb;
}
use of com.ericsson.otp.erlang.OtpErlangRangeException in project erlide_eclipse by erlang.
the class DialyzerUtils method checkDialyzeError.
public static void checkDialyzeError(final OtpErlangObject result) throws DialyzerErrorException {
if (result == null) {
throw new DialyzerErrorException("Could not execute dialyzer, please check settings.");
}
if (result instanceof OtpErlangTuple) {
final OtpErlangTuple t = (OtpErlangTuple) result;
if (t.arity() > 0) {
final OtpErlangObject element = t.elementAt(0);
if (element instanceof OtpErlangLong) {
final OtpErlangLong l = (OtpErlangLong) element;
try {
final int d = l.intValue();
if (d == 0 || d == 1 || d == 2) {
return;
}
} catch (final OtpErlangRangeException e) {
}
}
}
final String s = Util.ioListToString(t.elementAt(1), DialyzerUtils.MAX_MSG_LEN + 10);
final String r = s.replaceAll("\\\\n", "\n");
if (s.length() > DialyzerUtils.MAX_MSG_LEN) {
ErlLogger.error("%s", s);
}
throw new DialyzerErrorException(r);
}
}
use of com.ericsson.otp.erlang.OtpErlangRangeException in project erlide_eclipse by erlang.
the class ErlangProcess method setStackFrames.
public void setStackFrames(final String module, final int line, final OtpErlangList erlStackFrames, final OtpErlangList bs) {
stackFrames = new ArrayList<>();
final IDebugTarget target = getDebugTarget();
stackFrames.add(new ErlangStackFrame(module, this, target, line, null, bs, erlStackFrames.arity() + 2));
for (final OtpErlangObject o : erlStackFrames) {
final OtpErlangTuple t = (OtpErlangTuple) o;
final OtpErlangTuple mfa;
final OtpErlangObject el0 = t.elementAt(0);
final OtpErlangObject el1 = t.elementAt(1);
if (el0 instanceof OtpErlangTuple) {
mfa = (OtpErlangTuple) el0;
} else if (el1 instanceof OtpErlangTuple) {
mfa = (OtpErlangTuple) el1;
} else {
mfa = t;
}
int stackFrameNo;
final OtpErlangObject mfa0 = mfa.elementAt(0);
if (!(mfa0 instanceof OtpErlangAtom)) {
ErlLogger.debug("%s", mfa0);
}
final OtpErlangAtom m = (OtpErlangAtom) mfa0;
final OtpErlangLong l = (OtpErlangLong) t.elementAt(1);
final OtpErlangList bindings = (OtpErlangList) t.elementAt(2);
final OtpErlangLong n = (OtpErlangLong) t.elementAt(3);
int lin;
try {
lin = l.intValue();
} catch (final OtpErlangRangeException e) {
lin = -1;
}
final String mod = m.atomValue();
try {
stackFrameNo = n.intValue();
} catch (final OtpErlangRangeException e) {
stackFrameNo = -1;
}
stackFrames.add(new ErlangStackFrame(mod, this, target, lin, null, bindings, stackFrameNo));
}
}
use of com.ericsson.otp.erlang.OtpErlangRangeException in project erlide_eclipse by erlang.
the class ErlParser method makeErlFunction.
/**
* @param module
* module
* @param el
* -record(function, {pos, name, arity, args, head, clauses, name_pos,
* comment, exported}).
* @return ErlFunction
*/
private ErlFunction makeErlFunction(final IErlModule module, final OtpErlangTuple el) {
final OtpErlangTuple pos = (OtpErlangTuple) el.elementAt(1);
final OtpErlangAtom name = (OtpErlangAtom) el.elementAt(2);
final OtpErlangLong arity = (OtpErlangLong) el.elementAt(3);
final OtpErlangList parameters = (OtpErlangList) el.elementAt(4);
final OtpErlangObject head = el.elementAt(5);
final OtpErlangTuple namePos = (OtpErlangTuple) el.elementAt(7);
ErlFunction f = null;
final OtpErlangAtom exportedA = (OtpErlangAtom) el.elementAt(8);
final boolean exported = Boolean.parseBoolean(exportedA.atomValue());
try {
f = new ErlFunction(module, name.atomValue(), arity.intValue(), Util.stringValue(head), exported, parameters);
} catch (final OtpErlangRangeException e) {
return f;
}
setPos(f, pos);
try {
setNamePos(f, namePos);
} catch (final OtpErlangRangeException e) {
}
return f;
}
use of com.ericsson.otp.erlang.OtpErlangRangeException in project erlide_eclipse by erlang.
the class ErlParser method setPos.
private boolean setPos(final SourceRefElement e, final OtpErlangObject pos) {
if (!(pos instanceof OtpErlangTuple)) {
if (pos instanceof OtpErlangLong) {
int ipos = 999999;
try {
ipos = ((OtpErlangLong) pos).intValue();
} catch (final OtpErlangRangeException e1) {
}
setPos(e, 0, 0, ipos, 0);
return true;
}
ErlLogger.debug("!> expecting pos tuple, got " + pos);
return false;
}
try {
// pos=
// {{Line, LastLine, Offset}, PosLength} or
// {{Line, Offset}, PosLength}
final OtpErlangTuple tpos = (OtpErlangTuple) pos;
final OtpErlangTuple tpos1 = (OtpErlangTuple) tpos.elementAt(0);
final OtpErlangLong lenL = (OtpErlangLong) tpos.elementAt(1);
final OtpErlangLong lineL = (OtpErlangLong) tpos1.elementAt(0);
final OtpErlangLong lastLineL = (OtpErlangLong) tpos1.elementAt(1);
final int line = lineL.intValue();
int lastLine = lastLineL.intValue();
int ofs;
if (tpos1.arity() > 2) {
ofs = ((OtpErlangLong) tpos1.elementAt(2)).intValue();
} else {
ofs = lastLine;
lastLine = line;
}
final int len = lenL.intValue();
setPos(e, line, lastLine, ofs, len);
return true;
} catch (final OtpErlangRangeException ex) {
return false;
}
}
Aggregations