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;
}
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;
}
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());
}
}
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!");
}
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());
}
}
};
}
Aggregations