Search in sources :

Example 11 with IErlFunctionClause

use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.

the class ErlangEditor method setSelection.

public void setSelection(final ISourceReference reference, final boolean moveCursor) {
    if (getSelectionProvider() == null) {
        return;
    }
    final ISelection selection = getSelectionProvider().getSelection();
    if (selection instanceof TextSelection) {
        final TextSelection textSelection = (TextSelection) selection;
        if (moveCursor && (textSelection.getOffset() != 0 || textSelection.getLength() != 0)) {
            markInNavigationHistory();
        }
    }
    if (reference != null) {
        StyledText textWidget = null;
        final ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer == null) {
            return;
        }
        textWidget = sourceViewer.getTextWidget();
        if (textWidget == null) {
            return;
        }
        try {
            ISourceRange range = null;
            range = reference.getSourceRange();
            if (range == null) {
                return;
            }
            int offset = range.getOffset();
            int length = range.getLength();
            if (offset < 0 || length < 0) {
                return;
            }
            setHighlightRange(offset, length, moveCursor);
            if (!moveCursor) {
                return;
            }
            offset = -1;
            length = -1;
            if (reference instanceof IErlMember) {
                range = ((IErlMember) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            } else if (reference instanceof IErlAttribute) {
                range = ((IErlAttribute) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            } else if (reference instanceof IErlFunctionClause) {
                range = ((IErlFunctionClause) reference).getNameRange();
                if (range != null) {
                    offset = range.getOffset();
                    length = range.getLength();
                }
            }
            if (offset > -1 && length > 0) {
                try {
                    textWidget.setRedraw(false);
                    sourceViewer.revealRange(offset, length);
                    sourceViewer.setSelectedRange(offset, length);
                } finally {
                    textWidget.setRedraw(true);
                }
                markInNavigationHistory();
            }
        } catch (final IllegalArgumentException x) {
        }
    } else if (moveCursor) {
        resetHighlightRange();
        markInNavigationHistory();
    }
}
Also used : IErlMember(org.erlide.engine.model.erlang.IErlMember) StyledText(org.eclipse.swt.custom.StyledText) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IErlAttribute(org.erlide.engine.model.erlang.IErlAttribute) Point(org.eclipse.swt.graphics.Point) ISourceRange(org.erlide.engine.model.erlang.ISourceRange) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Example 12 with IErlFunctionClause

use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.

the class CallHierarchyAction method run.

@Override
public void run() {
    if (module == null) {
        return;
    }
    final IErlElement el = editor.getElementAt(editor.getViewer().getSelectedRange().x, false);
    IErlFunction f = null;
    if (el instanceof IErlFunction) {
        f = (IErlFunction) el;
    } else if (el instanceof IErlFunctionClause) {
        f = (IErlFunction) el.getParent();
    }
    if (f == null) {
        return;
    }
    String name = module.getName();
    final int i = name.lastIndexOf('.');
    if (i > 0) {
        name = name.substring(0, i);
    }
    final FunctionRef ref = new FunctionRef(name, f.getFunctionName(), f.getArity());
    final IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    final IWorkbenchPage page = dw.getActivePage();
    final AsyncCaller<CallHierarchyView> ac = new AsyncCaller<CallHierarchyView>(100) {

        @Override
        protected CallHierarchyView prepare() {
            try {
                final IViewPart p = page.showView("org.erlide.ui.callhierarchy");
                final CallHierarchyView cvh = p.getAdapter(CallHierarchyView.class);
                if (cvh == null) {
                    return null;
                }
                cvh.setMessage("<searching... project " + ErlangEngine.getInstance().getModelUtilService().getProject(module).getName() + ">");
                return cvh;
            } catch (final PartInitException e) {
                ErlLogger.error("could not open Call hierarchy view: ", e.getMessage());
                return null;
            }
        }

        @Override
        protected RpcFuture call() throws BackendException {
            final RpcFuture result = xrefService.addProject(ErlangEngine.getInstance().getModelUtilService().getProject(module));
            return result;
        }

        @Override
        protected void handleResult(final CallHierarchyView context, final RpcFuture result) {
            page.activate(context);
            try {
                context.setRoot(ErlangEngine.getInstance().getModel().findFunction(ref));
            } catch (final ErlModelException e) {
                ErlLogger.error(e);
            }
        }
    };
    ac.run();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) IErlFunction(org.erlide.engine.model.erlang.IErlFunction) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause) IErlElement(org.erlide.engine.model.IErlElement) CallHierarchyView(org.erlide.ui.views.CallHierarchyView) ErlModelException(org.erlide.engine.model.ErlModelException) AsyncCaller(org.erlide.ui.jinterface.AsyncCaller) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) RpcFuture(org.erlide.runtime.rpc.RpcFuture) PartInitException(org.eclipse.ui.PartInitException) FunctionRef(org.erlide.engine.model.erlang.FunctionRef)

Example 13 with IErlFunctionClause

use of org.erlide.engine.model.erlang.IErlFunctionClause in project erlide_eclipse by erlang.

the class ErlangLineBreakpoint method resetClauseHead.

protected void resetClauseHead(final int lineNumber, final IResource resource) {
    clauseHead = "";
    if (resource instanceof IFile) {
        final IFile file = (IFile) resource;
        final IErlModule m = ErlangEngine.getInstance().getModel().findModule(file);
        if (m != null) {
            try {
                m.open(null);
                final IErlElement e = m.getElementAtLine(lineNumber);
                if (e instanceof IErlFunctionClause) {
                    final IErlFunctionClause clause = (IErlFunctionClause) e;
                    clauseHead = clause.getName() + clause.getHead();
                }
            } catch (final ErlModelException e1) {
                ErlLogger.warn(e1);
            }
        }
    }
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) IFile(org.eclipse.core.resources.IFile) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) IErlFunctionClause(org.erlide.engine.model.erlang.IErlFunctionClause)

Aggregations

IErlFunctionClause (org.erlide.engine.model.erlang.IErlFunctionClause)13 IErlElement (org.erlide.engine.model.IErlElement)6 ErlModelException (org.erlide.engine.model.ErlModelException)4 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)4 IErlModule (org.erlide.engine.model.root.IErlModule)4 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IErlAttribute (org.erlide.engine.model.erlang.IErlAttribute)3 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)2 ISelection (org.eclipse.jface.viewers.ISelection)2 FunctionRef (org.erlide.engine.model.erlang.FunctionRef)2 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangRangeException (com.ericsson.otp.erlang.OtpErlangRangeException)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProject (org.eclipse.core.resources.IProject)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1