Search in sources :

Example 1 with ISourceReference

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

the class ErlangEditor method setSelection.

public void setSelection(final IErlElement element) {
    if (element == null || element instanceof IErlModule) {
        return;
    }
    if (element instanceof ISourceReference) {
        final ISourceReference reference = (ISourceReference) element;
        // set highlight range
        setSelection(reference, true);
        if (myOutlinePage != null) {
            myOutlinePage.select(reference);
        }
    }
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference)

Example 2 with ISourceReference

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

the class ErlangEditor method computeHighlightRangeSourceReference.

protected ISourceReference computeHighlightRangeSourceReference() {
    final ISourceViewer sourceViewer = getSourceViewer();
    if (sourceViewer == null) {
        return null;
    }
    final StyledText styledText = sourceViewer.getTextWidget();
    if (styledText == null) {
        return null;
    }
    int caret = 0;
    if (sourceViewer instanceof ITextViewerExtension5) {
        final ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
        caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
    } else {
        final int offset = sourceViewer.getVisibleRegion().getOffset();
        caret = offset + styledText.getCaretOffset();
    }
    final IErlElement element = getElementAt(caret, false);
    if (!(element instanceof ISourceReference)) {
        return null;
    }
    return (ISourceReference) element;
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) Point(org.eclipse.swt.graphics.Point)

Example 3 with ISourceReference

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

the class ErlangEditor method selectionChanged.

protected void selectionChanged() {
    if (getSelectionProvider() == null) {
        return;
    }
    final ISourceReference element = computeHighlightRangeSourceReference();
    if (isLinkedToOutlinePage()) {
        synchronizeOutlinePage(element);
    }
    setSelection(element, false);
// updateStatusLine();
}
Also used : ISourceReference(org.erlide.engine.model.erlang.ISourceReference)

Example 4 with ISourceReference

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

the class ErlNode method createErlNode.

public static ErlNode createErlNode(final ErlNode parent, final IErlElement element, final IDocument doc) {
    int start = 0;
    int length = 0;
    String name = element.toString();
    if (element instanceof IErlModule) {
        final IErlModule m = (IErlModule) element;
        length = doc.getLength();
        name = m.getModuleName();
    } else if (element instanceof ISourceReference) {
        final ISourceReference sourceReference = (ISourceReference) element;
        final ISourceRange sr = sourceReference.getSourceRange();
        start = sr.getOffset();
        length = sr.getLength();
    }
    return new ErlNode(parent, element.getKind(), name, ErlangCompareUtilities.getErlElementID(element), doc, start, length);
}
Also used : IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Example 5 with ISourceReference

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

the class DefaultErlangFoldingStructureProvider method computeProjectionRanges.

// private boolean isInnerType(IType type) {
// return type.getDeclaringType() != null;
// }
/**
 * Computes the projection ranges for a given <code>IErlElement</code>. More
 * than one range may be returned if the element has a leading comment which
 * gets folded separately. If there are no foldable regions,
 * <code>null</code> is returned.
 *
 * @param element
 *            the erlang element that can be folded
 * @return the regions to be folded, or <code>null</code> if there are none
 */
private IRegion computeProjectionRanges(final IErlElement element) {
    if (element instanceof ISourceReference) {
        final ISourceReference reference = (ISourceReference) element;
        final ISourceRange range = reference.getSourceRange();
        return new Region(range.getOffset(), range.getLength());
    }
    return null;
}
Also used : IRegion(org.eclipse.jface.text.IRegion) Region(org.eclipse.jface.text.Region) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Aggregations

ISourceReference (org.erlide.engine.model.erlang.ISourceReference)10 ISourceRange (org.erlide.engine.model.erlang.ISourceRange)5 IErlElement (org.erlide.engine.model.IErlElement)4 ErlModelException (org.erlide.engine.model.ErlModelException)3 IErlModule (org.erlide.engine.model.root.IErlModule)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 Function (com.google.common.base.Function)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)1 Region (org.eclipse.jface.text.Region)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StyledText (org.eclipse.swt.custom.StyledText)1 Point (org.eclipse.swt.graphics.Point)1