Search in sources :

Example 1 with ISourceRange

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

the class ModelFindUtil method findVariable.

@Override
public ISourceRange findVariable(final ISourceRange range, final String variableName, final String elementText) throws OtpErlangRangeException {
    final OtpErlangTuple res2 = ErlangEngine.getInstance().getOpenService().findFirstVar(variableName, elementText);
    if (res2 != null) {
        final int relativePos = ((OtpErlangLong) res2.elementAt(0)).intValue() - 1;
        final int length = ((OtpErlangLong) res2.elementAt(1)).intValue();
        final int start = relativePos + range.getOffset();
        return new SourceRange(start, length);
    }
    return range;
}
Also used : OtpErlangLong(com.ericsson.otp.erlang.OtpErlangLong) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) ISourceRange(org.erlide.engine.model.erlang.ISourceRange) SourceRange(org.erlide.engine.internal.model.SourceRange)

Example 2 with ISourceRange

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

the class MarkerUtils method createProblemMarkerFor.

public void createProblemMarkerFor(final IResource resource, final IErlFunction erlElement, final String message, final int problemSeverity) throws CoreException {
    final ISourceRange range = erlElement == null ? null : erlElement.getNameRange();
    final IMarker marker = MarkerUtils.createProblemMarker(resource, null, message, 0, problemSeverity);
    final int start = range == null ? 0 : range.getOffset();
    final int end = range == null ? 1 : start + range.getLength();
    marker.setAttribute(IMarker.CHAR_START, start);
    marker.setAttribute(IMarker.CHAR_END, end);
}
Also used : IMarker(org.eclipse.core.resources.IMarker) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Example 3 with ISourceRange

use of org.erlide.engine.model.erlang.ISourceRange 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 4 with ISourceRange

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

Example 5 with ISourceRange

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

the class ErlangAbstractHandler method getTextSelection.

/**
 * Provide the text selection that is needed to execute the command. Default
 * implementation, extend to Erlang elements selected.
 *
 * @param document
 *            text {@link IDocument}
 * @param selection
 *            selection affected by command (extended by extendSelection)
 * @return new {@link ITextSelection} with all text up to selection
 */
protected ITextSelection getTextSelection(final IDocument document, final ITextSelection selection, final ITextEditor editor) {
    if (editor instanceof ErlangEditor) {
        final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) editor;
        final IErlModule module = erlangEditor.getModule();
        if (module != null) {
            final int offset1 = selection.getOffset();
            final int offset2 = offset1 + selection.getLength();
            try {
                final IErlElement e1 = module.getElementAt(offset1);
                final IErlElement e2 = module.getElementAt(offset2);
                if (e1 instanceof ISourceReference) {
                    final ISourceReference ref1 = (ISourceReference) e1;
                    final ISourceRange r1 = ref1.getSourceRange();
                    final int offset = r1.getOffset();
                    int length = r1.getLength();
                    if (e1 == e2) {
                        final int docLength = document.getLength();
                        if (offset + length > docLength) {
                            length = docLength - offset;
                        }
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, length));
                    } else if (e2 == null) {
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, selection.getLength() + selection.getOffset() - offset));
                    } else if (e2 instanceof ISourceReference) {
                        final ISourceReference ref2 = (ISourceReference) e2;
                        final ISourceRange r2 = ref2.getSourceRange();
                        return ErlangAbstractHandler.extendSelectionToWholeLines(document, new TextSelection(document, offset, r2.getOffset() - offset + r2.getLength()));
                    }
                }
            } catch (final ErlModelException e) {
            }
        }
    }
    return ErlangAbstractHandler.extendSelectionToWholeLines(document, selection);
}
Also used : IErlElement(org.erlide.engine.model.IErlElement) ErlModelException(org.erlide.engine.model.ErlModelException) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IErlModule(org.erlide.engine.model.root.IErlModule) ISourceReference(org.erlide.engine.model.erlang.ISourceReference) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ErlangEditor(org.erlide.ui.editors.erl.ErlangEditor) AbstractErlangEditor(org.erlide.ui.editors.erl.AbstractErlangEditor) ISourceRange(org.erlide.engine.model.erlang.ISourceRange)

Aggregations

ISourceRange (org.erlide.engine.model.erlang.ISourceRange)8 ISourceReference (org.erlide.engine.model.erlang.ISourceReference)5 ITextSelection (org.eclipse.jface.text.ITextSelection)2 TextSelection (org.eclipse.jface.text.TextSelection)2 ErlModelException (org.erlide.engine.model.ErlModelException)2 IErlElement (org.erlide.engine.model.IErlElement)2 IErlModule (org.erlide.engine.model.root.IErlModule)2 OtpErlangLong (com.ericsson.otp.erlang.OtpErlangLong)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 Function (com.google.common.base.Function)1 IMarker (org.eclipse.core.resources.IMarker)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 Region (org.eclipse.jface.text.Region)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1