Search in sources :

Example 51 with ITypedRegion

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

the class DirtyRegionProcessor 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 + "] ";
            Logger.logException(info, e);
            tr = new ITypedRegion[0];
        }
    }
    return tr;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 52 with ITypedRegion

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

the class DocumentRegionProcessor method process.

/**
 * @param dirtyRegion
 */
protected void process(DirtyRegion dirtyRegion) {
    if (!isInstalled() || isInRewriteSession() || dirtyRegion == null || getDocument() == null)
        return;
    super.process(dirtyRegion);
    ITypedRegion[] partitions = computePartitioning(dirtyRegion);
    // call the validator strategy once for each effected partition
    DirtyRegion dirty = null;
    for (int i = 0; i < partitions.length; i++) {
        dirty = createDirtyRegion(partitions[i], DirtyRegion.INSERT);
        // [source]validator (extension) for this partition
        if (getValidatorStrategy() != null) {
            getValidatorStrategy().reconcile(partitions[i], dirty);
        }
    }
    /* if there is a folding strategy then reconcile it for the
		 * entire dirty region.
		 * NOTE: the folding strategy does not care about the sub regions.
		 */
    if (getFoldingStrategy() != null) {
        getFoldingStrategy().reconcile(dirtyRegion, null);
    }
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion)

Example 53 with ITypedRegion

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

the class HTMLFindOccurrencesHandler method getProcessorForCurrentSelection.

/**
 * Get the appropriate find occurrences processor
 *
 * @param document -
 *            assumes not null
 * @param textSelection
 * @return
 */
private FindOccurrencesProcessor getProcessorForCurrentSelection(IDocument document, ITextSelection textSelection) {
    // check if we have an action that's enabled on the current partition
    ITypedRegion tr = getPartition(document, textSelection);
    // $NON-NLS-1$
    String partition = tr != null ? tr.getType() : "";
    Iterator it = getProcessors().iterator();
    FindOccurrencesProcessor processor = null;
    while (it.hasNext()) {
        processor = (FindOccurrencesProcessor) it.next();
        // we just choose the first action that can handle the partition
        if (processor.enabledForParitition(partition))
            return processor;
    }
    List extendedFindOccurrencesProcessors = ExtendedConfigurationBuilder.getInstance().getConfigurations(FindOccurrencesProcessor.class.getName(), partition);
    for (int i = 0; i < extendedFindOccurrencesProcessors.size(); i++) {
        Object o = extendedFindOccurrencesProcessors.get(i);
        if (o instanceof FindOccurrencesProcessor) {
            /*
				 * We just choose the first registered processor that
				 * explicitly says it can handle the partition
				 */
            processor = (FindOccurrencesProcessor) o;
            if (processor.enabledForParitition(partition))
                return processor;
        }
    }
    return null;
}
Also used : Iterator(java.util.Iterator) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) HTMLFindOccurrencesProcessor(org.eclipse.wst.html.ui.internal.search.HTMLFindOccurrencesProcessor) ITypedRegion(org.eclipse.jface.text.ITypedRegion) ArrayList(java.util.ArrayList) List(java.util.List)

Example 54 with ITypedRegion

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

the class JavaHeuristicScanner method getPartition.

/**
 * Returns the partition at <code>position</code>.
 *
 * @param position
 *            the position to get the partition for
 * @return the partition at <code>position</code> or a dummy zero-length
 *         partition if accessing the document fails
 */
private ITypedRegion getPartition(int position) {
    Assert.isTrue(position >= 0);
    Assert.isTrue(position <= fDocument.getLength());
    try {
        return TextUtilities.getPartition(fDocument, fPartitioning, position, false);
    } catch (BadLocationException e) {
        // $NON-NLS-1$
        return new TypedRegion(position, 0, "__no_partition_at_all");
    }
}
Also used : TypedRegion(org.eclipse.jface.text.TypedRegion) ITypedRegion(org.eclipse.jface.text.ITypedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 55 with ITypedRegion

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

the class DefaultPartitionerZeroLengthTest method assertEqualPartition.

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

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