Search in sources :

Example 51 with OtpErlangAtom

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

the class TypeConverter method mapToProplist.

public static OtpErlangObject mapToProplist(final Map<String, OtpErlangObject> map) {
    final Set<Entry<String, OtpErlangObject>> v = map.entrySet();
    final OtpErlangObject[] vv = new OtpErlangObject[v.size()];
    int i = 0;
    for (final Entry<String, OtpErlangObject> entry : v) {
        final OtpErlangAtom key = new OtpErlangAtom(entry.getKey());
        final OtpErlangObject value = entry.getValue();
        vv[i] = OtpErlang.mkTuple(key, value);
        i++;
    }
    return new OtpErlangList(vv);
}
Also used : Entry(java.util.Map.Entry) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 52 with OtpErlangAtom

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

the class EUnitEventHandler method handleEvent.

@Subscribe
public void handleEvent(final ErlEvent event) {
    if (!event.getTopic().equals(getTopic())) {
        return;
    }
    final OtpErlangObject data = event.getEvent();
    if (!(data instanceof OtpErlangTuple) || !(((OtpErlangTuple) data).elementAt(0) instanceof OtpErlangAtom)) {
        return;
    }
    final OtpErlangTuple msg = (OtpErlangTuple) data;
    final OtpErlangAtom resType = (OtpErlangAtom) msg.elementAt(0);
    log.info(resType);
    if (resType.atomValue().equals(EUnitEventHandler.GROUP_BEGIN)) {
        handle_group_begin(msg);
    } else if (resType.atomValue().equals(EUnitEventHandler.TEST_BEGIN)) {
    } else if (resType.atomValue().equals(EUnitEventHandler.TEST_END)) {
        handle_test(msg);
    } else if (resType.atomValue().equals(EUnitEventHandler.GROUP_END)) {
        handle_group(msg);
    } else if (resType.atomValue().equals(EUnitEventHandler.SUMMARY)) {
        handle_summary(msg);
        for (final IEUnitObserver obs : coverBackend.getEUnitListeners()) {
            obs.labelChanged();
        }
    } else if (resType.atomValue().equals(EUnitEventHandler.ERROR)) {
        handle_error(msg);
    } else if (resType.atomValue().equals(EUnitEventHandler.SKIPPED)) {
        handle_skipped(msg);
    } else if (resType.atomValue().equals(EUnitEventHandler.TEST_CANCELED)) {
        handle_test_canceled(msg);
    } else if (resType.atomValue().equals(EUnitEventHandler.GROUP_CANCELED)) {
        handle_group_canceled(msg);
    }
    for (final IEUnitObserver obs : coverBackend.getEUnitListeners()) {
        obs.treeChanged();
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) Subscribe(com.google.common.eventbus.Subscribe)

Example 53 with OtpErlangAtom

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

the class TraceDataHandler method processFileInfo.

private ITreeNode processFileInfo(final OtpErlangTuple tuple) {
    TracingResultsNode node = null;
    if (tuple.elementAt(TraceDataHandler.INDEX_INFO_START_DATE) instanceof OtpErlangAtom) {
        // file contains no trace events
        return null;
    }
    try {
        final Date from = readDateTuple((OtpErlangTuple) tuple.elementAt(TraceDataHandler.INDEX_INFO_START_DATE));
        final Date to = readDateTuple((OtpErlangTuple) tuple.elementAt(TraceDataHandler.INDEX_INFO_END_DATE));
        final String path = ((OtpErlangString) tuple.elementAt(TraceDataHandler.INDEX_INFO_PATH)).stringValue();
        final long size = ((OtpErlangLong) tuple.elementAt(TraceDataHandler.INDEX_INFO_COUNT)).longValue();
        node = new TracingResultsNode();
        node.setStartDate(from);
        node.setEndDate(to);
        node.setFileName(path);
        node.setSize(size);
        // node label
        final String builder = infoDateFormatter.format(from) + " - " + infoDateFormatter.format(to) + " (" + size + " traces): " + path;
        node.setLabel(builder);
    } catch (final OtpErlangRangeException e) {
        ErlLogger.error(e);
    }
    return node;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) TracingResultsNode(org.erlide.tracing.core.mvc.model.treenodes.TracingResultsNode) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Date(java.util.Date) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 54 with OtpErlangAtom

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

the class TraceDataHandler method createFunctionNode.

private ITreeNode createFunctionNode(final String label, final OtpErlangObject erlangObject) {
    final ITreeNode node = new TreeNode();
    if (erlangObject instanceof OtpErlangTuple) {
        final OtpErlangTuple functionTuple = (OtpErlangTuple) erlangObject;
        final OtpErlangAtom moduleName = (OtpErlangAtom) functionTuple.elementAt(TraceDataHandler.INDEX_FUNCTION_MODULE);
        final OtpErlangAtom functionName = (OtpErlangAtom) functionTuple.elementAt(TraceDataHandler.INDEX_FUNCTION_NAME);
        // args or arity node
        final TreeNode argsNode = new TreeNode();
        argsNode.setImage(Activator.getImage(Images.INFO_NODE));
        final OtpErlangObject arityOrArgs = functionTuple.elementAt(TraceDataHandler.INDEX_FUNCTION_ARGS);
        int arityValue = -1;
        if (arityOrArgs instanceof OtpErlangList) {
            // last element is a list of arguments
            final OtpErlangList arguments = (OtpErlangList) arityOrArgs;
            final StringBuilder builder = new StringBuilder("arguments: ");
            for (int i = 1; i < arguments.arity(); i++) {
                builder.append(arguments.elementAt(i)).append(", ");
            }
            arityValue = arguments.arity() - 1;
            argsNode.setLabel(builder.substring(0, builder.length() - 2));
        } else {
            // last element is arity
            try {
                if (functionTuple.elementAt(TraceDataHandler.INDEX_FUNCTION_ARGS) instanceof OtpErlangInt) {
                    arityValue = ((OtpErlangInt) functionTuple.elementAt(TraceDataHandler.INDEX_FUNCTION_ARGS)).intValue();
                } else {
                    arityValue = (int) ((OtpErlangLong) functionTuple.elementAt(TraceDataHandler.INDEX_FUNCTION_ARGS)).longValue();
                }
                argsNode.setLabel("arity: " + arityValue);
            } catch (final OtpErlangRangeException e) {
                ErlLogger.error(e);
            }
        }
        // module name node
        final TreeNode moduleNameNode = new ModuleNode(moduleName.atomValue());
        moduleNameNode.setLabel("module: " + moduleName);
        // function name node
        final TreeNode functionNameNode = new FunctionNode(moduleName.atomValue(), functionName.atomValue(), arityValue);
        functionNameNode.setLabel("function: " + functionName);
        node.addChildren(moduleNameNode, functionNameNode, argsNode);
        lastFunctionDescription = label + moduleName + ":" + functionName + "/" + arityValue;
    } else {
        lastFunctionDescription = "unknown";
    }
    node.setLabel(lastFunctionDescription);
    return node;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) FunctionNode(org.erlide.tracing.core.mvc.model.treenodes.FunctionNode) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) ITreeNode(org.erlide.tracing.core.mvc.model.treenodes.ITreeNode) TreeNode(org.erlide.tracing.core.mvc.model.treenodes.TreeNode) ITreeNode(org.erlide.tracing.core.mvc.model.treenodes.ITreeNode) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangInt(com.ericsson.otp.erlang.OtpErlangInt) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) ModuleNode(org.erlide.tracing.core.mvc.model.treenodes.ModuleNode)

Example 55 with OtpErlangAtom

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

the class TraceBackend method start.

/**
 * Starts tracing given nodes.
 *
 * @return <code>true</code> if successful, <code>false</code> otherwise
 */
public TracingStatus start() {
    TracingStatus status = TracingStatus.OK;
    if (!tracing) {
        synchronized (this) {
            if (!tracing) {
                try {
                    tracing = true;
                    getBackend(true);
                    loadingFileInfo = true;
                    handler = new TraceEventHandler();
                    tracerBackend.getRuntime().registerEventListener(handler);
                    // list of nodes being traced
                    final List<OtpErlangObject> erlangObjects = new ArrayList<>();
                    notActivatedNodes = new HashSet<>();
                    for (final TracedNode tracedNode : tracedNodes) {
                        if (tracedNode.isEnabled()) {
                            final OtpErlangAtom name = new OtpErlangAtom(tracedNode.getNodeName());
                            final OtpErlangAtom cookie = new OtpErlangAtom(tracedNode.getCookie());
                            erlangObjects.add(new OtpErlangTuple(new OtpErlangObject[] { name, cookie }));
                            notActivatedNodes.add(tracedNode.getNodeName());
                        }
                    }
                    final OtpErlangList nodes = new OtpErlangList(erlangObjects.toArray(new OtpErlangObject[erlangObjects.size()]));
                    // net tick time
                    final int tickTimeValue = Activator.getDefault().getPreferenceStore().getInt(PreferenceNames.TICK_TIME);
                    final OtpErlangInt netTickTime = new OtpErlangInt(tickTimeValue);
                    final OtpErlangObject callResult = tracerBackend.getOtpRpc().call(Constants.ERLANG_HELPER_MODULE, TraceBackend.FUN_START, "xsi", nodes, Constants.OUTPUT_FILE, netTickTime);
                    status = processResult(callResult);
                    if (TracingStatus.OK.equals(status) || TracingStatus.NOT_ALL_NODES_ACTIVATED.equals(status)) {
                        setProcessFlags();
                        setFunctionTracePatterns();
                        for (final ITraceNodeObserver listener : listeners) {
                            try {
                                listener.startTracing();
                            } catch (final Exception e) {
                                ErlLogger.error(e);
                            }
                        }
                    } else {
                        tracing = false;
                    }
                } catch (final Exception e) {
                    ErlLogger.error(e);
                    status = TracingStatus.EXCEPTION_THROWN;
                    errorObject = e;
                    tracing = false;
                }
            }
        }
    }
    return status;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) TracedNode(org.erlide.tracing.core.mvc.model.TracedNode) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangInt(com.ericsson.otp.erlang.OtpErlangInt) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

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