Search in sources :

Example 6 with IErlFunction

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeItem(org.eclipse.swt.widgets.TreeItem) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) Label(org.eclipse.swt.widgets.Label) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) ErlModelException(org.erlide.engine.model.ErlModelException) GridData(org.eclipse.swt.layout.GridData) IErlModule(org.erlide.engine.model.root.IErlModule) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with IErlFunction

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();
}
Also used : IErlFunction(org.erlide.engine.model.erlang.IErlFunction) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ExpressionPosRpcMessage(org.erlide.wrangler.refactoring.backend.internal.ExpressionPosRpcMessage)

Example 8 with IErlFunction

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;
}
Also used : IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlModule(org.erlide.engine.model.root.IErlModule) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor)

Example 9 with IErlFunction

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;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ISelection(org.eclipse.jface.viewers.ISelection) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Example 10 with IErlFunction

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;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) ISelection(org.eclipse.jface.viewers.ISelection) TracePattern(org.erlide.tracing.core.mvc.model.TracePattern)

Aggregations

IErlFunction (org.erlide.engine.model.erlang.IErlFunction)22 IErlModule (org.erlide.engine.model.root.IErlModule)7 IErlElement (org.erlide.engine.model.IErlElement)6 ISelection (org.eclipse.jface.viewers.ISelection)5 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)5 ErlModelException (org.erlide.engine.model.ErlModelException)5 ErlangFunction (org.erlide.engine.model.erlang.ErlangFunction)4 IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)3 IErlPreprocessorDef (org.erlide.engine.model.erlang.IErlPreprocessorDef)3 IErlElementLocator (org.erlide.engine.model.root.IErlElementLocator)3 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 PartInitException (org.eclipse.ui.PartInitException)2 IErlModel (org.erlide.engine.model.root.IErlModel)2 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1