Search in sources :

Example 21 with OtpErlangString

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

the class ExpressionPosRpcMessage method parseRefactoringMessage.

@Override
protected void parseRefactoringMessage(final OtpErlangTuple resultTuple) throws WranglerException {
    try {
        final OtpErlangObject wranglerResult = resultTuple.elementAt(1);
        if ("ok".equals(resultTuple.elementAt(0).toString())) {
            OtpErlangList posDefList;
            if (wranglerResult instanceof OtpErlangTuple) {
                syntaxTree = ((OtpErlangTuple) wranglerResult).elementAt(0);
                posDefList = (OtpErlangList) ((OtpErlangTuple) wranglerResult).elementAt(1);
            } else {
                syntaxTree = null;
                posDefList = (OtpErlangList) wranglerResult;
            }
            positionDefs = new HashMap<>();
            final OtpErlangObject[] elements = posDefList.elements();
            for (final OtpErlangObject o : elements) {
                final OtpErlangTuple value = (OtpErlangTuple) o;
                final OtpErlangTuple pos = (OtpErlangTuple) value.elementAt(0);
                try {
                    positionDefs.put(new Range(pos), value);
                } catch (final OtpErlangRangeException e) {
                    ErlLogger.error(e);
                    setUnsuccessful("Failed to parse the result!");
                }
            }
            setSuccessful();
        } else {
            final OtpErlangString errorMsg = (OtpErlangString) wranglerResult;
            setUnsuccessful(errorMsg.stringValue());
            return;
        }
    } catch (final Exception e) {
        throw new WranglerRpcParsingException(resultTuple.toString());
    }
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) IRange(org.erlide.wrangler.refactoring.util.IRange) Range(org.erlide.wrangler.refactoring.util.Range) ErlRange(org.erlide.wrangler.refactoring.util.ErlRange) IErlRange(org.erlide.wrangler.refactoring.util.IErlRange) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) OtpErlangRangeException(com.ericsson.otp.erlang.OtpErlangRangeException) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 22 with OtpErlangString

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

the class ProcessRpcMessage method parseRefactoringMessage.

@Override
protected void parseRefactoringMessage(final OtpErlangTuple resultTuple) throws WranglerException {
    final OtpErlangObject wranglerResult = resultTuple.elementAt(1);
    if ("ok".equals(resultTuple.elementAt(0).toString())) {
        if (wranglerResult instanceof OtpErlangList) {
            changedFiles = parseFileList((OtpErlangList) wranglerResult);
            setSuccessful();
            return;
        }
    } else if ("undecidables".equals(resultTuple.elementAt(0).toString())) {
        hasUndecidables = true;
    }
    final OtpErlangString errorMsg = (OtpErlangString) wranglerResult;
    setUnsuccessful(errorMsg.stringValue());
    return;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 23 with OtpErlangString

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

the class RefactoringRpcMessage method parseRefactoringMessage.

@Override
protected void parseRefactoringMessage(final OtpErlangTuple tuple) throws WranglerRpcParsingException {
    resultTuple = tuple;
    final OtpErlangObject wranglerResult = tuple.elementAt(1);
    if ("ok".equals(tuple.elementAt(0).toString())) {
        if (wranglerResult instanceof OtpErlangList) {
            changedFiles = parseFileList((OtpErlangList) wranglerResult);
            setSuccessful();
            return;
        }
    } else {
        final OtpErlangString msg = (OtpErlangString) wranglerResult;
        if ("warning".equals(tuple.elementAt(0).toString())) {
            setWarning(msg.stringValue());
        } else if ("question".equals(tuple.elementAt(0).toString())) {
            setQuestion(msg.stringValue());
        } else {
            setUnsuccessful(msg.stringValue());
        }
        return;
    }
    throw new WranglerRpcParsingException(tuple.toString());
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 24 with OtpErlangString

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

the class OpenUtils method findLocalCall.

private IErlElement findLocalCall(final IErlModule module, final IErlProject erlProject, final OpenResult res, final IErlElement element, final IErlElementLocator.Scope scope) throws RpcException, CoreException {
    if (isTypeDefOrRecordDef(element, res)) {
        return modelFindService.findTypespec(module, res.getFun());
    }
    final IErlFunction foundElement = module.findFunction(res.getFunction());
    if (foundElement != null) {
        return foundElement;
    }
    // imported functions
    OtpErlangObject res2 = null;
    String moduleName = null;
    final IErlImport ei = module.findImport(res.getFunction());
    if (ei != null) {
        final IErlModel model = ErlangEngine.getInstance().getModel();
        moduleName = ei.getImportModule();
        res2 = ErlangEngine.getInstance().getOpenService().getSourceFromModule(model.getPathVars(), moduleName, erlProject.getProperties().getExternalModules());
    }
    if (res2 instanceof OtpErlangString && moduleName != null) {
        // imported from otp module
        final OtpErlangString otpErlangString = (OtpErlangString) res2;
        final String modulePath = otpErlangString.stringValue();
        final IErlElementLocator model = ErlangEngine.getInstance().getModel();
        return modelFindService.findFunction(model, erlProject, module, moduleName, modulePath, res.getFunction(), scope);
    }
    // functions defined in include files
    final Collection<IErlModule> allIncludedFiles = ErlangEngine.getInstance().getModelFindService().findAllIncludedFiles(module);
    for (final IErlModule includedModule : allIncludedFiles) {
        final IErlFunction function = includedModule.findFunction(res.getFunction());
        if (function != null) {
            return function;
        }
    }
    return null;
}
Also used : IErlModel(org.erlide.engine.model.root.IErlModel) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) IErlElementLocator(org.erlide.engine.model.root.IErlElementLocator) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) IErlImport(org.erlide.engine.model.erlang.IErlImport) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 25 with OtpErlangString

use of com.ericsson.otp.erlang.OtpErlangString 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)

Aggregations

OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)56 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)36 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)31 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)22 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)15 ArrayList (java.util.ArrayList)9 RpcResult (org.erlide.runtime.rpc.RpcResult)8 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)7 RpcException (org.erlide.runtime.rpc.RpcException)7 Test (org.junit.Test)7 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)6 OtpErlangBinary (com.ericsson.otp.erlang.OtpErlangBinary)5 IPath (org.eclipse.core.runtime.IPath)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 IErlElement (org.erlide.engine.model.IErlElement)5 WranglerRpcParsingException (org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)5 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)5 CoreException (org.eclipse.core.runtime.CoreException)4 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)4 Map (java.util.Map)3