Search in sources :

Example 1 with RpcResult

use of org.erlide.runtime.rpc.RpcResult in project erlide_eclipse by erlang.

the class SimpleCodeInspectionHandler method handleLongFunctions.

private void handleLongFunctions(final IErlSelection wranglerSelection, final Shell shell) {
    try {
        CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.LONG_FUNCTIONS);
        // call inputdialog
        final InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(shell, "Search for long functions", "Number of lines:", "Search in the project", "", new IntegerInputValidator());
        if (Window.OK == dialog.open()) {
            final int linesVal = Integer.parseInt(dialog.getValue());
            final boolean inProject = dialog.isCheckBoxChecked();
            RpcResult res = null;
            if (inProject) {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("long_functions_in_dirs_eclipse", "ixi", linesVal, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            } else {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("long_functions_in_file_eclipse", "sixi", wranglerSelection.getFilePath(), linesVal, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            }
            // handle rpc
            final ArrayList<IErlElement> elements = processFunctionResult(shell, res);
            if (elements == null) {
                return;
            }
            // show result
            if (!elements.isEmpty()) {
                CodeInspectionViewsManager.showErlElements("Long functions", elements, SimpleCodeInspectionHandler.LONG_FUNCTIONS);
            } else {
                MessageDialog.openInformation(shell, "No result", "Could not found any function which is longer, than " + linesVal + " lines.");
            }
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : InputDialogWithCheckbox(org.erlide.wrangler.refactoring.codeinspection.ui.InputDialogWithCheckbox) IErlElement(org.erlide.engine.model.IErlElement) RpcResult(org.erlide.runtime.rpc.RpcResult) 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)

Example 2 with RpcResult

use of org.erlide.runtime.rpc.RpcResult in project erlide_eclipse by erlang.

the class SimpleCodeInspectionHandler method handleNotFlushUnknownMessages.

private void handleNotFlushUnknownMessages(final IErlSelection wranglerSelection, final Shell shell) {
    final String inFile = "not_flush_unknown_messages_in_file_eclipse";
    final String inProject = "not_flush_unknown_messages_in_dirs_eclipse";
    CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.NOT_FLUSH_UNKNOWN_MESSAGES);
    final Boolean answer = MessageDialog.openQuestion(shell, "Find incomplete receive patterns", "Would you like to run the scan in the whole project?");
    try {
        RpcResult result = null;
        String function = "";
        if (answer) {
            function = inProject;
            result = WranglerBackendManager.getRefactoringBackend().callInspection(function, "xi", wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
        } else {
            function = inFile;
            result = WranglerBackendManager.getRefactoringBackend().callInspection(function, "sxi", wranglerSelection.getFilePath(), wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
        }
        final ArrayList<IErlElement> elements = processFunctionResult(shell, result);
        if (elements == null) {
            return;
        }
        if (!elements.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Incomplete receive patterns", elements, SimpleCodeInspectionHandler.NOT_FLUSH_UNKNOWN_MESSAGES);
        } else {
            MessageDialog.openInformation(shell, "No result", "Could not found any incomplete receive patterns!");
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) RpcResult(org.erlide.runtime.rpc.RpcResult) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) 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)

Example 3 with RpcResult

use of org.erlide.runtime.rpc.RpcResult in project erlide_eclipse by erlang.

the class SimpleCodeInspectionHandler method handleDepenenciesCall.

private void handleDepenenciesCall(final IErlSelection wranglerSelection, final Shell shell) {
    // hiding the views
    CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.DEPENECIES_1_VIEW_ID);
    CodeInspectionViewsManager.hideView(CodeInspectionViewsManager.CODE_INSPECTION_VIEW, SimpleCodeInspectionHandler.DEPENECIES_2_VIEW_ID);
    // run the rpc
    try {
        final RpcResult res = WranglerBackendManager.getRefactoringBackend().callInspection("dependencies_of_a_module_eclipse", "sx", wranglerSelection.getFilePath(), wranglerSelection.getSearchPath());
        ArrayList<IErlElement> modules1 = new ArrayList<>();
        ArrayList<IErlElement> modules2 = new ArrayList<>();
        final OtpErlangObject obj = res.getValue();
        final OtpErlangTuple restuple = (OtpErlangTuple) obj;
        final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
        if ("ok".equals(resindicator.atomValue())) {
            final OtpErlangTuple listtuple = (OtpErlangTuple) restuple.elementAt(1);
            final OtpErlangList modList1 = (OtpErlangList) listtuple.elementAt(0);
            final OtpErlangList modList2 = (OtpErlangList) listtuple.elementAt(1);
            modules1 = createErlModuleList(modList1);
            modules2 = createErlModuleList(modList2);
        } else {
            final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
            MessageDialog.openError(shell, "Error", s.stringValue());
            return;
        }
        if (!modules1.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Modules which depends on " + wranglerSelection.getErlElement().getAncestorOfKind(ErlElementKind.MODULE).getName(), modules1, SimpleCodeInspectionHandler.DEPENECIES_1_VIEW_ID);
        }
        if (!modules2.isEmpty()) {
            CodeInspectionViewsManager.showErlElements("Modules, on which " + wranglerSelection.getErlElement().getAncestorOfKind(ErlElementKind.MODULE).getName() + " depends", modules2, SimpleCodeInspectionHandler.DEPENECIES_2_VIEW_ID);
        } else {
            MessageDialog.openInformation(shell, "No result", "There is no large module with the specified parameter!");
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcResult(org.erlide.runtime.rpc.RpcResult) ArrayList(java.util.ArrayList) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) 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) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Example 4 with RpcResult

use of org.erlide.runtime.rpc.RpcResult in project erlide_eclipse by erlang.

the class SimpleCodeInspectionHandler method handleNested.

private void handleNested(final IErlSelection wranglerSelection, final Shell shell, final String type) {
    try {
        CodeInspectionViewsManager.hideView(SimpleCodeInspectionHandler.NESTED_EXPRESSIONS + type);
        // call inputdialog
        final InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(shell, "Search for nested expression", "Nest level:", "Search in the project", "", new IntegerInputValidator());
        if (Window.OK == dialog.open()) {
            final int nestedVal = Integer.parseInt(dialog.getValue());
            final boolean inProject = dialog.isCheckBoxChecked();
            RpcResult res = null;
            if (inProject) {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("nested_exprs_in_dirs_eclipse", "iaxi", nestedVal, type, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            } else {
                res = WranglerBackendManager.getRefactoringBackend().callInspection("nested_exprs_in_file_eclipse", "siaxi", wranglerSelection.getFilePath(), nestedVal, type, wranglerSelection.getSearchPath(), GlobalParameters.getTabWidth());
            }
            // handle rpc
            final ArrayList<IErlElement> elements = processFunctionResult(shell, res);
            if (elements == null) {
                return;
            }
            // show result
            if (!elements.isEmpty()) {
                CodeInspectionViewsManager.showErlElements("Nested " + type + " expressions", elements, SimpleCodeInspectionHandler.NESTED_EXPRESSIONS + type);
            } else {
                MessageDialog.openInformation(shell, "No result", "Could not found any " + nestedVal + " levels nested " + type + " expression!");
            }
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
}
Also used : InputDialogWithCheckbox(org.erlide.wrangler.refactoring.codeinspection.ui.InputDialogWithCheckbox) IErlElement(org.erlide.engine.model.IErlElement) RpcResult(org.erlide.runtime.rpc.RpcResult) 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)

Example 5 with RpcResult

use of org.erlide.runtime.rpc.RpcResult 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)

Aggregations

RpcResult (org.erlide.runtime.rpc.RpcResult)26 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)10 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)8 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)7 ExecutionException (org.eclipse.core.commands.ExecutionException)7 ErlModelException (org.erlide.engine.model.ErlModelException)7 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)7 IErlElement (org.erlide.engine.model.IErlElement)6 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)6 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)5 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)4 WranglerRefactoringBackend (org.erlide.wrangler.refactoring.backend.internal.WranglerRefactoringBackend)4 WranglerRpcParsingException (org.erlide.wrangler.refactoring.exception.WranglerRpcParsingException)4 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)3 ArrayList (java.util.ArrayList)2 InputDialogWithCheckbox (org.erlide.wrangler.refactoring.codeinspection.ui.InputDialogWithCheckbox)2 OtpErlangFloat (com.ericsson.otp.erlang.OtpErlangFloat)1 OtpErlangInt (com.ericsson.otp.erlang.OtpErlangInt)1 Enumeration (java.util.Enumeration)1 LinkedList (java.util.LinkedList)1