use of org.eclipse.xtext.util.TextRegion in project xtext-core by eclipse.
the class EObjectAtOffsetTest method testGetCrossReferenceNode.
@Test
public void testGetCrossReferenceNode() throws Exception {
String firstPart = "foo Foo1=X.Y foo Foo2=X.Y zonk bar Bar1 Foo1=X.Y";
String modelAsString = firstPart + ",Foo2=X.Y";
XtextResource resource = getResourceFromString(modelAsString);
INode node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length(), 0));
assertEquals(firstPart.length() - 8, node.getOffset());
assertEquals(8, node.getLength());
assertNull(eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length(), 1)));
node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length() + 1, 0));
assertEquals(firstPart.length() + 1, node.getOffset());
assertEquals(8, node.getLength());
node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length() + 1, 5));
assertEquals(firstPart.length() + 1, node.getOffset());
assertEquals(8, node.getLength());
node = eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length() + 1, 8));
assertEquals(firstPart.length() + 1, node.getOffset());
assertEquals(8, node.getLength());
assertNull(eObjectAtOffsetHelper.getCrossReferenceNode(resource, new TextRegion(firstPart.length() + 1, 9)));
}
use of org.eclipse.xtext.util.TextRegion in project xtext-core by eclipse.
the class TraceRegionToStringTest method twoFrame2.
@Test
public void twoFrame2() {
final TraceRegionToStringTester tester = new TraceRegionToStringTester();
StringConcatenation _builder = new StringConcatenation();
_builder.append("foo bar");
_builder.newLine();
tester.setLocalText(_builder.toString());
TextRegion _textRegion = new TextRegion(2, 4);
tester.setLocalFrame(_textRegion);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("baz buz");
_builder_1.newLine();
tester.setRemote1(_builder_1.toString());
SourceRelativeURI _uri1 = tester.getUri1();
TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 5, _uri1);
TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> {
TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(1, 5);
it.addChild(2, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1)));
TraceRegionToStringTester.Location _location_2 = new TraceRegionToStringTester.Location(1, 5);
it.addChild(5, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_2)));
};
TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function);
tester.setTrace(_doubleArrow);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("---- local1 ---- | ---- remote1 ----");
_builder_2.newLine();
_builder_2.append("[1[o]1] b[2[a]2] | b[1,2[az bu]2,1]z");
_builder_2.newLine();
_builder_2.append("------------------------------------");
_builder_2.newLine();
_builder_2.append("1: D 2-1 Region -> Location[1,5]");
_builder_2.newLine();
_builder_2.append("2: D 5-1 Region -> Location[1,5]");
_builder_2.newLine();
this.operator_tripleEquals(tester, _builder_2);
}
use of org.eclipse.xtext.util.TextRegion in project xtext-core by eclipse.
the class TraceRegionToStringTest method twoFrame1.
@Test
public void twoFrame1() {
final TraceRegionToStringTester tester = new TraceRegionToStringTester();
StringConcatenation _builder = new StringConcatenation();
_builder.append("foo bar");
_builder.newLine();
tester.setLocalText(_builder.toString());
TextRegion _textRegion = new TextRegion(1, 5);
tester.setLocalFrame(_textRegion);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("baz buz");
_builder_1.newLine();
tester.setRemote1(_builder_1.toString());
SourceRelativeURI _uri1 = tester.getUri1();
TraceRegionToStringTester.Location _location = new TraceRegionToStringTester.Location(1, 5, _uri1);
TraceRegionToStringTester.Region _region = new TraceRegionToStringTester.Region(0, 7, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location)));
final Procedure1<TraceRegionToStringTester.Region> _function = (TraceRegionToStringTester.Region it) -> {
TraceRegionToStringTester.Location _location_1 = new TraceRegionToStringTester.Location(1, 5);
it.addChild(2, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_1)));
TraceRegionToStringTester.Location _location_2 = new TraceRegionToStringTester.Location(1, 5);
it.addChild(5, 1, Collections.<ILocationData>unmodifiableList(CollectionLiterals.<ILocationData>newArrayList(_location_2)));
};
TraceRegionToStringTester.Region _doubleArrow = ObjectExtensions.<TraceRegionToStringTester.Region>operator_doubleArrow(_region, _function);
tester.setTrace(_doubleArrow);
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("---- local1 ----- | ---- remote1 ----");
_builder_2.newLine();
_builder_2.append("o[1[o]1] b[2[a]2] | b[1,2[az bu]2,1]z");
_builder_2.newLine();
_builder_2.append("-------------------------------------");
_builder_2.newLine();
_builder_2.append("1: D 2-1 Region -> Location[1,5]");
_builder_2.newLine();
_builder_2.append("2: D 5-1 Region -> Location[1,5]");
_builder_2.newLine();
this.operator_tripleEquals(tester, _builder_2);
}
use of org.eclipse.xtext.util.TextRegion in project xtext-core by eclipse.
the class XtextResource method update.
public void update(int offset, int replacedTextLength, String newText) {
if (!isLoaded()) {
throw new IllegalStateException("You can't update an unloaded resource.");
}
try {
isUpdating = true;
IParseResult oldParseResult = parseResult;
ReplaceRegion replaceRegion = new ReplaceRegion(new TextRegion(offset, replacedTextLength), newText);
IParseResult newParseResult;
ParserRule oldEntryPoint = NodeModelUtils.getEntryParserRule(oldParseResult.getRootNode());
if (entryPoint == null || entryPoint == oldEntryPoint) {
newParseResult = parser.reparse(oldParseResult, replaceRegion);
} else {
StringBuilder builder = new StringBuilder(oldParseResult.getRootNode().getText());
replaceRegion.applyTo(builder);
newParseResult = parser.parse(entryPoint, new StringReader(builder.toString()));
}
updateInternalState(oldParseResult, newParseResult);
} finally {
isUpdating = false;
}
}
use of org.eclipse.xtext.util.TextRegion in project xtext-core by eclipse.
the class FormattableDocumentTest method shouldFormat.
@Test
public void shouldFormat() {
final Procedure1<GenericFormatterTestRequest> _function = (GenericFormatterTestRequest it) -> {
Collection<ITextRegion> _regions = it.getRequest().getRegions();
TextRegion _textRegion = new TextRegion(0, 6);
_regions.add(_textRegion);
StringConcatenation _builder = new StringConcatenation();
_builder.append("idlist");
it.setToBeFormatted(_builder);
it.setFormatter(new GenericFormatter() {
@Override
protected void format(final EObject model, final ITextRegionExtensions regionAccess, final IFormattableDocument document) {
throw new IllegalStateException("this method should never be called");
}
@Override
public boolean shouldFormat(final Object obj, final IFormattableDocument document) {
return false;
}
});
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("idlist");
it.setExpectation(_builder_1);
};
this._genericFormatterTester.assertFormatted(_function);
}
Aggregations