diff --git a/org.eclipse.xtext.xbase.tests/.classpath b/org.eclipse.xtext.xbase.tests/.classpath
index c59580bb78..2c3019a9a7 100644
--- a/org.eclipse.xtext.xbase.tests/.classpath
+++ b/org.eclipse.xtext.xbase.tests/.classpath
@@ -7,13 +7,6 @@
-
-
-
-
-
-
-
diff --git a/org.eclipse.xtext.xbase.tests/build.properties b/org.eclipse.xtext.xbase.tests/build.properties
index 3d4be68bf1..c387a04a8f 100644
--- a/org.eclipse.xtext.xbase.tests/build.properties
+++ b/org.eclipse.xtext.xbase.tests/build.properties
@@ -1,5 +1,4 @@
source.. = src/,\
- xtend-gen/,\
longrunning/src/,\
suites/,\
smoke-suites/
diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java
new file mode 100644
index 0000000000..dbb69b0f1d
--- /dev/null
+++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.eclipse.xtext.xbase.tests.formatting;
+
+import org.eclipse.xtext.testing.InjectWith;
+import org.eclipse.xtext.testing.XtextRunner;
+import org.eclipse.xtext.testing.formatter.FormatterTestRequest;
+import org.eclipse.xtext.util.Strings;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.google.inject.Inject;
+
+@RunWith(XtextRunner.class)
+@InjectWith(XbaseFormatterTestInjectorProvider.class)
+public class XbaseCommentFormatterTest {
+ @Inject
+ private XbaseFormatterTester xbaseFormatterTester;
+
+ @Test
+ public void commentInIfExpression() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String model =
+ "if (true)\n" +
+ " println(\"foo\")\n" +
+ "else // if (true)\n" +
+ " println(\"bar\")\n" +
+ "println(\"end\")\n";
+ it.setToBeFormatted(Strings.toPlatformLineSeparator(model));
+ });
+ }
+
+ @Test
+ public void commentAfterForExpression1() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String model =
+ "for (f : #[])\n" +
+ " if (1 < 2) {\n" +
+ " }\n" +
+ "\n" +
+ "// foo\n" +
+ "var lastOffset = \"\"\n";
+ it.setToBeFormatted(Strings.toPlatformLineSeparator(model));
+ });
+ }
+
+ @Test
+ public void commentAfterForExpression3() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String model = "val ll = #[].map(e|e.toString) // error here\n";
+ it.setToBeFormatted(Strings.toPlatformLineSeparator(model));
+ });
+ }
+}
diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.xtend b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.xtend
deleted file mode 100644
index ee3b6a183c..0000000000
--- a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseCommentFormatterTest.xtend
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.eclipse.xtext.xbase.tests.formatting
-
-import com.google.inject.Inject
-import org.eclipse.xtext.testing.InjectWith
-import org.eclipse.xtext.testing.XtextRunner
-import org.junit.Test
-import org.junit.runner.RunWith
-
-@RunWith(typeof(XtextRunner))
-@InjectWith(typeof(XbaseFormatterTestInjectorProvider))
-class XbaseCommentFormatterTest {
-
- @Inject extension XbaseFormatterTester
-
- @Test def commentInIfExpression() {
- assertFormattedExpression [
- toBeFormatted = '''
- if (true)
- println("foo")
- else // if (true)
- println("bar")
- println("end")
- '''
- ]
- }
-
- @Test def commentAfterForExpression1() {
- assertFormattedExpression [
- toBeFormatted = '''
- for (f : #[])
- if (1 < 2) {
- }
-
- // foo
- var lastOffset = ""
- '''
- ]
- }
-
- @Test def commentAfterForExpression3() {
- assertFormattedExpression [
- toBeFormatted = '''
- val ll = #[].map(e|e.toString) // error here
- '''
- ]
- }
-}
diff --git a/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java
new file mode 100644
index 0000000000..89027479d5
--- /dev/null
+++ b/org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/formatting/XbaseFormatterTest.java
@@ -0,0 +1,1867 @@
+/**
+ * Copyright (c) 2012, 2021 itemis AG (http://www.itemis.eu) and others.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.eclipse.xtext.xbase.tests.formatting;
+
+import org.eclipse.xtext.preferences.MapBasedPreferenceValues;
+import org.eclipse.xtext.testing.InjectWith;
+import org.eclipse.xtext.testing.XtextRunner;
+import org.eclipse.xtext.testing.formatter.FormatterTestRequest;
+import org.eclipse.xtext.util.Strings;
+import org.eclipse.xtext.xbase.formatting2.XbaseFormatterPreferenceKeys;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.google.inject.Inject;
+
+@RunWith(XtextRunner.class)
+@InjectWith(XbaseFormatterTestInjectorProvider.class)
+public class XbaseFormatterTest {
+ @Inject
+ private XbaseFormatterTester xbaseFormatterTester;
+
+ @Test
+ public void formatGenerics() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String toBeFormatted =
+ "val x = >newArrayList()\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatBlockExpression() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String expectation =
+ "val x = newArrayList(\"A\", \"b\");\n" +
+ "val y = 'foo';\n" +
+ "x.join\n";
+ it.setExpectation(expectation);
+ String toBeFormatted =
+ "val x = newArrayList(\"A\", \"b\") ; val y = 'foo' ; x.join\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatBlockExpressionPreserveNewLines() {
+ xbaseFormatterTester.assertFormatted((FormatterTestRequest it) -> {
+ String string = "{\n" +
+ "\n" +
+ " val x = newArrayList(\"A\", \"b\");\n" +
+ "\n" +
+ " val y = 'foo'\n" +
+ "\n" +
+ " x.join\n" +
+ "\n" +
+ "}\n";
+ String expectation = string.toString().trim();
+ it.setExpectation(Strings.toPlatformLineSeparator(expectation));
+ String toBeFormatted =
+ " { \n" +
+ "\n" +
+ "\n" +
+ "val x = newArrayList(\"A\", \"b\") ;\n" +
+ "\n" +
+ "\n" +
+ "val y = 'foo'\n" +
+ "\n" +
+ "\n" +
+ " x.join\n" +
+ "\n" +
+ "\n" +
+ " }\n";
+ it.setToBeFormatted(Strings.toPlatformLineSeparator(toBeFormatted));
+ });
+ }
+
+ @Test
+ public void formatClosures() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String toBeFormatted =
+ "val x = newArrayList(\"A\", \"b\")\n" +
+ "val y = x.filter[toUpperCase == it]\n" +
+ "y.join\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatClosuresParenthesis() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String toBeFormatted =
+ "val x = newArrayList(\"A\", \"b\")\n" +
+ "val y = x.filter(toUpperCase == it)\n" +
+ "y.join\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatClosuresParenthesis2() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String expectation =
+ "val x = newArrayList(\"A\", \"b\")\n" +
+ "val y = x.filter(foo|foo.toUpperCase == foo)\n" +
+ "y.join\n";
+ it.setToBeFormatted(expectation);
+ });
+ }
+
+ @Test
+ public void formatClosuresSemicolon() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String expectation =
+ "newArrayList(\"A\", \"b\").filter[val b = it; b.toUpperCase == b]\n";
+ it.setExpectation(expectation);
+ String toBeFormatted =
+ "newArrayList(\"A\", \"b\").filter[ val b = it ; b.toUpperCase == b ]\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatClosuresEmpty() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String expectation =
+ "val x = newArrayList(\"A\", \"b\")\n" +
+ "val y = x.filter[]\n" +
+ "y.join\n";
+ it.setExpectation(expectation);
+ String toBeFormatted =
+ "val x = newArrayList(\"A\", \"b\") val y = x.filter[ ] y.join\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatClosuresParam() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String toBeFormatted =
+ "val x = newArrayList(\"A\", \"b\")\n" +
+ "val y = x.filter[z|z.toUpperCase == z]\n" +
+ "y.join\n";
+ it.setToBeFormatted(toBeFormatted);
+ });
+ }
+
+ @Test
+ public void formatClosuresEmptyParam() {
+ xbaseFormatterTester.assertFormattedExpression((FormatterTestRequest it) -> {
+ String toBeFormatted =
+ "val Iterable