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);
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations