Search in sources :

Example 61 with OtpErlangAtom

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

the class CommandData method addUserInput.

// non-interactive
public void addUserInput(final List<String> input) {
    final List<OtpErlangObject> argsTmp = new LinkedList<>();
    final OtpErlangObject[] userInput = new OtpErlangObject[input.size()];
    int i = 0;
    for (final String text : input) {
        userInput[i] = new OtpErlangString(text);
        i++;
    }
    for (final OtpErlangObject arg : args) {
        if (arg instanceof OtpErlangTuple && ((OtpErlangTuple) arg).elementAt(0).equals(new OtpErlangAtom("prompt"))) {
            argsTmp.add(new OtpErlangList(userInput));
        // TODO make it so that it adds input only once, check repeat
        // interactive
        } else {
            argsTmp.add(arg);
        }
    }
    args = argsTmp.toArray(new OtpErlangObject[0]);
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) LinkedList(java.util.LinkedList) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 62 with OtpErlangAtom

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

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

the class CoverEventHandler method gotResults.

/**
 * When coverage results came
 *
 * @param msg
 * @return
 */
private boolean gotResults(final OtpErlangObject msg) {
    if (msg instanceof OtpErlangTuple) {
        final OtpErlangTuple resTuple = (OtpErlangTuple) msg;
        if (resTuple.elementAt(0) instanceof OtpErlangAtom && ((OtpErlangAtom) resTuple.elementAt(0)).atomValue().equals(CoverEventHandler.COVER_RES)) {
            final String moduleName = resTuple.elementAt(1).toString();
            String htmlPath = resTuple.elementAt(2).toString();
            htmlPath = htmlPath.substring(1, htmlPath.length() - 1);
            final int allLines = Integer.parseInt(resTuple.elementAt(3).toString());
            final int coveredLines = Integer.parseInt(resTuple.elementAt(4).toString());
            final double percent = Double.parseDouble(resTuple.elementAt(5).toString());
            log.info(String.format("Module %s %s %d %d %f", moduleName, htmlPath, allLines, coveredLines, percent));
            final ModuleStats moduleStats = new ModuleStats();
            moduleStats.setLabel(moduleName);
            moduleStats.setHtmlPath(htmlPath);
            moduleStats.setLiniesCount(allLines);
            moduleStats.setCoverCount(coveredLines);
            try {
                final File file = new File(ErlangEngine.getInstance().getModel().findModule(moduleName).getFilePath());
                moduleStats.setMd5(MD5Checksum.getMD5(file));
            } catch (final Exception e) {
                ErlLogger.error(e);
            }
            // 
            prepLineResults((OtpErlangList) resTuple.elementAt(6), moduleStats);
            prepFuncResults((OtpErlangList) resTuple.elementAt(7), moduleStats);
            addModuleToTree(moduleStats);
            ModuleSet.add(moduleStats);
            return true;
        }
    }
    return false;
}
Also used : OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) ModuleStats(org.erlide.cover.views.model.ModuleStats) File(java.io.File)

Example 64 with OtpErlangAtom

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

the class ErlParser method addOtherAttribute.

private IErlAttribute addOtherAttribute(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra, final String nameS) {
    // user-defined attribute? or maybe if else endif...
    // OtpErlangObject val1 = concreteTerm(val);
    // if (val instanceof OtpErlangList) {
    // final OtpErlangList list = (OtpErlangList) val;
    // if (list.arity() == 0) {
    // val1 = null;
    // }
    // }
    // final ErlAttribute a = new ErlAttribute(parent, nameS, val1, null);
    OtpErlangObject o = val;
    if (o instanceof OtpErlangAtom) {
        final OtpErlangAtom u = (OtpErlangAtom) o;
        if ("u".equals(u.atomValue())) {
            o = null;
        }
    }
    final ErlAttribute a = new ErlAttribute(module, nameS, o, Util.stringValue(extra));
    setPos(a, pos);
    // a.setParseTree(val);
    return a;
}
Also used : IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) ErlAttribute(org.erlide.engine.internal.model.erlang.ErlAttribute) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 65 with OtpErlangAtom

use of com.ericsson.otp.erlang.OtpErlangAtom 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)

Aggregations

OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)87 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)56 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)48 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)32 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)24 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)17 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)14 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)11 RpcException (org.erlide.runtime.rpc.RpcException)11 OtpBindings (org.erlide.util.erlang.OtpBindings)9 IErlElement (org.erlide.engine.model.IErlElement)6 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)4 OtpErlangPid (com.ericsson.otp.erlang.OtpErlangPid)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)3 OtpErlangMap (com.ericsson.otp.erlang.OtpErlangMap)3 Subscribe (com.google.common.eventbus.Subscribe)3 Collection (java.util.Collection)3 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)2