use of org.eclipse.jface.text.ITypedRegion in project xtext-xtend by eclipse.
the class TypedRegionMerger method merge.
public ITypedRegion[] merge(ITypedRegion[] original) {
if (original == null || original.length == 0)
return original;
ITypedRegion[] result = new ITypedRegion[original.length];
String contentType = original[0].getType();
result[0] = original[0];
for (int i = 1; i < original.length; i++) {
ITypedRegion copyMe = original[i];
result[i] = new TypedRegion(copyMe.getOffset(), copyMe.getLength(), contentType);
}
return result;
}
use of org.eclipse.jface.text.ITypedRegion in project xtext-xtend by eclipse.
the class XtendDoubleClickStrategyProvider method getStrategy.
@Override
public ITextDoubleClickStrategy getStrategy(ISourceViewer sourceViewer, String contentType, String documentPartitioning) {
if (TokenTypeToPartitionMapper.RICH_STRING_LITERAL_PARTITION.equals(contentType)) {
return new AbstractPartitionDoubleClickSelector(documentPartitioning) {
@Override
protected IRegion getSelectedRegion(IDocument document, ITypedRegion completePartition) throws BadLocationException {
String content = document.get(completePartition.getOffset(), completePartition.getLength());
// assume � as start character
int trimLeft = 1;
if (content.startsWith("'''")) {
trimLeft = 3;
}
int trimRight = 0;
if (content.endsWith("'''")) {
trimRight = 3;
} else if (content.endsWith("''")) {
trimRight = 2;
} else if (content.endsWith("'") || content.endsWith("\u00AB")) {
trimRight = 1;
}
return new Region(completePartition.getOffset() + trimLeft, completePartition.getLength() - trimLeft - trimRight);
}
};
}
if (TokenTypeToPartitionMapper.JAVA_DOC_PARTITION.equals(contentType)) {
return new AbstractPartitionDoubleClickSelector(documentPartitioning) {
/**
* Allows to select the complete <code>@param</code> instead of just the literal <code>param</code>.
* Copied from org.eclipse.jdt.internal.ui.text.java.JavadocDoubleClickStrategy.
*/
@Override
protected IRegion findExtendedDoubleClickSelection(IDocument document, int position) {
try {
IRegion match = super.findExtendedDoubleClickSelection(document, position);
if (match != null)
return match;
IRegion word = findWord(document, position);
IRegion line = document.getLineInformationOfOffset(position);
if (position == line.getOffset() + line.getLength())
return null;
int start = word.getOffset();
int end = start + word.getLength();
if (start > 0 && document.getChar(start - 1) == '@' && Character.isJavaIdentifierPart(document.getChar(start)) && (start == 1 || Character.isWhitespace(document.getChar(start - 2)) || document.getChar(start - 2) == '{')) {
// double click after @ident
start--;
} else if (end == position && end == start + 1 && end < line.getOffset() + line.getLength() && document.getChar(end) == '@') {
// double click before " @ident"
return findExtendedDoubleClickSelection(document, position + 1);
}
if (start == end)
return null;
return new Region(start, end - start);
} catch (BadLocationException x) {
return null;
}
}
@Override
protected CommonBreakIterator createBreakIterator() {
return new CommonBreakIterator(false) {
class Braces extends Other {
@Override
protected boolean isValid(char ch) {
return ch == '{' || ch == '}';
}
}
class Parentheses extends Other {
@Override
protected boolean isValid(char ch) {
return ch == '(' || ch == ')';
}
}
Braces braces = new Braces();
Parentheses parentheses = new Parentheses();
@Override
protected Run getRun(char ch) {
if (braces.isValid(ch)) {
return braces;
}
if (parentheses.isValid(ch)) {
return parentheses;
}
return super.getRun(ch);
}
};
}
};
}
return super.getStrategy(sourceViewer, contentType, documentPartitioning);
}
use of org.eclipse.jface.text.ITypedRegion in project xtext-xtend by eclipse.
the class PartitionTest method testPartitioningAfterModify_02.
@Test
public void testPartitioningAfterModify_02() throws BadLocationException {
String input = "class SomeType {\n" + " def someOperation() '''\n" + " Dear,\n" + " bla bla foo\n" + " \n" + " Yours sincerely,\n" + " \n" + " Joe Developer\n" + " \n" + " ''' \n" + "}";
document.set(input);
document.replace(input.indexOf("\t\tYours"), 0, "���");
document.replace(input.indexOf("Joe") + 3, /*���*/
0, "\t");
ITypedRegion[] partitions = document.getDocumentPartitioner().computePartitioning(0, input.length() + 4);
assertEquals(4, partitions.length);
ITypedRegion first = partitions[0];
assertEquals(0, first.getOffset());
assertEquals(input.indexOf("'"), first.getLength());
assertEquals(IDocument.DEFAULT_CONTENT_TYPE, first.getType());
ITypedRegion second = partitions[1];
assertEquals(input.indexOf("'"), second.getOffset());
assertEquals(input.indexOf("\t\tYours") + 1, second.getLength() + second.getOffset());
assertEquals(TokenTypeToPartitionMapper.RICH_STRING_LITERAL_PARTITION, second.getType());
ITypedRegion third = partitions[2];
assertEquals(input.indexOf("\t\tYours") + 1, third.getOffset());
assertEquals(input.lastIndexOf("'") + 1 + 4, /*��� + \t*/
third.getLength() + third.getOffset());
assertEquals(TokenTypeToPartitionMapper.RICH_STRING_LITERAL_PARTITION, third.getType());
ITypedRegion forth = partitions[3];
assertEquals(input.lastIndexOf("'") + 1 + 4, /*��� + \t*/
forth.getOffset());
assertEquals(document.getLength(), forth.getLength() + forth.getOffset());
assertEquals(input.length() + 4, /*��� + \t*/
forth.getLength() + forth.getOffset());
assertEquals(IDocument.DEFAULT_CONTENT_TYPE, forth.getType());
}
use of org.eclipse.jface.text.ITypedRegion in project eclipse.platform.text by eclipse.
the class NonRuleBasedDamagerRepairer method getDamageRegion.
@Override
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 eclipse.platform.text by eclipse.
the class PresentationReconciler method createPresentation.
/**
* Constructs a "repair description" for the given damage and returns this
* description as a text presentation. For this, it queries the partitioning
* of the damage region and asks the appropriate presentation repairer for
* each partition to construct the "repair description" for this partition.
*
* @param damage the damage to be repaired
* @param document the document whose presentation must be repaired
* @return the presentation repair description as text presentation or
* <code>null</code> if the partitioning could not be computed
*/
protected TextPresentation createPresentation(IRegion damage, IDocument document) {
try {
if (fRepairers == null || fRepairers.isEmpty()) {
TextPresentation presentation = new TextPresentation(damage, 100);
presentation.setDefaultStyleRange(new StyleRange(damage.getOffset(), damage.getLength(), null, null));
return presentation;
}
TextPresentation presentation = new TextPresentation(damage, 1000);
ITypedRegion[] partitioning = TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), damage.getLength(), false);
for (ITypedRegion r : partitioning) {
IPresentationRepairer repairer = getRepairer(r.getType());
if (repairer != null)
repairer.createPresentation(presentation, r);
}
return presentation;
} catch (BadLocationException x) {
return null;
}
}
Aggregations