use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class SimpleCodeInspectionHandler method processFunctionResult.
private ArrayList<IErlElement> processFunctionResult(final Shell shell, final RpcResult result) throws OtpErlangRangeException {
final ArrayList<IErlElement> elements = new ArrayList<>();
final OtpErlangObject obj = result.getValue();
final OtpErlangTuple restuple = (OtpErlangTuple) obj;
final OtpErlangAtom resindicator = (OtpErlangAtom) restuple.elementAt(0);
if ("ok".equals(resindicator.atomValue())) {
final OtpErlangList erlangFunctionList = (OtpErlangList) restuple.elementAt(1);
for (int i = 0; i < erlangFunctionList.arity(); ++i) {
final OtpErlangTuple fTuple = (OtpErlangTuple) erlangFunctionList.elementAt(i);
IErlFunctionClause f;
try {
f = extractFunction(fTuple);
elements.add(f);
} catch (final ErlModelException e) {
}
}
} else {
final OtpErlangString s = (OtpErlangString) restuple.elementAt(1);
MessageDialog.openError(shell, "Error", s.stringValue());
return null;
}
return elements;
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class SearchPatternFactory method getSearchPatternFromErlElementAndLimitTo.
public ErlangSearchPattern getSearchPatternFromErlElementAndLimitTo(final IErlElement element, final LimitTo limitTo) {
if (element instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) element;
final String withoutExtension = SystemConfiguration.withoutExtension(function.getModuleName());
return new FunctionPattern(withoutExtension, function.getFunctionName(), function.getArity(), limitTo, true, modelUtilService.getModule(function), !function.isExported());
} else if (element instanceof IErlMacroDef) {
final IErlMacroDef m = (IErlMacroDef) element;
final String unquoted = StringUtils.unquote(m.getDefinedName());
return new MacroPattern(unquoted, limitTo);
} else if (element instanceof IErlRecordDef) {
final IErlRecordDef r = (IErlRecordDef) element;
final String unquoted = StringUtils.unquote(r.getDefinedName());
return new RecordPattern(unquoted, limitTo);
} else if (element instanceof IErlFunctionClause) {
final IErlFunctionClause clause = (IErlFunctionClause) element;
return getSearchPatternFromErlElementAndLimitTo((IErlElement) clause.getParent(), limitTo);
} else if (element instanceof IErlAttribute) {
final IErlAttribute a = (IErlAttribute) element;
if (a.getName().startsWith("include")) {
final String s = Util.stringValue(a.getValue());
return new IncludePattern(s, limitTo);
}
}
return null;
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class RefactoringHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
try {
GlobalParameters.setSelection(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection());
} catch (final WranglerException e1) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", e1.getMessage());
return null;
}
if (!checkForDirtyEditors()) {
return null;
}
DefaultWranglerRefactoringWizard wizard = null;
WranglerRefactoring refactoring = null;
final String actionId = event.getCommand().getId();
final ArrayList<WranglerPage> pages = new ArrayList<>();
// apply ad hoc refactoring
if ("org.erlide.wrangler.refactoring.adhoc".equals(actionId)) {
final InputDialog dialog = getModuleInput("Apply ad hoc refactoring", "Please type the gen_refac module name!");
dialog.open();
if (dialog.getReturnCode() == Window.CANCEL) {
return null;
}
final String callbackModule = dialog.getValue();
pages.add(new UserRefacInputPage("Apply ad hoc refactoring", "Please type input arguments for this refactoring", "Arguments should not be empty!", new NonEmptyStringValidator()));
refactoring = new ApplyAdhocElemRefactoring();
((ApplyAdhocElemRefactoring) refactoring).setCallbackModuleName(callbackModule);
if (!((ApplyAdhocElemRefactoring) refactoring).fetchParPrompts()) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Elementary refactoring error", "Can not load callback module");
return null;
}
// apply user-defined refactoring
} else if ("org.erlide.wrangler.refactoring.gen_refac".equals(actionId)) {
final String callbackModule = event.getParameter("org.erlide.wrangler.refactoring.gen_refac.callback");
final String name = event.getParameter("org.erlide.wrangler.refactoring.gen_refac.name");
pages.add(new UserRefacInputPage(name, "Please type input arguments for this refactoring", "Arguments should not be empty!", new NonEmptyStringValidator()));
refactoring = new ApplyUserElementaryRefactoring(name, callbackModule);
if (!((ApplyUserElementaryRefactoring) refactoring).fetchParPrompts()) {
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Refactoring error", "Can not find callback module");
return null;
}
// run rename variable refactoring
} else if ("org.erlide.wrangler.refactoring.renamevariable".equals(actionId)) {
refactoring = new RenameVariableRefactoring();
final SimpleInputPage page = new SimpleInputPage("Rename variable", "Please type the new variable name!", "New variable name:", "New name must be a valid Erlang variable name!", new VariableNameValidator());
page.setInput(refactoring.getDefaultValue());
pages.add(page);
// introduce new variable refactoring
} else if ("org.erlide.wrangler.refactoring.introducenewvariable".equals(actionId)) {
pages.add(new SimpleInputPage("Introduce new variable", "Please type the new variable name!", "New variable name:", "New name must be a valid Erlang variable name!", new VariableNameValidator()));
refactoring = new IntroduceNewVariableRefactoring();
// run rename function refactoring
} else if ("org.erlide.wrangler.refactoring.renamefunction".equals(actionId)) {
refactoring = new RenameFunctionRefactoring();
final CostumworkFlowInputPage page = new CostumworkFlowInputPage("Rename function", "Please type the new function name!", "New function name:", "New name must be a valid Erlang atom!", new AtomValidator());
page.setInput(refactoring.getDefaultValue());
pages.add(page);
// run extract function refactoring
} else if ("org.erlide.wrangler.refactoring.extractfunction".equals(actionId)) {
pages.add(new CostumworkFlowInputPage("Extract function", "Please type a function name!", "Function name:", "Function name must be a valid Erlang atom!", new AtomValidator()));
refactoring = new ExtractFunctionRefactoring();
// run rename module refactoring
} else if ("org.erlide.wrangler.refactoring.renamemodule".equals(actionId)) {
final boolean answer = MessageDialog.openQuestion(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Warning!", "The requested operation cannot be undone. Would you like to continue?");
if (!answer) {
return null;
}
refactoring = new RenameModuleRefactoring();
final CostumworkFlowInputPage page = new CostumworkFlowInputPage("Rename module", "Please type the new module name!", "New module name:", "New module name must be a valid Erlang atom!", new AtomValidator());
page.setInput(refactoring.getDefaultValue());
pages.add(page);
// run move function refactoring
} else if ("org.erlide.wrangler.refactoring.movefunction".equals(actionId)) {
final IProject project = ErlangEngine.getInstance().getModelUtilService().getProject(GlobalParameters.getWranglerSelection().getErlElement()).getWorkspaceProject();
final ArrayList<String> moduleList = WranglerUtils.getModuleNames(project);
final String moduleName = GlobalParameters.getWranglerSelection().getErlElement().getResource().getName();
moduleList.remove(WranglerUtils.removeExtension(moduleName));
pages.add(new ComboInputPage("Move function", "Please select the destination module", "Destination module:", moduleList));
refactoring = new MoveFunctionRefactoring();
// run fold expression against a local function
} else if ("org.erlide.wrangler.refactoring.foldlocalexpression".equals(actionId)) {
refactoring = new FoldLocalExpressionRefactoring();
pages.add(new SelectionInputPage("Fold expression", "Please select expression which should be fold!", "Select expressions which should be folded!", (CostumWorkflowRefactoringWithPositionsSelection) refactoring));
// run fold expression against a remote function
} else {
final Shell activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
if ("org.erlide.wrangler.refactoring.foldremoteexpression".equals(actionId)) {
// must store the selection, because, the user through the
// dialog
// may change it
final IErlMemberSelection sel = (IErlMemberSelection) GlobalParameters.getWranglerSelection();
final RemoteFunctionClauseDialog dialog = new RemoteFunctionClauseDialog(activeShell, "Fold expression");
dialog.open();
dialog.resetSelection();
if (dialog.isFinished()) {
final IErlFunctionClause functionClause = dialog.getFunctionClause();
refactoring = new FoldRemoteExpressionRefactoring(functionClause, sel);
pages.add(new SelectionInputPage("Fold expression", "Please select expression which should be fold!", "Select expressions which should be folded!", (CostumWorkflowRefactoringWithPositionsSelection) refactoring));
} else {
return null;
}
// run introduce macro refactoring
} else if ("org.erlide.wrangler.refactoring.introducemacro".equals(actionId)) {
refactoring = new IntroduceMacroRefactoring();
pages.add(new SimpleInputPage("Introduce macro definition", "Please type the new macro name!", "New macro name:", "Macro name cannot be empty!", new NonEmptyStringValidator()));
// run rename process refactoring
} else if ("org.erlide.wrangler.refactoring.renameprocess".equals(actionId)) {
refactoring = new RenameProcessRefactoring();
pages.add(new SimpleInputPage("Rename process", "Please type the new process name!", "New process name:", "New process name must be an Erlang atom!", new AtomValidator()));
// run function to process refactoring
} else if ("org.erlide.wrangler.refactoring.functiontoprocess".equals(actionId)) {
refactoring = new FunctionToProcessRefactoring();
pages.add(new SimpleInputPage("Convert function to process", "Please type the new process name!", "New process name:", "New process name must be an Erlang atom!", new AtomValidator()));
// run tuple function parameters refactoring
} else if ("org.erlide.wrangler.refactoring.tuplefunctonparameters".equals(actionId)) {
refactoring = new TupleFunctionParametersRefactoring();
// run generalise function refactoring
} else if ("org.erlide.wrangler.refactoring.generalise".equals(actionId)) {
/*
* pages.add(new CostumworkFlowInputPage("Generalise function",
* "Please type the new parameter name!", "New parameter name:",
* "New parameter name must be a valid Erlang variable name!",
* new VariableNameValidator()));
*/
try {
refactoring = runGenFunRefactoring(pages, activeShell);
} catch (final OtpErlangRangeException e) {
ErlLogger.error(e);
return null;
}
if (refactoring == null) {
return null;
}
// fold against macro definition
} else if ("org.erlide.wrangler.refactoring.foldagainstmacro".equals(actionId)) {
refactoring = new FoldAgainstMacro();
pages.add(new SelectionInputPage("Fold against macro definition", "Please select expression which should be fold!", "Select expressions which should be folded!", (CostumWorkflowRefactoringWithPositionsSelection) refactoring));
// normalize record expression
} else if ("org.erlide.wrangler.refactoring.normalizerecordexpression".equals(actionId)) {
final boolean showDefaultFields = MessageDialog.openQuestion(activeShell, "Showing defaults", "Show record fields with default values?");
refactoring = new NormalizeRecordExpression(showDefaultFields);
} else if ("org.erlide.wrangler.refactoring.introducelet".equals(actionId)) {
pages.add(new CostumworkFlowInputPage("Introduce ?LET", "Please type the pattern variable name!", "Pattern variable name:", "New name must be a valid Erlang atom!", new VariableNameValidator()));
refactoring = new IntroduceLetRefactoring();
} else if ("org.erlide.wrangler.refactoring.mergelet".equals(actionId)) {
refactoring = new MergeLetRefactoring();
pages.add(new SelectionInputPage("Merge ?LET expressions", "Please select expressions which whould be merged!", "Select expressions which should be merged", (CostumWorkflowRefactoringWithPositionsSelection) refactoring));
} else if ("org.erlide.wrangler.refactoring.mergeforall".equals(actionId)) {
refactoring = new MergeForAllRefactoring();
pages.add(new SelectionInputPage("Merge ?FORALL expressions", "Please select expressions which should be merged!", "Select expressions which should be merged", (CostumWorkflowRefactoringWithPositionsSelection) refactoring));
} else if ("org.erlide.wrangler.refactoring.eqc_statemtorecord".equals(actionId)) {
refactoring = new EqcStatemStateDataToRecordRefactoring();
pages.add(new RecordDataInputPage("eqc_statem State Data To Record"));
} else if ("org.erlide.wrangler.refactoring.eqc_fsmtorecord".equals(actionId)) {
refactoring = new EqcFsmStateDataToRecordRefactoring();
pages.add(new RecordDataInputPage("eqc_fsm State Data To Record"));
} else if ("org.erlide.wrangler.refactoring.gen_fsmtorecord".equals(actionId)) {
refactoring = new GenFsmStateDataToRecordRefactoring();
pages.add(new RecordDataInputPage("gen_fsm State Data To Record"));
} else if ("org.erlide.wrangler.refactoring.unfoldfunctionapplication".equals(actionId)) {
refactoring = new UnfoldFunctionApplicationRefactoring();
} else if ("org.erlide.wrangler.refactoring.partitionexports".equals(actionId)) {
refactoring = new PartitionExportsRefactoring();
final SimpleInputPage page = new SimpleInputPage("Partition exports", "Please input the the distance treshould between 0.1 and 1.0", "Distance treshold", "The value must be between 0.1 and 1.0", new NormalDoulbeValidator());
page.setInput("0.8");
pages.add(page);
} else {
return null;
}
}
refactoring.doBeforeRefactoring();
// run the given refactoring's wizard
wizard = new DefaultWranglerRefactoringWizard(refactoring, RefactoringWizard.DIALOG_BASED_USER_INTERFACE, pages);
final Shell shell = new Shell();
final RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
try {
final int ret = op.run(shell, refactoring.getName());
if (RefactoringStatus.OK == ret) {
refactoring.doAfterRefactoring();
}
} catch (final Exception e) {
ErlLogger.error(e);
}
checkWarningMessages();
return null;
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class RemoteFunctionClauseDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
final Tree functionClausesTree;
final Label label = new Label(composite, SWT.WRAP);
label.setText("Please select the function clause which against should fold!");
final GridData minToksData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
minToksData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(minToksData);
label.setFont(parent.getFont());
functionClausesTree = new Tree(composite, SWT.BORDER);
final GridData treeData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
treeData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
functionClausesTree.setLayoutData(treeData);
try {
final Collection<IErlModule> erlmodules = ErlangEngine.getInstance().getModelUtilService().getProject(GlobalParameters.getWranglerSelection().getErlElement()).getModules();
for (final IErlModule m : erlmodules) {
// must refresh the scanner!
m.open(null);
final TreeItem moduleName = new TreeItem(functionClausesTree, 0);
moduleName.setText(m.getModuleName());
moduleName.setData(m);
final List<IErlFunction> functions = filterFunctions(m.getChildren());
for (final IErlFunction f : functions) {
final TreeItem functionName = new TreeItem(moduleName, 0);
functionName.setText(f.getNameWithArity());
final List<IErlFunctionClause> clauses = filterClauses(f.getChildren());
functionName.setData(f);
for (final IErlFunctionClause c : clauses) {
final TreeItem clauseName = new TreeItem(functionName, 0);
clauseName.setText(String.valueOf(c.getName()));
clauseName.setData(c);
}
}
}
// listen to treeitem selection
functionClausesTree.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
}
// if a function or a function clause is selected, then
// highlight it
// and store the selection
@Override
public void widgetSelected(final SelectionEvent e) {
final TreeItem[] selectedItems = functionClausesTree.getSelection();
if (selectedItems.length > 0) {
final TreeItem treeItem = selectedItems[0];
final Object data = treeItem.getData();
if (data instanceof IErlFunctionClause) {
// enable the ok button
okButton.setEnabled(true);
// highlight
WranglerUtils.highlightSelection((IErlFunctionClause) data);
// store
functionClause = (IErlFunctionClause) data;
} else {
okButton.setEnabled(false);
}
}
}
});
} catch (final ErlModelException e) {
ErlLogger.error(e);
}
applyDialogFont(composite);
return composite;
}
use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.
the class MoveFunctionDropHandler method validateDrop.
@Override
public IStatus validateDrop(final Object target, final int operation, final TransferData transferType) {
final ISelection sel = (ISelection) LocalSelectionTransfer.getTransfer().nativeToJava(transferType);
final TreeSelection s = (TreeSelection) sel;
final IErlElement e = (IErlElement) s.getFirstElement();
if (e instanceof IErlFunctionClause) {
if (target instanceof IErlElement || target instanceof IFile) {
return Status.OK_STATUS;
}
}
return Status.CANCEL_STATUS;
}
Aggregations