Search in sources :

Example 16 with OtpErlangRangeException

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;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 17 with OtpErlangRangeException

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);
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 18 with OtpErlangRangeException

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));
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IDebugTarget(org.eclipse.debug.core.model.IDebugTarget) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint)

Example 19 with OtpErlangRangeException

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;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ErlFunction(org.erlide.engine.internal.model.erlang.ErlFunction) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 20 with OtpErlangRangeException

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;
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Aggregations

OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)23 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)18 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)18 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)16 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)8 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)7 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)4 ArrayList (java.util.ArrayList)3 RpcException (org.erlide.runtime.rpc.RpcException)3 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)3 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)1 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)1 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)1 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)1 TreeElement (com.intellij.ide.util.treeView.smartTree.TreeElement)1 Date (java.util.Date)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1