Search in sources :

Example 66 with OtpErlangAtom

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

the class ErlParser method create.

/**
 * create an IErlMember from a tuple from noparse
 *
 * @param el
 *            the tuple, either function or attribute
 * @return
 */
private IErlMember create(final IErlModule module, final OtpErlangTuple el) {
    final OtpErlangAtom type = (OtpErlangAtom) el.elementAt(0);
    final String typeS = type.atomValue();
    if ("error".equals(typeS)) {
        final OtpErlangTuple er = (OtpErlangTuple) el.elementAt(1);
        final String msg = helper.formatError(er);
        final ErlParserProblem e = ErlParserProblem.newError(module, msg);
        setPos(e, er.elementAt(0));
        return e;
    } else if ("tree".equals(typeS)) {
        final OtpErlangTuple atr = (OtpErlangTuple) el.elementAt(3);
        final OtpErlangObject pos = ((OtpErlangTuple) el.elementAt(2)).elementAt(1);
        final OtpErlangTuple name = (OtpErlangTuple) atr.elementAt(1);
        final OtpErlangAtom n = (OtpErlangAtom) concreteTerm(name);
        final OtpErlangObject val = atr.elementAt(2);
        final OtpErlangObject extra = el.arity() > 4 ? el.elementAt(4) : null;
        return addAttribute(module, pos, n, val, extra, null);
    } else if ("attribute".equals(typeS)) {
        final OtpErlangObject pos = el.elementAt(1);
        final OtpErlangAtom name = (OtpErlangAtom) el.elementAt(2);
        final OtpErlangObject val = el.elementAt(3);
        final OtpErlangObject extra = el.arity() > 4 ? el.elementAt(4) : null;
        final OtpErlangObject arity = el.arity() > 5 ? el.elementAt(5) : null;
        return addAttribute(module, pos, name, val, extra, arity);
    } else if ("function".equals(typeS)) {
        final ErlFunction f = makeErlFunction(module, el);
        final OtpErlangList clauses = (OtpErlangList) el.elementAt(6);
        final List<ErlFunctionClause> cls = Lists.newArrayListWithCapacity(clauses.arity());
        for (int i = 0; i < clauses.arity(); i++) {
            final OtpErlangTuple clause = (OtpErlangTuple) clauses.elementAt(i);
            final ErlFunctionClause cl = makeErlFunctionClause(f, i, clause);
            cls.add(cl);
        }
        f.setChildren(cls);
        return f;
    } else {
        ErlLogger.debug("unknown: " + typeS);
    }
    return null;
}
Also used : 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) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) List(java.util.List) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) ErlFunctionClause(org.erlide.engine.internal.model.erlang.ErlFunctionClause)

Example 67 with OtpErlangAtom

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

the class ErlParser method addMacroDef.

private IErlMember addMacroDef(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra, final String nameS) {
    if (val instanceof OtpErlangAtom) {
        final String s = Util.stringValue(extra);
        final ErlMember r = new ErlMacroDef(module, ((OtpErlangAtom) val).atomValue(), s);
        setPos(r, pos);
        // r.setParseTree(val);
        return r;
    } else if (val instanceof OtpErlangList) {
        final OtpErlangList macroList = (OtpErlangList) val;
        if (macroList.elementAt(0) instanceof OtpErlangTuple) {
            final OtpErlangTuple macroNameTuple = (OtpErlangTuple) macroList.elementAt(0);
            OtpErlangObject o = macroNameTuple.elementAt(2);
            if (o instanceof OtpErlangTuple) {
                o = ((OtpErlangTuple) o).elementAt(2);
            }
            ErlMember r;
            if (o instanceof OtpErlangAtom) {
                final String macroName = ((OtpErlangAtom) o).atomValue();
                r = new ErlMacroDef(module, macroName, null);
            } else {
                // what do we do here? the define isn't correct
                // Erlang...
                ErlLogger.warn("Strange macro definition in %s: %s", module.getName(), o.toString());
                r = new ErlMacroDef(module, o.toString(), null);
            }
            setPos(r, pos);
            // r.setParseTree(val);
            return r;
        }
    }
    return addOtherAttribute(module, pos, val, extra, nameS);
}
Also used : ErlMacroDef(org.erlide.engine.internal.model.erlang.ErlMacroDef) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ErlMember(org.erlide.engine.internal.model.erlang.ErlMember) IErlMember(org.erlide.engine.model.erlang.IErlMember) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 68 with OtpErlangAtom

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

the class ErlParser method addImportAttribute.

private IErlImport addImportAttribute(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val) {
    final OtpErlangTuple t = (OtpErlangTuple) val;
    if (t.elementAt(0) instanceof OtpErlangAtom && t.elementAt(1) instanceof OtpErlangList) {
        final OtpErlangAtom importModule = (OtpErlangAtom) t.elementAt(0);
        final OtpErlangList functionList = (OtpErlangList) t.elementAt(1);
        final ErlImport imp = new ErlImport(module, importModule.atomValue(), functionList);
        setPos(imp, pos);
        return imp;
    }
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) ErlImport(org.erlide.engine.internal.model.erlang.ErlImport) IErlImport(org.erlide.engine.model.erlang.IErlImport)

Example 69 with OtpErlangAtom

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

the class OtpRpc method async_call_result.

@Override
public void async_call_result(final IRpcResultCallback cb, final String m, final String f, final String signature, final Object... args) throws RpcException {
    final OtpErlangAtom gleader = OtpRpc.USER_ATOM;
    try {
        final Object[] args1 = new Object[args.length + 1];
        System.arraycopy(args, 0, args1, 1, args.length);
        final OtpMbox mbox = localNode.createMbox();
        args1[0] = mbox.self();
        new RpcResultReceiver(mbox, cb);
        rpcCast(localNode, nodeName, false, gleader, m, f, signature, args1);
    } catch (final SignatureException e) {
        throw new RpcException(e);
    }
}
Also used : OtpMbox(com.ericsson.otp.erlang.OtpMbox) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) SignatureException(org.erlide.util.erlang.SignatureException)

Example 70 with OtpErlangAtom

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

the class RpcResultReceiver method run.

@Override
public void run() {
    boolean done = false;
    do {
        OtpErlangObject msg;
        try {
            msg = mbox.receive(3000);
            if (msg != null) {
                if (msg instanceof OtpErlangTuple) {
                    final OtpErlangTuple tuple = (OtpErlangTuple) msg;
                    final String tag = ((OtpErlangAtom) tuple.elementAt(0)).atomValue();
                    if ("start".equals(tag)) {
                        callback.start(tuple.elementAt(1));
                    } else if ("stop".equals(tag)) {
                        done = true;
                        callback.stop(tuple.elementAt(1));
                    } else if ("progress".equals(tag)) {
                        callback.progress(tuple.elementAt(1));
                    }
                }
            }
        } catch (final Exception e) {
            ErlLogger.error(e);
        }
    } while (!done || Thread.interrupted());
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) 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