Search in sources :

Example 71 with OtpErlangAtom

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

the class EventParser method isEventMessage.

public boolean isEventMessage(final OtpErlangObject msg) {
    try {
        final OtpErlangTuple tmsg = (OtpErlangTuple) msg;
        final OtpErlangObject el0 = tmsg.elementAt(0);
        return "event".equals(((OtpErlangAtom) el0).atomValue()) && tmsg.arity() == 4;
    } catch (final Exception e) {
        return false;
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 72 with OtpErlangAtom

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

the class EventParser method getEventTopic.

private String getEventTopic(final OtpErlangObject msg) {
    final OtpErlangTuple tmsg = (OtpErlangTuple) msg;
    final Object el0 = tmsg.elementAt(1);
    final OtpErlangAtom a = (OtpErlangAtom) el0;
    return a.atomValue();
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 73 with OtpErlangAtom

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

the class ErlideOpen method getExternalModuleTree.

@Override
public List<ExternalTreeEntry> getExternalModuleTree(final IOtpRpc backend, final String externalModules, final OtpErlangList pathVars) {
    ErlLogger.debug("open:external_module_tree -> " + externalModules);
    final Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        final OtpErlangObject res = backend.call(ErlideOpen.ERLIDE_OPEN, "get_external_module_tree", "x", mkContext(externalModules, null, pathVars, null, null));
        if (Util.isOk(res)) {
            OtpErlangTuple t = (OtpErlangTuple) res;
            final OtpErlangList l = (OtpErlangList) t.elementAt(1);
            final List<ExternalTreeEntry> result = Lists.newArrayListWithCapacity(l.arity());
            for (final OtpErlangObject i : l) {
                t = (OtpErlangTuple) i;
                final String parentPath = Util.stringValue(t.elementAt(0));
                final String path = Util.stringValue(t.elementAt(1));
                final OtpErlangAtom isModuleA = (OtpErlangAtom) t.elementAt(2);
                result.add(new ExternalTreeEntry(new Path(parentPath), new Path(path), "module".equals(isModuleA.atomValue())));
            }
            final String msg = "open:external_module_tree <- " + stopwatch;
            if (stopwatch.elapsed(TimeUnit.SECONDS) > 5) {
                ErlLogger.warn("WARNING " + msg);
            } else {
                ErlLogger.debug(msg);
            }
            return result;
        }
    } catch (final RpcException e) {
        ErlLogger.warn("open:external_module_tree TIMEOUT <- " + stopwatch);
        ErlLogger.warn(e);
    }
    return Lists.newArrayList();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) Stopwatch(com.google.common.base.Stopwatch) ExternalTreeEntry(org.erlide.engine.services.search.ExternalTreeEntry) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 74 with OtpErlangAtom

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

the class ErlideOpen method mkContext.

@Override
public OtpErlangTuple mkContext(final String externalModules, final String externalIncludes, final OtpErlangList pathVars, final Collection<IPath> extraSourcePaths, final Collection<OtpErlangObject> imports) {
    final OtpErlangAtom tag = new OtpErlangAtom("open_context");
    final OtpErlangAtom UNDEFINED = new OtpErlangAtom("undefined");
    final List<OtpErlangObject> result = Lists.newArrayList();
    // order must match definition of #open_context !
    // TODO use a proplist instead?
    result.add(tag);
    result.add(externalModules != null ? new OtpErlangString(externalModules) : UNDEFINED);
    result.add(externalIncludes != null ? new OtpErlangString(externalIncludes) : UNDEFINED);
    result.add(pathVars != null ? pathVars : UNDEFINED);
    result.add(extraSourcePaths != null ? OtpErlang.mkStringList(extraSourcePaths) : UNDEFINED);
    result.add(imports != null ? OtpErlang.mkList(imports) : UNDEFINED);
    return new OtpErlangTuple(result.toArray(new OtpErlangObject[] {}));
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 75 with OtpErlangAtom

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

the class BeamLoader method loadBeam.

public static boolean loadBeam(final IOtpRpc backend, final String moduleName, final OtpErlangBinary bin) {
    OtpErlangObject r = null;
    try {
        r = backend.call("code", "is_sticky", "a", moduleName);
        // TODO handle sticky directories
        if (!((OtpErlangAtom) r).booleanValue()) {
            r = backend.call("code", "load_binary", "asb", moduleName, moduleName + ".erl", bin);
        } else {
            ErlLogger.warn("sticky:: %s", moduleName);
            r = null;
        }
    } catch (final Exception e) {
        ErlLogger.warn(e);
    }
    if (r instanceof OtpErlangTuple) {
        final OtpErlangTuple t = (OtpErlangTuple) r;
        if (((OtpErlangAtom) t.elementAt(0)).atomValue().compareTo("module") == 0) {
            return true;
        }
    }
    // binary couldn't be extracted
    ErlLogger.error("Could not load " + moduleName + ": " + r);
    return false;
}
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