+import java.util.List;
+
aspect SwitchPatternAspect {
Object around(Object o) : execution(* doSomethingWithObject(*)) && args(o) {
System.out.println(switch (o) {
final class B implements S {}
record C(int i) implements S {} // Implicitly final
-public class Application {
+class Application {
public static void main(String[] args) {
doSomethingWithObject(null);
doSomethingWithObject(123);
doSomethingWithShape(new Circle(5));
doSomethingWithShape(new Circle(6));
- doSomethingWithSealedClass(new A()));
- doSomethingWithSealedClass(new B()));
- doSomethingWithSealedClass(new C(5)));
+ doSomethingWithSealedClass(new A());
+ doSomethingWithSealedClass(new B());
+ doSomethingWithSealedClass(new C(5));
}
- public Object doSomethingWithObject(Object o) { return o; }
- public void doSomethingWithSealedClass(S s) {}
- public void doSomethingWithShape(Shape s) {}
+ public static Object doSomethingWithObject(Object o) { return o; }
+ public static void doSomethingWithSealedClass(S s) {}
+ public static void doSomethingWithShape(Shape s) {}
}
public class Java17PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava17Only {
public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
- // TODO: JDT Core does not support detecting type domination detection in the development version yet -> activate when available
- System.out.println("TODO: JDT Core does not support detecting type domination detection in the development version yet -> activate when available");
-// runTest("switch pattern matching error");
+ runTest("switch pattern matching error");
}
public void testSwitchPatternMatchingJava() {
- // TODO: JDT Core does not support sealed class coverage in the development version yet -> activate when available
- System.out.println("TODO: JDT Core does not support sealed class coverage in the development version yet -> activate when available");
-// runTest("switch pattern matching java");
-// checkVersion("SwitchPatternOK", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ runTest("switch pattern matching java");
+ checkVersion("SwitchPatternOK", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
}
public void testSwitchPatternMatchingAspect() {
- // TODO: JDT Core does not support sealed class coverage in the development version yet -> activate when available
- System.out.println("TODO: JDT Core does not support sealed class coverage in the development version yet -> activate when available");
-// runTest("switch pattern matching aspect");
-// checkVersion("SwitchPatternAspect", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
-// checkVersion("Application", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
-// checkVersion("Shape", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
-// checkVersion("S", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ runTest("switch pattern matching aspect");
+ checkVersion("SwitchPatternAspect", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Application", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("Shape", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
+ checkVersion("S", Constants.MAJOR_17, Constants.PREVIEW_MINOR_VERSION);
}
public static Test suite() {