Search in sources :

Example 6 with IErlMember

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

the class ErlParser method checkForComment.

private void checkForComment(final List<IErlMember> all, final int i) {
    final IErlMember m = all.get(i);
    if (m instanceof IErlFunction) {
        final IErlFunction function = (IErlFunction) m;
        final LinkedList<IErlComment> comments = Lists.newLinkedList();
        int j = considerPrevious(i, all, comments, function);
        j = considerPrevious(j, all, comments, function);
        j = considerPrevious(j, all, comments, function);
        if (!comments.isEmpty()) {
            function.setComments(comments);
        }
    }
}
Also used : IErlComment(org.erlide.engine.model.erlang.IErlComment) IErlMember(org.erlide.engine.model.erlang.IErlMember) IErlFunction(org.erlide.engine.model.erlang.IErlFunction)

Example 7 with IErlMember

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

the class ErlParser method considerPrevious.

private int considerPrevious(final int i, final List<IErlMember> all, final Deque<IErlComment> comments, final IErlFunction function) {
    final int j = i - 1;
    if (j > 0) {
        final IErlMember member = all.get(i);
        final IErlMember prevMember = all.get(j);
        if (prevMember instanceof IErlComment) {
            if (prevMember.getLineEnd() + ErlParser.FUNCTION_COMMENT_THRESHOLD >= member.getLineStart()) {
                comments.addFirst((IErlComment) prevMember);
            }
        } else if (prevMember instanceof IErlTypespec) {
            final IErlTypespec spec = (IErlTypespec) prevMember;
            if (spec.getName().equals(function.getName()) && spec.getArity() == function.getArity() && prevMember.getLineEnd() + ErlParser.FUNCTION_COMMENT_THRESHOLD >= member.getLineStart()) {
                function.setTypespec(spec);
            }
        } else {
            return -1;
        }
    }
    return j;
}
Also used : IErlComment(org.erlide.engine.model.erlang.IErlComment) IErlMember(org.erlide.engine.model.erlang.IErlMember) IErlTypespec(org.erlide.engine.model.erlang.IErlTypespec)

Example 8 with IErlMember

use of org.erlide.engine.model.erlang.IErlMember 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)

Aggregations

IErlMember (org.erlide.engine.model.erlang.IErlMember)8 IErlElement (org.erlide.engine.model.IErlElement)3 IErlComment (org.erlide.engine.model.erlang.IErlComment)3 OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 Position (org.eclipse.jface.text.Position)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 IProjectionPosition (org.eclipse.jface.text.source.projection.IProjectionPosition)1 ISelection (org.eclipse.jface.viewers.ISelection)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1 ErlMacroDef (org.erlide.engine.internal.model.erlang.ErlMacroDef)1