Search in sources :

Example 1 with ModuleNode

use of org.erlide.tracing.core.mvc.model.treenodes.ModuleNode 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 2 with ModuleNode

use of org.erlide.tracing.core.mvc.model.treenodes.ModuleNode 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);
    }
}
Also used : ITreeNode(org.erlide.tracing.core.mvc.model.treenodes.ITreeNode) CoreException(org.eclipse.core.runtime.CoreException) FunctionNode(org.erlide.tracing.core.mvc.model.treenodes.FunctionNode) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModuleNode(org.erlide.tracing.core.mvc.model.treenodes.ModuleNode)

Aggregations

FunctionNode (org.erlide.tracing.core.mvc.model.treenodes.FunctionNode)2 ITreeNode (org.erlide.tracing.core.mvc.model.treenodes.ITreeNode)2 ModuleNode (org.erlide.tracing.core.mvc.model.treenodes.ModuleNode)2 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeNode (org.erlide.tracing.core.mvc.model.treenodes.TreeNode)1