use of org.eclipse.jface.text.ITypedRegion in project xtext-eclipse by eclipse.
the class DocumentUtil method searchBackwardsInSamePartition.
/**
* searches backwards for the given string within the same partition type
* @return the region of the match or <code>null</code> if no match were found
* @since 2.4
*/
public IRegion searchBackwardsInSamePartition(String toFind, String documentText, IDocument document, int endOffset) throws BadLocationException {
if (endOffset < 0) {
return null;
}
int length = toFind.length();
String text = preProcessSearchString(documentText);
ITypedRegion partition = document.getPartition(endOffset);
int indexOf = text.lastIndexOf(toFind, endOffset - length);
while (indexOf >= 0) {
ITypedRegion partition2 = document.getPartition(indexOf);
if (partition2.getType().equals(partition.getType())) {
return new Region(indexOf, length);
}
indexOf = text.lastIndexOf(toFind, partition2.getOffset() - length);
}
String trimmed = toFind.trim();
if (trimmed.length() > 0 && trimmed.length() != length) {
return searchBackwardsInSamePartition(trimmed, documentText, document, endOffset);
}
return null;
}
use of org.eclipse.jface.text.ITypedRegion in project xtext-eclipse by eclipse.
the class XtextAutoEditStrategy method getCurrentRuleUptoOffset.
protected String getCurrentRuleUptoOffset(int offset, IDocument doc) throws BadLocationException {
ITypedRegion currentPartition = doc.getPartition(offset);
String partitionType = currentPartition.getType();
String currentSegment = doc.get(currentPartition.getOffset(), offset - currentPartition.getOffset());
StringBuilder ruleAsString = new StringBuilder();
while (currentSegment.indexOf(';') == -1) {
ruleAsString.insert(0, currentSegment);
do {
if (currentPartition.getOffset() == 0) {
return ruleAsString.toString();
}
currentPartition = doc.getPartition(currentPartition.getOffset() - 1);
currentSegment = doc.get(currentPartition.getOffset(), currentPartition.getLength());
} while (!partitionType.equals(currentPartition.getType()));
}
ruleAsString.insert(0, currentSegment.substring(currentSegment.lastIndexOf(';') + 1));
return ruleAsString.toString();
}
use of org.eclipse.jface.text.ITypedRegion in project tmdm-studio-se by Talend.
the class NonRuleBasedDamagerRepairer method getDamageRegion.
/**
* @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
*/
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
int start = Math.max(partition.getOffset(), info.getOffset());
int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
// optimize the case of the same line
end = info.getOffset() + info.getLength();
} else
end = endOfLineOf(end);
end = Math.min(partition.getOffset() + partition.getLength(), end);
return new Region(start, end - start);
} catch (BadLocationException x) {
}
}
return partition;
}
use of org.eclipse.jface.text.ITypedRegion in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method getPartition.
public ITypedRegion getPartition(int offset) {
try {
Position[] category = document.getPositions(positionCategory);
if (category == null || category.length == 0) {
// $NON-NLS-1$
return new TypedRegion(0, document.getLength(), "__dftl_partition_content_type");
}
int index = document.computeIndexInCategory(positionCategory, offset);
if (index < category.length) {
TypedPosition next = (TypedPosition) category[index];
if (offset == next.offset) {
return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
}
if (index == 0) {
// $NON-NLS-1$
return new TypedRegion(0, next.offset, "__dftl_partition_content_type");
}
TypedPosition previous = (TypedPosition) category[index - 1];
if (previous.includes(offset)) {
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
}
int endOffset = previous.getOffset() + previous.getLength();
// $NON-NLS-1$
return new TypedRegion(endOffset, next.getOffset() - endOffset, "__dftl_partition_content_type");
}
TypedPosition previous = (TypedPosition) category[category.length - 1];
if (previous.includes(offset)) {
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
}
int endOffset = previous.getOffset() + previous.getLength();
// $NON-NLS-1$
return new TypedRegion(endOffset, document.getLength() - endOffset, "__dftl_partition_content_type");
} catch (BadPositionCategoryException _ex) {
} catch (BadLocationException _ex) {
}
// $NON-NLS-1$
return new TypedRegion(0, document.getLength(), "__dftl_partition_content_type");
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class XMLFindOccurencesHandler method getProcessorForCurrentSelection.
/**
* Get the appropriate find occurrences processor
*
* @param document -
* assumes not null
* @param textSelection
* @return FindOccurrencesProcessor
*/
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;
}
Aggregations