Search in sources :

Example 1 with Range

use of org.erlide.wrangler.refactoring.util.Range 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 2 with Range

use of org.erlide.wrangler.refactoring.util.Range in project erlide_eclipse by erlang.

the class GeneraliseFunctionRefactoring method createPositionList.

/**
 * Returns IErlRange, OtpErlangTuple pairs, which are represents the same
 * position in a module
 *
 * @param thePositions
 * @return
 */
protected HashMap<IErlRange, OtpErlangTuple> createPositionList(final OtpErlangList thePositions) {
    try {
        final HashMap<IErlRange, OtpErlangTuple> ret = new HashMap<>();
        final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
        for (final OtpErlangObject o : thePositions) {
            // {{sl, sc}, {el,ec}}
            final OtpErlangTuple pos = (OtpErlangTuple) o;
            ret.put(new ErlRange(new Range(pos), sel.getDocument()), pos);
        }
        return ret;
    } catch (final OtpErlangException e) {
        ErlLogger.error(e);
        return null;
    }
}
Also used : IErlRange(org.erlide.wrangler.refactoring.util.IErlRange) HashMap(java.util.HashMap) IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangException(com.ericsson.otp.erlang.OtpErlangException) ErlRange(org.erlide.wrangler.refactoring.util.ErlRange) IErlRange(org.erlide.wrangler.refactoring.util.IErlRange) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) Range(org.erlide.wrangler.refactoring.util.Range) ErlRange(org.erlide.wrangler.refactoring.util.ErlRange) IErlRange(org.erlide.wrangler.refactoring.util.IErlRange)

Aggregations

OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ErlRange (org.erlide.wrangler.refactoring.util.ErlRange)2 IErlRange (org.erlide.wrangler.refactoring.util.IErlRange)2 Range (org.erlide.wrangler.refactoring.util.Range)2 OtpErlangException (com.ericsson.otp.erlang.OtpErlangException)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 HashMap (java.util.HashMap)1 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)1 WranglerRpcParsingException (org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)1 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)1 IRange (org.erlide.wrangler.refactoring.util.IRange)1