use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-xtend by eclipse.
the class XtendFormatter method _format.
protected void _format(final XtendFile xtendFile, @Extension final IFormattableDocument format) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.<XtendFile>prepend(xtendFile, _function);
final ISemanticRegion pkg = this.textRegionExtensions.regionFor(xtendFile).feature(XtendPackage.Literals.XTEND_FILE__PACKAGE);
if ((pkg != null)) {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.prepend(pkg, _function_1);
final ISemanticRegion pkgSemicolon = pkg.immediatelyFollowing().keyword(";");
if ((pkgSemicolon != null)) {
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.append(pkg, _function_2);
format.append(pkgSemicolon, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
} else {
format.append(pkg, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
}
}
XImportSection _importSection = xtendFile.getImportSection();
if (_importSection != null) {
format.<XImportSection>format(_importSection);
}
EList<XtendTypeDeclaration> _xtendTypes = xtendFile.getXtendTypes();
for (final XtendTypeDeclaration clazz : _xtendTypes) {
{
format.<XtendTypeDeclaration>format(clazz);
XtendTypeDeclaration _last = IterableExtensions.<XtendTypeDeclaration>last(xtendFile.getXtendTypes());
boolean _notEquals = (!Objects.equal(clazz, _last));
if (_notEquals) {
format.<XtendTypeDeclaration>append(clazz, XtendFormatterPreferenceKeys.blankLinesBetweenClasses);
}
}
}
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.newLine();
};
format.<XtendFile>append(xtendFile, _function_3);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testDeleteOne.
@Test
public void testDeleteOne() throws Exception {
String model = "4/*1*/prefix/*2*/foo\n";
ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
ITextRegionExtensions ext = access.getExtensions();
PrefixedUnassigned rootObj = (PrefixedUnassigned) access.regionForRootEObject().getSemanticElement();
ISemanticRegion prefix = ext.regionFor(rootObj.getDelegate()).keyword("prefix");
it.remove(prefix);
});
String expectation = " 0 0 H\n" + " B PrefixedUnassigned Root\n" + " 0 1 S \"4\" PrefixedUnassigned:'4'\n" + " 1 1 H \"/*1*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " 10 \"/*2*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " B Delegate'foo' PrefixedUnassigned:delegate=PrefixedDelegate path:PrefixedUnassigned/delegate\n" + "11 3 S \"foo\" Delegate:name=ID\n" + " E Delegate'foo' PrefixedUnassigned:delegate=PrefixedDelegate path:PrefixedUnassigned/delegate\n" + " E PrefixedUnassigned Root\n" + "14 0 H\n" + "------------ diff 1 ------------\n" + " 1 5 H \"/*1*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " 6 6 S \"prefix\" PrefixedDelegate:'prefix'\n" + "12 5 H \"/*2*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n";
regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testInsertReplaceReplace.
@Test
public void testInsertReplaceReplace() throws Exception {
String model = "8 a\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();
it.replace(a, "b");
it.replace(a, "c");
});
String expectation = "0 0 H\n" + " B ValueList'[a]' Root\n" + "0 1 S \"8\" Root:'8'\n" + "1 1 H \" \" Whitespace:TerminalRule'WS'\n" + "2 1 1 S \"c\" ValueList:name+=ID\n" + " E ValueList'[a]' Root\n" + "3 0 H\n" + "------------ diff 1 ------------\n" + "2 1 S \"a\" ValueList: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 testDeleteTwo.
@Test
public void testDeleteTwo() throws Exception {
String model = "4/*1*/prefix/*2*/foo/*3*/\n";
ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
ITextRegionExtensions ext = access.getExtensions();
PrefixedUnassigned rootObj = (PrefixedUnassigned) access.regionForRootEObject().getSemanticElement();
ISemanticRegion prefix = ext.regionFor(rootObj.getDelegate()).keyword("prefix");
ISemanticRegion foo = ext.regionFor(rootObj.getDelegate()).feature(RegionaccesstestlanguagePackage.Literals.DELEGATE__NAME);
it.remove(prefix.getPreviousHiddenRegion(), foo.getNextHiddenRegion());
});
String expectation = " 0 0 H\n" + " B PrefixedUnassigned Root\n" + " 0 1 S \"4\" PrefixedUnassigned:'4'\n" + " E PrefixedUnassigned Root\n" + " 1 1 H \"/*1*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " 10 \"/*3*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "------------ diff 1 ------------\n" + " 1 5 H \"/*1*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + " 6 6 S \"prefix\" PrefixedDelegate:'prefix'\n" + "12 5 H \"/*2*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "17 3 S \"foo\" Delegate:name=ID\n" + "20 5 H \"/*3*/\" Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n";
regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class RegionAccessDiffTest method testInsertInsertReplace.
@Test
public void testInsertInsertReplace() throws Exception {
String model = "8 a\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();
it.replace(a.getNextHiddenRegion(), a.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
it.replace(a.getNextHiddenRegion(), a.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
it.replace(a, "new");
});
String expectation = " 0 0 H\n" + " B ValueList'[a]' Root\n" + " 0 1 S \"8\" Root:'8'\n" + " 1 1 H \" \" Whitespace:TerminalRule'WS'\n" + " 2 3 2 S \"new\" ValueList:name+=ID\n" + " 5 0 2 H\n" + " 5 3 2 S \"new\" ValueList:name+=ID\n" + " 8 0 2 H\n" + " 8 3 2 S \"new\" ValueList:name+=ID\n" + " E ValueList'[a]' Root\n" + "11 0 2 H\n" + "------------ diff 1 ------------\n" + " 2 1 S \"a\" ValueList:name+=ID\n" + "------------ diff 2 ------------\n" + " 2 1 S \"a\" ValueList:name+=ID\n" + " 3 0 H\n";
regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Aggregations