final String newParamName = dialog.getData();
dialog.close();
// call initial RPC
final GenFunRefactoringMessage m = (GenFunRefactoringMessage) WranglerBackendManager
.getRefactoringBackend().callWithParser(new GenFunRefactoringMessage(),
"generalise_eclipse", "sxxsxi", sel.getFilePath(),
sel.getSelectionRange().getStartPos(),
sel.getSelectionRange().getEndPos(), newParamName,
sel.getSearchPath(), GlobalParameters.getTabWidth());
// Examine the result of the refactoring: 4 cases
if (m.getRefactoringState() == RefactoringState.OK) {
refactoring = new GeneraliseFunctionRefactoring(State.ok, m);
} else if (m.getRefactoringState() == RefactoringState.MULTI_INSTANCES) {
refactoring = new GeneraliseFunctionRefactoring(State.multi_instance, m);
pages.add(new SelectionInputPage("Generalise expression",
"Please select which of them should be generalised!",
"Select one of them, which should be folded!",
(CostumWorkflowRefactoringWithPositionsSelection) refactoring));
} else if (m.getRefactoringState() == RefactoringState.MORE_THAN_ONE_CLAUSE) {
final boolean selectedClauseOnly = MessageDialog.openQuestion(activeShell,
"Multiple clauses",
"The function selected has multiple clauses, would you like"
+ " to generalise the function clause selected only?");
refactoring = new GeneraliseFunctionRefactoring(State.more_than_one_clause,
m, selectedClauseOnly);
if (((OtpErlangList) m.getParameters().get(
GenFunReturnParameterName.dupsInClause)).arity() > 0) {
pages.add(new SelectionInputPage("Generalise expression",
"Please select which of them should be generalised!",
"Select one of them, which should be folded!",
(CostumWorkflowRefactoringWithPositionsSelection) refactoring));
}
} else if (m.getRefactoringState() == RefactoringState.UNKNOWN_SIDE_EFFECT) {
final boolean sideEffect = MessageDialog.openQuestion(activeShell,
"Side effect", "Does the expression selected has side effect?");
final OtpErlangObject noOfClausesPar = m.getParameters().get(
GenFunReturnParameterName.noOfClauses);
if (noOfClausesPar != null && ((OtpErlangLong) noOfClausesPar).intValue() > 1) {
final boolean selectedClauseOnly = MessageDialog.openQuestion(
activeShell, "Multiple clauses",
"The function selected has multiple clauses, would you like"
+ " to generalise the function clause selected only?");
refactoring = new GeneraliseFunctionRefactoring(
State.unknown_side_effect, m, selectedClauseOnly, sideEffect);
if (!selectedClauseOnly
&& ((OtpErlangList) m.getParameters().get(
GenFunReturnParameterName.dupsInFun)).arity() > 0
|| selectedClauseOnly
&& ((OtpErlangList) m.getParameters().get(
GenFunReturnParameterName.dupsInClause)).arity() > 0) {
pages.add(new SelectionInputPage("Generalise expression",
"Please select which of them should be generalised!",
"Select one of them, which should be folded!",
(CostumWorkflowRefactoringWithPositionsSelection) refactoring));
}
} else {
refactoring = new GeneraliseFunctionRefactoring(
State.unknown_side_effect, m, true, sideEffect);
pages.add(new SelectionInputPage("Generalise expression",
"Please select which of them should be generalised!",
"Select one of them, which should be folded!",
(CostumWorkflowRefactoringWithPositionsSelection) refactoring));
}
} else if (m.getRefactoringState() == RefactoringState.ERROR) {
refactoring = new GeneraliseFunctionRefactoring(State.error,
m.getMessageString());
} else {
// error?
return null;
}