use of org.erlide.tracing.core.mvc.model.treenodes.FunctionNode 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 org.erlide.tracing.core.mvc.model.treenodes.FunctionNode in project erlide_eclipse by erlang.
the class TreeViewerView method doDoubleClick.
/**
* Action performed when user double-clicks on tree element.
*
* @param event
*/
private void doDoubleClick(final DoubleClickEvent event) {
final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
final ITreeNode treeNode = (ITreeNode) selection.getFirstElement();
try {
if (treeNode instanceof FunctionNode) {
final FunctionNode functionNode = (FunctionNode) treeNode;
ErlModelUtils.openMFA(functionNode.getModuleName(), functionNode.getFunctionName(), functionNode.getArity());
} else if (treeNode instanceof ModuleNode) {
final ModuleNode moduleNode = (ModuleNode) treeNode;
ErlModelUtils.openModule(moduleNode.getModuleName());
}
} catch (final CoreException e) {
ErlLogger.error(e);
}
}
Aggregations