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;
}
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);
}
}
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;
}
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");
}
}
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);
}
}
Aggregations