Search in sources :

Example 61 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class StructuredPresentationReconciler method getDamageEndOffset.

/**
 * Returns the end offset of the damage. If a partition has been split by
 * the given document event also the second half of the original
 * partition must be considered. This is achieved by using the remembered
 * partition range.
 *
 * @param e the event describing the change
 * @return the damage end offset (excluding)
 * @exception BadLocationException if method accesses invalid offset
 */
int getDamageEndOffset(DocumentEvent e) throws BadLocationException {
    IDocument d = e.getDocument();
    int length = 0;
    if (e.getText() != null) {
        length = e.getText().length();
        if (length > 0)
            --length;
    }
    ITypedRegion partition = getPartition(d, e.getOffset() + length);
    int endOffset = partition.getOffset() + partition.getLength();
    if (endOffset == e.getOffset())
        return -1;
    int end = fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength();
    if (endOffset < end && end < d.getLength())
        partition = getPartition(d, end);
    // if there is not damager for the partition then use the endOffset of the partition
    IPresentationDamager damager = getDamager(partition.getType());
    if (damager != null) {
        IRegion r = damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
        endOffset = r.getOffset() + r.getLength();
    }
    return endOffset;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) IPresentationDamager(org.eclipse.jface.text.presentation.IPresentationDamager) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion)

Example 62 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class DebugInfoHoverProcessor method getHoverInfo.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer,
	 *      org.eclipse.jface.text.IRegion)
	 */
public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) {
    String displayText = null;
    if ((hoverRegion == null) || (viewer == null) || (viewer.getDocument() == null)) {
        displayText = null;
    } else {
        int offset = hoverRegion.getOffset();
        ITypedRegion region;
        try {
            region = viewer.getDocument().getPartition(offset);
            if (region != null) {
                displayText = region.getType();
            } else {
                // $NON-NLS-1$
                displayText = "Null Region was returned?!";
            }
        } catch (BadLocationException e) {
            // $NON-NLS-1$
            displayText = "BadLocationException Occurred!?";
        }
    }
    return displayText;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 63 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class FastPartitionerTest method assertComputePartitioning_InterleavingPartitions.

private void assertComputePartitioning_InterleavingPartitions(int startOffset, int endOffset, int[] offsets, String startType) {
    ITypedRegion[] regions = fPartitioner.computePartitioning(startOffset, endOffset - startOffset);
    String type = startType;
    int previousOffset = startOffset;
    int j = 0;
    for (int i = 0; i <= offsets.length; i++) {
        int currentOffset = (i == offsets.length) ? endOffset : offsets[i];
        if (currentOffset - previousOffset != 0) {
            // don't do empty partitions
            ITypedRegion region = regions[j++];
            assertTypedRegion(region, previousOffset, currentOffset, type);
        }
        // advance
        if (type == DEFAULT)
            type = COMMENT;
        else
            type = DEFAULT;
        previousOffset = currentOffset;
    }
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion)

Example 64 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class FastPartitionerTest method assertEqualPartition.

private void assertEqualPartition(int offset, int end, String type) {
    int from = offset;
    int to = end - 1;
    for (int i = from; i <= to; i++) {
        ITypedRegion region = fPartitioner.getPartition(i);
        assertTypedRegion(region, offset, end, type);
    }
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion)

Example 65 with ITypedRegion

use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.

the class JavascriptValidationStrategy method computePartitioning.

protected ITypedRegion[] computePartitioning(int drOffset, int drLength) {
    ITypedRegion[] tr = new ITypedRegion[0];
    IDocument doc = getDocument();
    if (doc != null) {
        int docLength = doc.getLength();
        if (drOffset > docLength) {
            drOffset = docLength;
            drLength = 0;
        } else if (drOffset + drLength > docLength) {
            drLength = docLength - drOffset;
        }
        try {
            // dirty region may span multiple partitions
            tr = TextUtilities.computePartitioning(doc, getDocumentPartitioning(), drOffset, drLength, true);
        } catch (BadLocationException e) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            String info = "dr: [" + drOffset + ":" + drLength + "] doc: [" + docLength + "] ";
            IStatus status = new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.OK, info, e);
            JavaScriptPlugin.getDefault().getLog().log(status);
            tr = new ITypedRegion[0];
        }
    }
    return tr;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITypedRegion (org.eclipse.jface.text.ITypedRegion)129 BadLocationException (org.eclipse.jface.text.BadLocationException)59 IRegion (org.eclipse.jface.text.IRegion)42 IDocument (org.eclipse.jface.text.IDocument)21 Region (org.eclipse.jface.text.Region)19 ArrayList (java.util.ArrayList)17 TypedRegion (org.eclipse.jface.text.TypedRegion)16 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)14 Position (org.eclipse.jface.text.Position)14 TypedPosition (org.eclipse.jface.text.TypedPosition)13 List (java.util.List)11 StyleRange (org.eclipse.swt.custom.StyleRange)7 Test (org.junit.Test)7 Iterator (java.util.Iterator)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 ITextSelection (org.eclipse.jface.text.ITextSelection)5 BadPartitioningException (org.eclipse.jface.text.BadPartitioningException)4 Document (org.eclipse.jface.text.Document)4 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)4 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)4