Search in sources :

Example 46 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 47 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 48 with OtpErlangAtom

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

the class OtpParser method parse.

private static OtpErlangObject parse(final List<Token> tokens) throws OtpParserException {
    if (tokens.isEmpty()) {
        return null;
    }
    OtpErlangObject result = null;
    final Token t = tokens.remove(0);
    final String text = t.text;
    if (text == null) {
        throw new OtpParserException("null token" + t.toString());
    }
    switch(t.kind) {
        case ATOM:
            result = new OtpErlangAtom(text);
            break;
        case VARIABLE:
            result = new OtpPatternVariable(text);
            break;
        case STRING:
            result = new OtpErlangString(text);
            break;
        case INTEGER:
            result = new OtpErlangLong(Long.parseLong(text));
            break;
        case PLACEHOLDER:
            result = new OtpFormatPlaceholder(text);
            break;
        case TUPLESTART:
            result = OtpParser.parseTuple(tokens, new Stack<>());
            break;
        case TUPLEEND:
            throw new OtpParserException("unexpected " + t.toString());
        case LISTSTART:
            result = OtpParser.parseList(tokens, new Stack<>(), null);
            break;
        case LISTEND:
            throw new OtpParserException("unexpected " + t.toString());
        case MAP:
            result = OtpParser.parseMap(tokens, new Stack<>());
            break;
        case COMMA:
            throw new OtpParserException("unexpected " + t.toString());
        default:
            throw new OtpParserException("unknown token" + t.toString());
    }
    return result;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) Stack(java.util.Stack)

Example 49 with OtpErlangAtom

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

the class TypeConverter method cvtString.

private static String cvtString(final OtpErlangObject obj) throws SignatureException {
    if (obj instanceof OtpErlangString) {
        return ((OtpErlangString) obj).stringValue();
    }
    if (obj instanceof OtpErlangAtom) {
        return ((OtpErlangAtom) obj).atomValue();
    }
    if (obj instanceof OtpErlangBinary) {
        return new String(((OtpErlangBinary) obj).binaryValue());
    }
    if (obj instanceof OtpErlangList) {
        final StringBuilder res = new StringBuilder();
        for (final OtpErlangObject el : (OtpErlangList) obj) {
            if (el instanceof OtpErlangLong) {
                final long l = ((OtpErlangLong) el).longValue();
                res.append((char) (l & 0xFFFF));
            } else {
                res.append(TypeConverter.erlang2java(el, String.class));
            }
        }
        return res.toString();
    }
    throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + "String");
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 50 with OtpErlangAtom

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

the class TypeConverter method java2erlang.

@SuppressWarnings("boxing")
public static OtpErlangObject java2erlang(final Object obj, final Signature type) throws SignatureException {
    if (type.kind == 'x') {
        return TypeConverter.java2erlang(obj);
    }
    if (obj instanceof String) {
        return TypeConverter.cvtString(obj, type);
    }
    if (obj instanceof Character) {
        if (type.kind == 'i') {
            return new OtpErlangChar((Character) obj);
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof Number) {
        return TypeConverter.cvtNumber(obj, type);
    }
    if (obj instanceof Boolean) {
        if (type.kind == 'o') {
            return new OtpErlangAtom((Boolean) obj ? "true" : "false");
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof Collection<?>) {
        if (type.kind == 'l') {
            final Object[] v = ((Collection<?>) obj).toArray(new Object[] {});
            final OtpErlangObject[] vv = new OtpErlangObject[v.length];
            for (int i = 0; i < v.length; i++) {
                vv[i] = TypeConverter.java2erlang(v[i], type.content[0]);
            }
            return new OtpErlangList(vv);
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof Map<?, ?>) {
        if (type.kind == 'm') {
            @SuppressWarnings("unchecked") final Map<OtpErlangObject, OtpErlangObject> map = (Map<OtpErlangObject, OtpErlangObject>) obj;
            final int size = map.size();
            final OtpErlangObject[] keys = map.keySet().toArray(new OtpErlangObject[size]);
            final OtpErlangObject[] values = new OtpErlangObject[size];
            for (int i = 0; i < size; i++) {
                values[i] = map.get(keys[i]);
            }
            return new OtpErlangMap(keys, values);
        }
        TypeConverter.failConversion(obj, type);
    }
    if (obj instanceof OtpErlangPid) {
        return (OtpErlangPid) obj;
    }
    if (obj instanceof OtpErlangRef) {
        return (OtpErlangObject) obj;
    }
    if (obj instanceof OtpErlangBinary) {
        return (OtpErlangObject) obj;
    }
    if (obj instanceof OtpErlangObject) {
        TypeConverter.checkConversion(obj);
        return (OtpErlangObject) obj;
    }
    if (obj instanceof IConvertible) {
        return ((IConvertible) obj).toErlangObject();
    }
    if (obj != null && obj.getClass().isArray()) {
        final int len = Array.getLength(obj);
        // Class<?> component = obj.getClass().getComponentType();
        if (type.kind == 'b') {
            // TODO we can convert more things to binaries
            return new OtpErlangBinary(obj);
        }
        if (type.kind == 'l') {
            final OtpErlangObject[] vv = new OtpErlangObject[len];
            for (int i = 0; i < len; i++) {
                vv[i] = TypeConverter.java2erlang(Array.get(obj, i), type.content[0]);
            }
            return new OtpErlangList(vv);
        } else if (type.kind == 't') {
            final OtpErlangObject[] vv = new OtpErlangObject[len];
            for (int i = 0; i < len; i++) {
                vv[i] = TypeConverter.java2erlang(Array.get(obj, i), type.content[i]);
            }
            return new OtpErlangTuple(vv);
        } else {
            TypeConverter.failConversion(obj, type);
        }
    }
    if (type.kind == 's' && obj != null) {
        return new OtpErlangString(obj.toString());
    }
    if (type.kind == 'b' && obj != null) {
        return new OtpErlangBinary(obj.toString().getBytes());
    }
    TypeConverter.failConversion(obj, type);
    return null;
}
Also used : OtpErlangChar(com.ericsson.otp.erlang.OtpErlangChar) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangMap(com.ericsson.otp.erlang.OtpErlangMap) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangBinary(com.ericsson.otp.erlang.OtpErlangBinary) OtpErlangPid(com.ericsson.otp.erlang.OtpErlangPid) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) Collection(java.util.Collection) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangRef(com.ericsson.otp.erlang.OtpErlangRef) Map(java.util.Map) OtpErlangMap(com.ericsson.otp.erlang.OtpErlangMap) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

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