use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testSingleSemanticToken.
@Test
public void testSingleSemanticToken() throws Exception {
String model = "1 foo\n";
ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
ITextRegionExtensions ext = access.getExtensions();
EObject root = access.regionForRootEObject().getSemanticElement();
ISemanticRegion foo = ext.allRegionsFor(root).feature(RegionaccesstestlanguagePackage.Literals.SIMPLE__NAME);
it.replace(foo, "baaar");
});
String expectation = "0 0 H\n" + " B Simple'foo' Root\n" + "0 1 S \"1\" Simple:'1'\n" + "1 1 H \" \" Whitespace:TerminalRule'WS'\n" + "2 5 1 S \"baaar\" Simple:name=ID\n" + " E Simple'foo' Root\n" + "7 0 H\n" + "------------ diff 1 ------------\n" + "2 3 S \"foo\" Simple:name=ID\n";
regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testInsertBeforeComment.
@Test
public void testInsertBeforeComment() throws Exception {
String model = "8\n" + "/**/\n" + "a b\n";
ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
ITextRegionExtensions ext = access.getExtensions();
ValueList rootObj = (ValueList) access.regionForRootEObject().getSemanticElement();
ISemanticRegion a = ext.regionFor(rootObj).keyword("8").getNextSemanticRegion();
ISemanticRegion b = a.getNextSemanticRegion();
it.replace(a.getPreviousHiddenRegion(), a.getPreviousHiddenRegion(), b.getPreviousHiddenRegion(), b.getNextHiddenRegion());
});
String expectation = " 0 0 H\n" + " B ValueList'[a, b]' Root\n" + " 0 1 S \"8\" Root:'8'\n" + " 1 1 1 H \"\\n" + "\" Whitespace:TerminalRule'WS'\n" + " 2 1 1 S \"b\" ValueList:name+=ID\n" + " 3 1 H \"/**/\" Comment:TerminalRule'ML_COMMENT' Association:PREVIOUS\n" + " 5 \"\\n" + "\" Whitespace:TerminalRule'WS'\n" + " 8 1 S \"a\" ValueList:name+=ID\n" + " 9 1 H \" \" Whitespace:TerminalRule'WS'\n" + "10 1 S \"b\" ValueList:name+=ID\n" + " E ValueList'[a, b]' Root\n" + "11 0 H\n" + "------------ diff 1 ------------\n" + " 1 H \"\\n" + "\" Whitespace:TerminalRule'WS'\n" + " \"/**/\" Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + " 6 \"\\n" + "\" Whitespace:TerminalRule'WS'\n";
regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class SemanticRegionFinderTest method regionForKeyword.
@Test
public void regionForKeyword() throws Exception {
Mixed mixed = parseAs("6 (foo)", Mixed.class);
ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
ISemanticRegion actual = finder.keyword(grammarAccess.getMixedAccess().getLeftParenthesisKeyword_0());
List<ISemanticRegion> actuals = finder.keywords(grammarAccess.getMixedAccess().getLeftParenthesisKeyword_0());
assertEquals("(", actual, actuals);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class SemanticRegionFinderTest method regionForAssignment.
@Test
public void regionForAssignment() throws Exception {
Mixed mixed = parseAs("6 (foo)", Mixed.class);
ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
ISemanticRegion actual = finder.assignment(grammarAccess.getMixedAccess().getNameAssignment_2_2_0());
List<ISemanticRegion> actuals = finder.assignments(grammarAccess.getMixedAccess().getNameAssignment_2_2_0());
assertEquals("foo", actual, actuals);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class SemanticRegionFinderTest method regionForRuleCallToAssignedTerminal.
@Test
public void regionForRuleCallToAssignedTerminal() throws Exception {
Mixed mixed = parseAs("6 (foo)", Mixed.class);
ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
ISemanticRegion actual = finder.ruleCallTo(grammarAccess.getIDRule());
ISemanticRegion actuals = finder.ruleCallTo(grammarAccess.getIDRule());
Assert.assertEquals("foo", actual, actuals);
}
Aggregations