Search in sources :

Example 1 with IErlSelection

use of org.erlide.wrangler.refactoring.selection.IErlSelection in project erlide_eclipse by erlang.

the class GraphResultingInspectionHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final String actionId = event.getCommand().getId();
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().setFocus();
    try {
        GlobalParameters.setSelection(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection());
    } catch (final WranglerException e1) {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", e1.getMessage());
        return null;
    }
    try {
        final File tmpFile = File.createTempFile("wrangler_graph_", ".dot");
        tmpFile.deleteOnExit();
        final IErlSelection wranglerSelection = GlobalParameters.getWranglerSelection();
        if ("org.erlide.wrangler.refactoring.codeinspection.cyclicdependencies".equals(actionId)) {
            final Boolean answer = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Labels", "Label edges with function names called?");
            runInspection("Cyclic module dependency", GraphResultingInspectionHandler.CYCLYC_VIEW_ID, "There is no cyclic dependent modules in the project!", tmpFile, "cyclic_dependent_modules", "ssx", tmpFile.getAbsolutePath(), wranglerSelection.getSearchPath(), new OtpErlangBoolean(answer));
        } else if ("org.erlide.wrangler.refactoring.codeinspection.generatefunctioncallgraph".equals(actionId)) {
            runInspection("Function callgraph", GraphResultingInspectionHandler.FUNCTION_CALL_GRAPH_VIEW_ID, "There is no dependent functions in the module!", tmpFile, "gen_function_callgraph", "sss", tmpFile.getAbsolutePath(), wranglerSelection.getFilePath(), wranglerSelection.getSearchPath());
        } else if ("org.erlide.wrangler.refactoring.codeinspection.generatemodulegraph".equals(actionId)) {
            final Boolean answer = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Labels", "Label edges with function names called?");
            runInspection("Module dependency graph", GraphResultingInspectionHandler.MODULE_GRAPH_VIEW_ID, "There is no dependent modules in the project!", tmpFile, "gen_module_graph", "ssx", tmpFile.getAbsolutePath(), wranglerSelection.getSearchPath(), new OtpErlangBoolean(answer));
        } else if ("org.erlide.wrangler.refactoring.codeinspection.improperdependecies".equals(actionId)) {
            runInspection("Improper module dependencies", GraphResultingInspectionHandler.IMPROPER_DEPENDECIES_VIEW_ID, "There is no improper module dependecies!", tmpFile, "improper_inter_module_calls", "ss", tmpFile.getAbsolutePath(), wranglerSelection.getSearchPath());
        }
    } catch (final Exception e) {
        ErlLogger.error(e);
    }
    return event;
}
Also used : IErlSelection(org.erlide.wrangler.refactoring.selection.IErlSelection) OtpErlangBoolean(com.ericsson.otp.erlang.OtpErlangBoolean) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException) OtpErlangBoolean(com.ericsson.otp.erlang.OtpErlangBoolean) File(java.io.File) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException)

Example 2 with IErlSelection

use of org.erlide.wrangler.refactoring.selection.IErlSelection in project erlide_eclipse by erlang.

the class SimpleCodeInspectionHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final String actionId = event.getCommand().getId();
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().setFocus();
    try {
        GlobalParameters.setSelection(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection());
    } catch (final WranglerException e) {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", e.getMessage());
        return null;
    }
    final IErlSelection wranglerSelection = GlobalParameters.getWranglerSelection();
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if ("org.erlide.wrangler.refactoring.codeinspection.largemodules".equals(actionId)) {
        handleLargeModulesCall(wranglerSelection, shell);
    } else if ("org.erlide.wrangler.refactoring.codeinspection.dependencies".equals(actionId)) {
        handleDepenenciesCall(wranglerSelection, shell);
    } else if ("org.erlide.wrangler.refactoring.codeinspection.nontailrecursive".equals(actionId)) {
        handleNonTailRecursiveCall(wranglerSelection, shell);
    } else if ("org.erlide.wrangler.refactoring.codeinspection.notflush".equals(actionId)) {
        handleNotFlushUnknownMessages(wranglerSelection, shell);
    } else if ("org.erlide.wrangler.refactoring.codeinspection.nestedif".equals(actionId)) {
        handleNested(wranglerSelection, shell, "if");
    } else if ("org.erlide.wrangler.refactoring.codeinspection.nestedcase".equals(actionId)) {
        handleNested(wranglerSelection, shell, "case");
    } else if ("org.erlide.wrangler.refactoring.codeinspection.nestedreceive".equals(actionId)) {
        handleNested(wranglerSelection, shell, "receive");
    } else if ("org.erlide.wrangler.refactoring.codeinspection.longfunctions".equals(actionId)) {
        handleLongFunctions(wranglerSelection, shell);
    }
    return event;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IErlSelection(org.erlide.wrangler.refactoring.selection.IErlSelection) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) WranglerException(org.erlide.wrangler.refactoring.exception.WranglerException)

Example 3 with IErlSelection

use of org.erlide.wrangler.refactoring.selection.IErlSelection in project erlide_eclipse by erlang.

the class ExpressionSearchParser method parse.

@Override
public void parse(final OtpErlangObject object) {
    try {
        final OtpErlangTuple res = (OtpErlangTuple) object;
        if (!"ok".equals(res.elementAt(0).toString())) {
            setUnSuccessful(((OtpErlangString) res.elementAt(1)).stringValue());
            return;
        }
        if (res.elementAt(1).equals(new OtpErlangList())) {
            setUnSuccessful("No more instances found!");
            return;
        }
        final OtpErlangList posList = (OtpErlangList) res.elementAt(1);
        OtpErlangTuple actPos;
        OtpErlangLong startLine;
        OtpErlangLong startColumn;
        OtpErlangLong endLine;
        OtpErlangLong endColumn;
        final List<DuplicatedCodeInstanceElement> instances = new ArrayList<>();
        for (final OtpErlangObject aPosList : posList) {
            actPos = (OtpErlangTuple) aPosList;
            startLine = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(0)).elementAt(0);
            startColumn = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(0)).elementAt(1);
            endLine = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(1)).elementAt(0);
            endColumn = (OtpErlangLong) ((OtpErlangTuple) actPos.elementAt(1)).elementAt(1);
            final IErlSelection sel = GlobalParameters.getWranglerSelection();
            instances.add(new DuplicatedCodeInstanceElement((IFile) sel.getErlElement().getResource(), startLine.intValue(), startColumn.intValue(), endLine.intValue(), endColumn.intValue() + 1));
        }
        final DuplicatedCodeInstanceElement defaultInstance = instances.get(0);
        final DuplicatedCodeElement result = new DuplicatedCodeElement(defaultInstance);
        for (final DuplicatedCodeInstanceElement instance : instances) {
            result.addChild(instance);
        }
        isSuccessful = true;
        errorMessage = null;
        duplicates = new ArrayList<>();
        duplicates.add(result);
    } catch (final Exception e) {
        setUnSuccessful(e.getMessage());
    }
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) IFile(org.eclipse.core.resources.IFile) OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) ArrayList(java.util.ArrayList) IErlSelection(org.erlide.wrangler.refactoring.selection.IErlSelection) DuplicatedCodeElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeElement) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) DuplicatedCodeInstanceElement(org.erlide.wrangler.refactoring.duplicatedcode.ui.elements.DuplicatedCodeInstanceElement)

Example 4 with IErlSelection

use of org.erlide.wrangler.refactoring.selection.IErlSelection in project erlide_eclipse by erlang.

the class TupleFunctionParametersRefactoring method checkInitialConditions.

@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
    final IErlSelection sel = GlobalParameters.getWranglerSelection();
    if (sel instanceof IErlMemberSelection) {
        final SelectionKind kind = sel.getKind();
        if (kind == SelectionKind.FUNCTION_CLAUSE || kind == SelectionKind.FUNCTION) {
            final IErlMemberSelection s = (IErlMemberSelection) sel;
            numberOfTuplingParameters = calculateParametersNumber(WranglerUtils.getTextFromEditor(s.getSelectionRange(), s.getDocument()));
            if (numberOfTuplingParameters > 0) {
                return new RefactoringStatus();
            }
        }
    }
    return RefactoringStatus.createFatalErrorStatus("Please select function parameters!");
}
Also used : IErlMemberSelection(org.erlide.wrangler.refactoring.selection.IErlMemberSelection) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IErlSelection(org.erlide.wrangler.refactoring.selection.IErlSelection) SelectionKind(org.erlide.wrangler.refactoring.selection.IErlSelection.SelectionKind)

Example 5 with IErlSelection

use of org.erlide.wrangler.refactoring.selection.IErlSelection in project erlide_eclipse by erlang.

the class IntroduceLetRefactoring method getWorkflowController.

@Override
public RefactoringWorkflowController getWorkflowController(final Shell shell) {
    return new RefactoringWorkflowController(shell) {

        @Override
        public void doRefactoring() {
            final IErlSelection sel = GlobalParameters.getWranglerSelection();
            RefactoringRpcMessage message = (RefactoringRpcMessage) run(sel);
            if (message.isSuccessful()) {
                changedFiles = message.getRefactoringChangeset();
                status = new RefactoringStatus();
            } else if (message.getRefactoringState() == RefactoringState.QUESTION) {
                if (ask("Question", message.getMessageString())) {
                    final OtpErlangTuple res = message.getResultObject();
                    expr = ((OtpErlangTuple) res.elementAt(2)).elementAt(0);
                    parentExpr = ((OtpErlangTuple) res.elementAt(2)).elementAt(1);
                    message = (RefactoringRpcMessage) runAlternative(sel);
                    if (message.isSuccessful()) {
                        status = new RefactoringStatus();
                        changedFiles = message.getRefactoringChangeset();
                    } else {
                        status = RefactoringStatus.createFatalErrorStatus(message.getMessageString());
                    }
                } else {
                    status = RefactoringStatus.createFatalErrorStatus("Refactoring failed: the expression selected is not a QuickCheck generator.");
                }
            } else if (message.getRefactoringState() == RefactoringState.ERROR) {
                status = RefactoringStatus.createFatalErrorStatus(message.getMessageString());
            }
        }
    };
}
Also used : RefactoringWorkflowController(org.erlide.wrangler.refactoring.core.RefactoringWorkflowController) IRefactoringRpcMessage(org.erlide.wrangler.refactoring.backend.IRefactoringRpcMessage) RefactoringRpcMessage(org.erlide.wrangler.refactoring.backend.internal.RefactoringRpcMessage) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IErlSelection(org.erlide.wrangler.refactoring.selection.IErlSelection) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Aggregations

IErlSelection (org.erlide.wrangler.refactoring.selection.IErlSelection)22 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)19 IRefactoringRpcMessage (org.erlide.wrangler.refactoring.backend.IRefactoringRpcMessage)14 RefactoringWorkflowController (org.erlide.wrangler.refactoring.core.RefactoringWorkflowController)5 IErlMemberSelection (org.erlide.wrangler.refactoring.selection.IErlMemberSelection)5 ExpressionPosRpcMessage (org.erlide.wrangler.refactoring.backend.internal.ExpressionPosRpcMessage)4 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 WranglerException (org.erlide.wrangler.refactoring.exception.WranglerException)2 OtpErlangBoolean (com.ericsson.otp.erlang.OtpErlangBoolean)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 Shell (org.eclipse.swt.widgets.Shell)1