Search in sources :

Example 1 with WranglerRpcParsingException

use of org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException in project erlide_eclipse by erlang.

the class AbstractDuplicatesSearcherAction method run.

/**
 * Runs the refactoring.
 */
public void run() {
    // TODO: run it in a new thread
    selectionChanged();
    if (getUserInput()) {
        final IProgressMonitor monitor = new NullProgressMonitor();
        try {
            IResultParser result;
            monitor.beginTask("Detecting..", 0);
            result = callRefactoring();
            if (result.isSuccessful()) {
                showDuplicatesView();
                addDuplicates(result.getDuplicates());
            } else {
                DuplicatesUIManager.closeDuplicatesView();
                displayErrorNotification(result.getErrorMessage());
            }
        } catch (final WranglerWarningException e) {
        } catch (final WranglerRpcParsingException e) {
            displayErrorNotification(rpcErrorMsg);
        } catch (final CoreException e) {
            displayErrorNotification(rpcErrorMsg);
        } catch (final IOException e) {
            displayErrorNotification(rpcErrorMsg);
        } finally {
            monitor.done();
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WranglerWarningException(org.erlide.wrangler.refactoring.core.exception.WranglerWarningException) IOException(java.io.IOException) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 2 with WranglerRpcParsingException

use of org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException in project erlide_eclipse by erlang.

the class DuplicateDetectionAction method callRefactoring.

@SuppressWarnings("boxing")
@Override
protected IResultParser callRefactoring() throws WranglerRpcParsingException, CoreException, IOException, WranglerWarningException {
    String functionName;
    RpcResult result;
    // getting the path of the fragment
    final String suffixPath = getSuffixPath();
    ErlLogger.debug("Suffix binary at: " + suffixPath);
    final WranglerRefactoringBackend backend = WranglerBackendManager.getRefactoringBackend();
    final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
    if (onlyInfile) {
        functionName = "duplicated_code_eclipse";
        final OtpErlangString fp = new OtpErlangString(sel.getFilePath());
        final OtpErlangString[] fpa = new OtpErlangString[1];
        fpa[0] = fp;
        final OtpErlangList fpl = new OtpErlangList(fpa);
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiis", fpl, minToks, minClones, GlobalParameters.getTabWidth(), suffixPath);
    } else {
        functionName = "duplicated_code_eclipse";
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiis", sel.getSearchPath(), minToks, minClones, GlobalParameters.getTabWidth(), suffixPath);
    }
    if (!result.isOk()) {
        throw new WranglerRpcParsingException("Rpc error");
    }
    return new DuplicateDetectionParser(result.getValue());
}
Also used : WranglerRefactoringBackend(org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 3 with WranglerRpcParsingException

use of org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException in project erlide_eclipse by erlang.

the class SimilarDetectionAction method callRefactoring.

@Override
protected IResultParser callRefactoring() throws WranglerRpcParsingException, CoreException, IOException, WranglerWarningException {
    final WranglerRefactoringBackend backend = WranglerBackendManager.getRefactoringBackend();
    final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
    RpcResult result;
    final String functionName = "sim_code_detection_eclipse";
    if (onlyInFile) {
        final OtpErlangString fp = new OtpErlangString(sel.getFilePath());
        final OtpErlangString[] fpa = new OtpErlangString[1];
        fpa[0] = fp;
        final OtpErlangList fpl = new OtpErlangList(fpa);
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiiidxi", fpl, minLen, minToks, minFreq, maxNewVars, simScore, sel.getSearchPath(), GlobalParameters.getTabWidth());
    } else {
        result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "xiiiidxi", sel.getSearchPath(), minLen, minToks, minFreq, maxNewVars, simScore, sel.getSearchPath(), GlobalParameters.getTabWidth());
    }
    if (!result.isOk()) {
        throw new WranglerRpcParsingException("Rpc error");
    }
    return new DuplicateDetectionParser(result.getValue());
}
Also used : WranglerRefactoringBackend(org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 4 with WranglerRpcParsingException

use of org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException in project erlide_eclipse by erlang.

the class SimilarSearchAction method callRefactoring.

@Override
protected IResultParser callRefactoring() throws WranglerRpcParsingException, CoreException, IOException, WranglerWarningException {
    final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
    final WranglerRefactoringBackend backend = WranglerBackendManager.getRefactoringBackend();
    RpcResult result = null;
    String functionName;
    if (onlyInFile) {
        functionName = "simi_expr_search_in_buffer_eclipse";
    } else {
        functionName = "simi_expr_search_in_dirs_eclipse";
    }
    result = backend.callWithoutParser(WranglerRefactoringBackend.UNLIMITED_TIMEOUT, functionName, "sxxxxi", sel.getFilePath(), sel.getSelectionRange().getStartPos(), sel.getSelectionRange().getEndPos(), new OtpErlangFloat(simScore), sel.getSearchPath(), GlobalParameters.getTabWidth());
    if (result.isOk()) {
        return new SimilarExpressionSearchParser(result.getValue());
    }
    throw new WranglerRpcParsingException("RPC error");
}
Also used : WranglerRefactoringBackend(org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend) IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangFloat(com.ericsson.otp.erlang.OtpErlangFloat) WranglerRpcParsingException(org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)

Example 5 with WranglerRpcParsingException

use of org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException 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)

Aggregations

WranglerRpcParsingException (org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)8 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)5 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)5 RpcResult (org.erlide.runtime.rpc.RpcResult)4 WranglerRefactoringBackend (org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend)4 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)4 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)3 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 OtpErlangFloat (com.ericsson.otp.erlang.OtpErlangFloat)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 WranglerWarningException (org.erlide.wrangler.refactoring.core.exception.WranglerWarningException)1 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)1 ErlRange (org.erlide.wrangler.refactoring.util.ErlRange)1 IErlRange (org.erlide.wrangler.refactoring.util.IErlRange)1 IRange (org.erlide.wrangler.refactoring.util.IRange)1