use of org.erlide.engine.model.erlang.IErlFunction 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.IErlFunction in project erlide_eclipse by erlang.
the class FoldRemoteExpressionRefactoring method checkInitialConditions.
@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
if (functionClause == null) {
return RefactoringStatus.createFatalErrorStatus("No function clause was given!");
}
ExpressionPosRpcMessage m = new ExpressionPosRpcMessage();
final String path = selection.getFilePath();
final String moduleName = ErlangEngine.getInstance().getModelUtilService().getModule(functionClause).getModuleName();
final String functionName = functionClause.getFunctionName();
final int arity = functionClause.getArity();
int clauseIndex = 1;
if (!(functionClause instanceof IErlFunction)) {
clauseIndex = Integer.valueOf(functionClause.getName().substring(1));
}
m = (ExpressionPosRpcMessage) WranglerBackendManager.getRefactoringBackend().callWithParser(m, "fold_expr_by_name_eclipse", "sssiixi", path, moduleName, functionName, arity, clauseIndex, selection.getSearchPath(), GlobalParameters.getTabWidth());
if (m.isSuccessful()) {
syntaxTree = m.getSyntaxTree();
// TODO: store positions, selectedpositions
positions = m.getPositionDefinitions(selection.getDocument());
selectedPositions = new ArrayList<>();
} else {
return RefactoringStatus.createFatalErrorStatus(m.getMessageString());
}
return new RefactoringStatus();
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class ErlModelUtils method openFunctionInEditor.
/**
* Activate editor and select erlang function
*/
public static boolean openFunctionInEditor(final ErlangFunction erlangFunction, final IEditorPart editor) throws CoreException {
final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
final IErlModule module = erlangEditor.getModule();
if (module == null) {
return false;
}
module.open(null);
final IErlFunction function = module.findFunction(erlangFunction);
if (function == null) {
return false;
}
EditorUtility.revealInEditor(editor, function);
return true;
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class CreateTracePatternWithNoArityHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
if (selection instanceof ITreeSelection) {
final Object firstElement = ((ITreeSelection) selection).getFirstElement();
if (firstElement instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) firstElement;
final TracePattern tracePattern = new TracePattern(true);
tracePattern.setFunctionName(function.getFunctionName());
tracePattern.setModuleName(ErlangEngine.getInstance().getModelUtilService().getModule(function).getModuleName());
tracePattern.setLocal(true);
tracePattern.setEnabled(true);
TraceBackend.getInstance().addTracePattern(tracePattern);
}
}
return null;
}
use of org.erlide.engine.model.erlang.IErlFunction in project erlide_eclipse by erlang.
the class RemoveTracePatternWithNoArityHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
if (selection instanceof ITreeSelection) {
final Object firstElement = ((ITreeSelection) selection).getFirstElement();
if (firstElement instanceof IErlFunction) {
final IErlFunction function = (IErlFunction) firstElement;
final TracePattern tracePattern = new TracePattern(true);
tracePattern.setFunctionName(function.getFunctionName());
tracePattern.setModuleName(ErlangEngine.getInstance().getModelUtilService().getModule(function).getModuleName());
TraceBackend.getInstance().removeTracePattern(tracePattern);
}
}
return null;
}
Aggregations