use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class XtendExpressionUtil method getRichStringPartTextRegion.
protected ITextRegion getRichStringPartTextRegion(EObject element) {
if (element instanceof RichStringLiteral) {
return locationInFileProvider.getSignificantTextRegion(element);
}
ICompositeNode elementNode = NodeModelUtils.getNode(element);
ITextRegion totalTextRegion = elementNode.getTotalTextRegion();
int offset = totalTextRegion.getOffset() - 1;
int length = totalTextRegion.getLength() + 2;
ILeafNode nextNode = NodeModelUtils.findLeafNodeAtOffset(elementNode.getRootNode(), elementNode.getEndOffset());
while (nextNode != null && nextNode.isHidden()) {
length += nextNode.getLength();
INode nextSibling = nextNode.getNextSibling();
if (nextSibling instanceof ILeafNode) {
nextNode = (ILeafNode) nextSibling;
} else {
nextNode = null;
}
}
return new TextRegion(offset, length);
}
use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method getExpressionsRegion.
protected ITextRegion getExpressionsRegion() {
ITextRegion firstRegion = expressionUtil.getTextRegion(firstExpression);
ITextRegion lastRegion = expressionUtil.getTextRegion(lastExpression);
ITextRegion expressionRegion = new TextRegion(firstRegion.getOffset(), lastRegion.getOffset() + lastRegion.getLength() - firstRegion.getOffset());
return expressionRegion;
}
use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class AbstractXtendFormatterTest method assertFormatted.
public void assertFormatted(final Procedure1<? super MapBasedPreferenceValues> cfg, final CharSequence expectation, final CharSequence toBeFormatted, final String prefix, final String postfix, final boolean allowErrors) {
final Procedure1<FormatterTestRequest> _function = (FormatterTestRequest it) -> {
final Procedure1<MapBasedPreferenceValues> _function_1 = (MapBasedPreferenceValues it_1) -> {
it_1.<Integer>put(FormatterPreferenceKeys.maxLineWidth, Integer.valueOf(80));
it_1.<Boolean>put(XtendFormatterPreferenceKeys.keepOneLineMethods, Boolean.valueOf(false));
if (cfg != null) {
cfg.apply(it_1);
}
};
it.preferences(_function_1);
it.setExpectation(((prefix + expectation) + postfix));
it.setToBeFormatted(((prefix + toBeFormatted) + postfix));
Collection<ITextRegion> _regions = it.getRequest().getRegions();
int _length = prefix.length();
int _length_1 = toBeFormatted.length();
TextRegion _textRegion = new TextRegion(_length, _length_1);
_regions.add(_textRegion);
it.setAllowSyntaxErrors(allowErrors);
};
this.tester.assertFormatted(_function);
}
use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class FlexTokenRegionProviderTest method testTokenMerge_1.
@Test
public void testTokenMerge_1() throws Exception {
String model = " ab ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 0));
assertEquals(1, tokenRegion.getOffset());
assertEquals(2, tokenRegion.getLength());
}
use of org.eclipse.xtext.util.TextRegion in project xtext-xtend by eclipse.
the class FlexTokenRegionProviderTest method testTokenSplit_1.
@Test
public void testTokenSplit_1() throws Exception {
String model = " axb ";
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(2, 1));
assertEquals(1, tokenRegion.getOffset());
assertEquals(3, tokenRegion.getLength());
}
Aggregations