Search in sources :

Example 56 with OtpErlangAtom

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

the class TraceBackend method processResult.

private TracingStatus processResult(final OtpErlangObject callResult) {
    final OtpErlangTuple tuple = (OtpErlangTuple) callResult;
    if ("error".equals(((OtpErlangAtom) tuple.elementAt(0)).atomValue())) {
        errorObject = tuple.elementAt(1);
        return TracingStatus.ERROR;
    }
    final OtpErlangList nodeNames = (OtpErlangList) tuple.elementAt(1);
    activatedNodes = new ArrayList<>();
    for (final OtpErlangObject nodeName : nodeNames) {
        final String nodeNameString = ((OtpErlangAtom) nodeName).atomValue();
        activatedNodes.add(nodeNameString);
        notActivatedNodes.remove(nodeNameString);
    }
    if (activatedNodes.isEmpty()) {
        return TracingStatus.NO_ACTIVATED_NODES;
    } else if (!notActivatedNodes.isEmpty()) {
        return TracingStatus.NOT_ALL_NODES_ACTIVATED;
    } else {
        return TracingStatus.OK;
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom)

Example 57 with OtpErlangAtom

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

the class TypeConverter method erlang2java.

@SuppressWarnings("boxing")
public static Object erlang2java(final OtpErlangObject obj, final Class<?> cls) throws SignatureException {
    try {
        if (cls == obj.getClass()) {
            return obj;
        }
        // if the conversion method exists, use it
        try {
            final Method method = cls.getMethod("fromErlangObject", OtpErlangObject.class);
            method.setAccessible(true);
            final Object o = method.invoke(null, obj);
            return o;
        } catch (final NoSuchMethodException e) {
        // ignore, continue
        }
        if (cls.isArray()) {
            return TypeConverter.cvtArray(obj, cls);
        }
        if (cls == String.class) {
            return TypeConverter.cvtString(obj);
        }
        if (TypeConverter.isNumericClass(cls)) {
            if (obj instanceof OtpErlangLong) {
                final long res = ((OtpErlangLong) obj).longValue();
                if (cls == char.class || cls == Character.class) {
                    return (char) res;
                }
                if (cls == int.class || cls == Integer.class) {
                    return (int) res;
                }
                if (cls == byte.class || cls == Byte.class) {
                    return (byte) res;
                }
                if (cls == short.class || cls == Short.class) {
                    return (short) res;
                }
                if (cls == long.class || cls == Long.class) {
                    return res;
                }
            }
            throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
        }
        if (cls == boolean.class || cls == Boolean.class) {
            if (obj instanceof OtpErlangAtom) {
                final String s = ((OtpErlangAtom) obj).atomValue();
                if ("true".equals(s)) {
                    return true;
                }
                if ("false".equals(s)) {
                    return false;
                }
            }
            throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
        }
        if (Map.class.isAssignableFrom(cls)) {
            if (obj instanceof OtpErlangMap) {
                final Map<Object, Object> result = Maps.newHashMap();
                final OtpErlangMap map = (OtpErlangMap) obj;
                for (final OtpErlangObject key : map.keys()) {
                    final OtpErlangObject value = map.get(key);
                    result.put(TypeConverter.erlang2java(key, key.getClass()), TypeConverter.erlang2java(value, value.getClass()));
                }
                return result;
            }
            throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
        }
        if (Collection.class.isAssignableFrom(cls)) {
            if (obj instanceof OtpErlangList) {
                final OtpErlangObject[] list = ((OtpErlangList) obj).elements();
                final Object[] olist = new Object[list.length];
                for (int i = 0; i < list.length; i++) {
                    olist[i] = TypeConverter.erlang2java(list[i], list[i].getClass());
                }
                return Arrays.asList(olist);
            }
            throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
        }
        if (obj instanceof OtpErlangRef) {
            throw new SignatureException(TypeConverter.WRONG_ARG_TYPE + obj.getClass().getName() + TypeConverter.CANT_CONVERT_TO + cls.getCanonicalName());
        }
        return obj;
    } catch (final SignatureException e) {
        throw e;
    } catch (final Exception e) {
        throw new SignatureException(e);
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangMap(com.ericsson.otp.erlang.OtpErlangMap) Method(java.lang.reflect.Method) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) BigInteger(java.math.BigInteger) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangByte(com.ericsson.otp.erlang.OtpErlangByte) OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangRef(com.ericsson.otp.erlang.OtpErlangRef) OtpErlangShort(com.ericsson.otp.erlang.OtpErlangShort)

Example 58 with OtpErlangAtom

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

the class SimpleCodeInspectionHandler method handleLargeModulesCall.

private void handleLargeModulesCall(final IErlSelection wranglerSelection, final Shell shell) {
    CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
    final InputDialog dialog = new InputDialog(shell, "Lines of a large module", "Lines of a large module:", "", new IntegerInputValidator());
    final int ret = dialog.open();
    if (ret == Window.CANCEL) {
        return;
    }
    final int lines = Integer.parseInt(dialog.getValue());
    final RpcResult res = WranglerBackendManager.getRefactoringBackend().callInspection("large_modules_eclipse", "ixi", lines, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
    ArrayList<IErlElement> modules = new ArrayList<>();
    try {
        final OtpErlangObject obj = res.getValue();
        final OtpErlangTuple restuple = (OtpErlangTuple) obj;
        final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
        if ("ok".equals(resindicator.atomValue())) {
            final OtpErlangList modList = (OtpErlangList) restuple.elementAt(1);
            modules = createErlModuleList(modList);
        } else {
            final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
            MessageDialog.openError(shell, "Error", s.stringValue());
            return;
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    if (!modules.isEmpty()) {
        CodeInspectionViewsManager.showErlElements("Large modules", modules, SimpleCodeInspectionHandler.LARGE_MODULES_VIEW_ID);
    } else {
        MessageDialog.openInformation(shell, "No result", "There is no large module with the specified parameter!");
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) RpcResult(org.erlide.runtime.rpc.RpcResult) ArrayList(java.util.ArrayList) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) ErlModelException(org.erlide.engine.model.ErlModelException) ExecutionException(org.eclipse.core.commands.ExecutionException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) IErlElement(org.erlide.engine.model.IErlElement) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 59 with OtpErlangAtom

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

the class SimpleCodeInspectionHandler method extractFunction.

private IErlFunctionClause extractFunction(final OtpErlangTuple fTuple) throws OtpErlangRangeException, ErlModelException {
    final IErlModule mod = extractModule(fTuple.elementAt(0));
    final String function = ((OtpErlangAtom) fTuple.elementAt(1)).atomValue();
    final int arity = ((OtpErlangLong) fTuple.elementAt(2)).intValue();
    final IErlFunctionClause f = ErlangEngine.getInstance().getModel().findFunction(new FunctionRef(mod.getModuleName(), function, arity));
    return f;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 60 with OtpErlangAtom

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

the class SimpleCodeInspectionHandler method extractModule.

private IErlModule extractModule(final OtpErlangObject m) throws ErlModelException {
    String name = "";
    if (m instanceof OtpErlangString) {
        final OtpErlangString element = (OtpErlangString) m;
        name = element.stringValue();
    } else if (m instanceof OtpErlangAtom) {
        final OtpErlangAtom atom = (OtpErlangAtom) m;
        name = atom.atomValue();
    }
    final String[] modNameParts = name.split("/");
    final IErlModule mod = ErlangEngine.getInstance().getModel().findModule(modNameParts[modNameParts.length - 1]);
    return mod;
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) 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