Search in sources :

Example 36 with OtpErlangAtom

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

the class DebuggerTraceView method createViewer.

@Override
protected Viewer createViewer(final Composite parent) {
    viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION));
    // setViewer(viewer);
    // super.createPartControl(parent);
    // parent.setLayout(new FillLayout());
    viewer.getTree().setLinesVisible(true);
    viewer.setUseHashlookup(true);
    createColumns();
    viewer.setContentProvider(getContentProvider());
    viewer.setLabelProvider(new ColumnLabelProvider());
    getSite().setSelectionProvider(viewer);
    viewer.setInput(this);
    DebugPlugin.getDefault().addDebugEventListener(this);
    // viewer.getTree().addTreeListener(new TreeAdapter() {
    // @Override
    // public void treeCollapsed(final TreeEvent e) {
    // removeExpandedCategory((MarkerCategory) e.item.getData());
    // }
    // 
    // @Override
    // public void treeExpanded(final TreeEvent e) {
    // addExpandedCategory((MarkerCategory) e.item.getData());
    // }
    // });
    // // Set help on the view itself
    // viewer.getControl().addHelpListener(new HelpListener() {
    // public void helpRequested(HelpEvent e) {
    // Object provider = getAdapter(IContextProvider.class);
    // if (provider == null) {
    // return;
    // }
    // 
    // IContext context = ((IContextProvider) provider)
    // .getContext(viewer.getControl());
    // PlatformUI.getWorkbench().getHelpSystem().displayHelp(context);
    // }
    // 
    // });
    viewer.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final Object o = getSelectedInTree();
            // $NON-NLS-1$
            final String msg = o == null ? "" : o.toString();
            getViewSite().getActionBars().getStatusLineManager().setMessage(msg);
        }
    });
    viewer.getTree().addMouseListener(new MouseListener() {

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            final Object o = getSelectedInTree();
            if (o instanceof OtpErlangTuple) {
                final OtpErlangTuple t = (OtpErlangTuple) o;
                final OtpErlangTuple t2 = (OtpErlangTuple) t.elementAt(1);
                final OtpErlangTuple ieval = (OtpErlangTuple) t2.elementAt(0);
                final OtpErlangAtom mod = (OtpErlangAtom) ieval.elementAt(3);
                final String module = mod.atomValue();
                final OtpErlangLong lin = (OtpErlangLong) ieval.elementAt(2);
                try {
                    final int line = lin.intValue();
                    gotoModuleLine(module, line);
                } catch (final OtpErlangRangeException e1) {
                }
            }
        }

        @Override
        public void mouseDown(final MouseEvent e) {
        }

        @Override
        public void mouseUp(final MouseEvent e) {
        }
    });
    // .addPropertyChangeListener(getWorkingSetListener());
    return viewer;
// registerContextMenu();
// initDragAndDrop();
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) MouseListener(org.eclipse.swt.events.MouseListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 37 with OtpErlangAtom

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

the class DebugTraceEvent method getStackFrames.

public List<IStackFrame> getStackFrames(final IDebugTarget target, final IThread process) {
    // XXX JC copy paste
    final OtpErlangTuple tuple = getTuple();
    final OtpErlangList erlStackFrames = (OtpErlangList) tuple.elementAt(2);
    final OtpErlangTuple t2 = (OtpErlangTuple) tuple.elementAt(1);
    final OtpErlangTuple ieval = (OtpErlangTuple) t2.elementAt(0);
    OtpErlangAtom m = (OtpErlangAtom) ieval.elementAt(3);
    OtpErlangList bindings = (OtpErlangList) t2.elementAt(t2.arity() - 1);
    OtpErlangLong l = (OtpErlangLong) ieval.elementAt(1);
    final List<IStackFrame> stackFrames = new ArrayList<>(erlStackFrames.arity() + 1);
    for (final OtpErlangObject o : erlStackFrames) {
        final OtpErlangTuple t = (OtpErlangTuple) o;
        final OtpErlangTuple ml = (OtpErlangTuple) t.elementAt(1);
        final OtpErlangObject ml0 = ml.elementAt(0);
        int stackFrameNo;
        final OtpErlangLong n = (OtpErlangLong) t.elementAt(3);
        try {
            stackFrameNo = n.intValue();
        } catch (final OtpErlangRangeException e) {
            stackFrameNo = -1;
        }
        final String module = m.atomValue();
        int line;
        try {
            line = l.intValue();
        } catch (final OtpErlangRangeException e) {
            line = -1;
        }
        final IStackFrame sf = new ErlangStackFrame(module, (ErlangProcess) process, target, line, null, bindings, stackFrameNo);
        stackFrames.add(sf);
        bindings = (OtpErlangList) t.elementAt(2);
        m = (OtpErlangAtom) ml0;
        l = (OtpErlangLong) ml.elementAt(1);
    }
    return stackFrames;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) IStackFrame(org.eclipse.debug.core.model.IStackFrame) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) ErlangStackFrame(org.erlide.backend.debug.model.ErlangStackFrame) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 38 with OtpErlangAtom

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

the class RuntimeHelper method formatError.

public String formatError(final OtpErlangObject object) {
    final OtpErlangTuple err = (OtpErlangTuple) object;
    final OtpErlangAtom mod = (OtpErlangAtom) err.elementAt(1);
    final OtpErlangObject arg = err.elementAt(2);
    String res;
    try {
        OtpErlangObject r = target.call(mod.atomValue(), "format_error", "x", arg);
        r = target.call("lists", "flatten", "x", r);
        res = ((OtpErlangString) r).stringValue();
    } catch (final Exception e) {
        ErlLogger.error(e);
        res = err.toString();
    }
    return res;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) RpcException(org.erlide.runtime.rpc.RpcException)

Example 39 with OtpErlangAtom

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

the class SearchUtil method addSearchResult.

public static void addSearchResult(final List<ModuleLineFunctionArityRef> result, final OtpErlangObject r) throws OtpErlangRangeException {
    final OtpErlangTuple t = (OtpErlangTuple) r;
    final OtpErlangList l = (OtpErlangList) t.elementAt(1);
    for (final OtpErlangObject i : l) {
        /*
             * find_data([#ref{function=F, arity=A, clause=C, data=D, offset=O,
             * length=L, sub_clause=S} | Rest], Data, M, Acc) -> case D of Data
             * -> find_data(Rest, Data, M, [{M, F, A, C, S, O, L} | Acc]); _ ->
             * find_data(Rest, Data, M, Acc) end.
             */
        final OtpErlangTuple modLineT = (OtpErlangTuple) i;
        final String modName = Util.stringValue(modLineT.elementAt(0));
        final OtpErlangObject nameO = modLineT.elementAt(1);
        final OtpErlangLong arityL = (OtpErlangLong) modLineT.elementAt(2);
        final int arity = arityL.intValue();
        final String clauseHead = Util.stringValue(modLineT.elementAt(3));
        final OtpErlangAtom subClause = (OtpErlangAtom) modLineT.elementAt(4);
        final OtpErlangLong offsetL = (OtpErlangLong) modLineT.elementAt(5);
        final OtpErlangLong lengthL = (OtpErlangLong) modLineT.elementAt(6);
        final OtpErlangAtom isDef = (OtpErlangAtom) modLineT.elementAt(7);
        String name;
        if (nameO instanceof OtpErlangAtom) {
            final OtpErlangAtom nameA = (OtpErlangAtom) nameO;
            name = nameA.atomValue();
        } else {
            name = Util.stringValue(nameO);
        }
        result.add(new ModuleLineFunctionArityRef(modName, offsetL.intValue(), lengthL.intValue(), name, arity, clauseHead, Boolean.parseBoolean(subClause.atomValue()), Boolean.parseBoolean(isDef.atomValue())));
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ModuleLineFunctionArityRef(org.erlide.engine.services.search.ModuleLineFunctionArityRef) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 40 with OtpErlangAtom

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

the class TraceDataHandler method getData.

/**
 * Reads data described by given object. It can be trace event or
 * information about file containing tracing results.
 *
 * @param otpErlangObject
 *            input object
 *
 * @return tree node that describes data
 */
public ITreeNode getData(final OtpErlangObject otpErlangObject) {
    try {
        if (otpErlangObject instanceof OtpErlangTuple) {
            final OtpErlangTuple tuple = (OtpErlangTuple) otpErlangObject;
            final String atomValue = ((OtpErlangAtom) tuple.elementAt(0)).atomValue();
            if (atomValue.equals(TraceDataHandler.ATOM_TRACE_TS)) {
                // trace data: {trace_ts, Data}
                final OtpErlangAtom traceType = (OtpErlangAtom) tuple.elementAt(TraceDataHandler.INDEX_TRACE_TYPE);
                lastTraceDate = readDateTuple((OtpErlangTuple) tuple.elementAt(tuple.arity() - 1));
                switch(TraceType.valueOf(traceType.atomValue().toUpperCase())) {
                    case CALL:
                        return processCallTrace("Call", tuple);
                    case EXCEPTION_FROM:
                        return processExceptionFrom("Exception", tuple);
                    case EXIT:
                        return processExitTrace("Exit", tuple);
                    case GC_END:
                        return processGcTrace("GC end", Images.GC_END_NODE, tuple);
                    case GC_START:
                        return processGcTrace("GC start", Images.GC_START_NODE, tuple);
                    case GETTING_LINKED:
                        return processLinkTrace("Getting linked", Images.GETTING_LINKED_NODE, tuple);
                    case GETTING_UNLINKED:
                        return processLinkTrace("Getting unlinked", Images.GETTING_UNLINKED_NODE, tuple);
                    case IN:
                        return processInOutTrace("In", Images.IN_NODE, tuple);
                    case LINK:
                        return processLinkTrace("Link", Images.LINK_NODE, tuple);
                    case OUT:
                        return processInOutTrace("Out", Images.OUT_NODE, tuple);
                    case RECEIVE:
                        return processReceiveTrace("Received", tuple);
                    case REGISTER:
                        return processRegisterTrace("Register", Images.REGISTER_NODE, tuple);
                    case RETURN_FROM:
                        return processReturnTrace("Return from", Images.RETURN_FROM_NODE, tuple, true);
                    case RETURN_TO:
                        return processReturnTrace("Return to", Images.RETURN_TO_NODE, tuple, false);
                    case SEND:
                        return processSendTrace("Sent", Images.SENT_MESSAGE_NODE, tuple);
                    case SEND_TO_NON_EXISTING_PROCESS:
                        return processSendTrace("Sent to non existing process", Images.WRONG_MESSAGE_NODE, tuple);
                    case SPAWN:
                        return processSpawnTrace("Spawn", tuple);
                    case UNLINK:
                        return processLinkTrace("Unlink", Images.ULINK_NODE, tuple);
                    case UNREGISTER:
                        return processRegisterTrace("Unregister", Images.UNREGISTER_NODE, tuple);
                    default:
                        break;
                }
            } else if (atomValue.equals(TraceDataHandler.ATOM_FILE_INFO)) {
                return processFileInfo(tuple);
            } else if (atomValue.equals(TraceDataHandler.ATOM_DROP)) {
                // drop information: {drop, Long}
                return processDropTrace(tuple);
            }
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    return null;
}
Also used : OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException)

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)15 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