]> source.dussan.org Git - aspectj.git/commitdiff
Prepare code, tests and docs for Java 18
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 21 Mar 2022 03:45:00 +0000 (10:45 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 21 Mar 2022 03:51:35 +0000 (10:51 +0700)
- JDT Core dependency in pom.xml
- Constants.java
- LangUtil.java
- AjcTask.java
- messages_aspectj.properties

- XMLBasedAjcTestCaseForJava17Only.java
- XMLBasedAjcTestCaseForJava18*.java
- tests/bugs199
- tests/features199

- JavaVersionCompatibility.md
- README-199.html

- GitHub CI build

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
38 files changed:
.github/workflows/maven.yml
bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java
docs/dist/doc/JavaVersionCompatibility.md
docs/dist/doc/README-198.html
docs/dist/doc/README-199.html [new file with mode: 0644]
org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties
pom.xml
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java [new file with mode: 0644]
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java [new file with mode: 0644]
tests/bugs198/github_115/A.java [deleted file]
tests/bugs198/github_115/B.java [deleted file]
tests/bugs198/github_120/C.java [deleted file]
tests/bugs198/github_120/D.java [deleted file]
tests/bugs198/github_122/E.java [deleted file]
tests/bugs198/github_125/Application.java [deleted file]
tests/bugs199/github_115/A.java [new file with mode: 0644]
tests/bugs199/github_115/B.java [new file with mode: 0644]
tests/bugs199/github_120/C.java [new file with mode: 0644]
tests/bugs199/github_120/D.java [new file with mode: 0644]
tests/bugs199/github_122/E.java [new file with mode: 0644]
tests/bugs199/github_125/Application.java [new file with mode: 0644]
tests/features199/java18/SwitchPatternPreview2Aspect.aj [new file with mode: 0644]
tests/features199/java18/SwitchPatternPreview2Error.java [new file with mode: 0644]
tests/features199/java18/SwitchPatternPreview2OK.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java
tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java
tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java
tests/src/test/java/org/aspectj/systemtest/ajc199/Ajc199TestsJava.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc199/SanityTestsJava18.java [new file with mode: 0644]
tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml
tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml [new file with mode: 0644]
tests/src/test/resources/org/aspectj/systemtest/ajc199/sanity-tests-18.xml [new file with mode: 0644]
util/src/main/java/org/aspectj/util/LangUtil.java

index 9160a83b198cd175d54efacfdd8af5adee24429e..3e2564c77fea746000cdf32e4555f311db8dedc3 100644 (file)
@@ -19,7 +19,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        java: [ 11, 17 ]
+        java: [ 11, 17, 18-ea ]
 
     runs-on: ubuntu-latest
 
index 1ce3682d3e9c18c342b3fdac148ef9ec155bf8ac..3c1c12daf4ae6df509dc870d54c5987c59054e41 100644 (file)
@@ -98,8 +98,10 @@ public interface Constants {
        short MINOR_16 = 0;
        short MAJOR_17 = 61;
        short MINOR_17 = 0;
-//     short MAJOR_18 = 62;
-//     short MINOR_18 = 0;
+       short MAJOR_18 = 62;
+       short MINOR_18 = 0;
+//     short MAJOR_19 = 63;
+//     short MINOR_19 = 0;
 
        int PREVIEW_MINOR_VERSION = 65535;
 
index be557d462b8802ae985fb628d61f65c15be6bf12..18a7dcae7bcaed26532b41bedffa41bf48b9cd59 100644 (file)
@@ -7,6 +7,7 @@ be easily concluded from the AspectJ version number anymore, and we are sorry fo
 
 AspectJ version | Java version | Comments
 ----------------|--------------|--------
+1.9.9 | 18
 1.9.8 | 17 | AspectJ compiler requires JDK 11+ during build time. During runtime, AspectJ still only requires Java 8+ for both compile-time and load-time weaving. Pure Java code can be compiled down to as old as 1.3 byte code level.
 1.9.7 | 15, 16
 1.9.6 | 14
index 5beb81e3d230d1e05ee649fd6e7195c3dea899b6..6b79b5ab91396e8b9acd96c9eb6656d88757f2ba 100644 (file)
@@ -73,7 +73,8 @@
       Cross-compilation to legacy JDK
     </a>:
     An example class which only works correctly on JDK 8 when compiled with <tt>--release 8</tt> due to API changes in
-    the JDK. Simply <tt>-source 8 -target 8</tt> would not be enough in this case.</li>
+    the JDK. Simply <tt>-source 8 -target 8</tt> would not be enough in this case.
+  </li>
   <li>
     <a href="https://github.com/eclipse/org.aspectj/tree/master/tests/features198/java17">
       Pattern matching for switch
     <a href="https://github.com/eclipse/org.aspectj/blob/de63b63d/tests/bugs198/github_68/Generator.java#L50-L61">
       craft a condy class with ASM</a>.
   </li>
-  <li>
-    Improvements for <tt>if()</tt> pointcuts in annotation syntax, see issues
-    <a href="https://github.com/eclipse/org.aspectj/issues/115">#115</a>,
-    <a href="https://github.com/eclipse/org.aspectj/issues/120">#120</a>,
-    <a href="https://github.com/eclipse/org.aspectj/issues/122">#122</a>.
-  </li>
   <li>
     Thanks to Andrey Turbanov for several clean code contributions and to Dmitry Mikhaylov for fixing a potential
     concurrency problem.
diff --git a/docs/dist/doc/README-199.html b/docs/dist/doc/README-199.html
new file mode 100644 (file)
index 0000000..8e09cd9
--- /dev/null
@@ -0,0 +1,126 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+
+<head>
+<title>AspectJ 1.9.9 Readme</title>
+<style type="text/css">
+  <!--
+  P   { margin-left:  20px; }
+  PRE { margin-left:  20px; }
+  LI  { margin-left:  20px; }
+  H4  { margin-left:  20px; }
+  H3  { margin-left:  10px; }
+  -->
+</style>
+</head>
+
+<body>
+<div align="right"><small>&copy; Copyright 2022 Contributors. All rights reserved.</small></div>
+
+<h1>AspectJ 1.9.9</h1>
+
+<p>
+  Please note that Bugzilla for issue management is deprecated and new issues should be filed as
+  <a href="https://github.com/eclipse/org.aspectj/issues/new">GitHub issues</a>.
+  The list of issues addressed for 1.9.9 can be found
+  <a href="https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&f0=OP&f1=OP&f3=CP&f4=CP&j1=OR&list_id=16866879&product=AspectJ&query_format=advanced&target_milestone=1.9.9">here for Bugzilla</a>
+  and <a href="https://github.com/eclipse/org.aspectj/issues?q=is%3Aissue+is%3Aclosed++milestone%3A1.9.9">here for GitHub issues</a>.
+</p>
+
+<h2>New features</h2>
+
+<p>
+  AspectJ 1.9.9 supports <a href="https://openjdk.java.net/projects/jdk/18/">Java 18</a> and its final and preview
+  features, such as:
+</p>
+<ul>
+  <li>Pattern matching for <tt>switch</tt> (preview 2)</li>
+</ul>
+
+<h2>Improvements</h2>
+
+<h2>Code examples</h2>
+
+<p>
+  You can find some sample code in the AspectJ test suite under the respective AspectJ version in which the features
+  were first supported (possibly as JVM preview features):
+</p>
+<ul>
+  <li>
+    <a href="https://github.com/eclipse/org.aspectj/tree/master/tests/features198/java17">
+      Pattern matching for switch, preview 1
+    </a>
+  </li>
+  <li>
+    <a href="https://github.com/eclipse/org.aspectj/tree/master/tests/features199/java18">
+      Pattern matching for switch, preview 2
+    </a>
+  </li>
+</ul>
+
+<h2>Other changes and bug fixes</h2>
+
+<ul>
+  <li>
+    Fix a bug which led to <tt>NullPointerException</tt>s if too many JAR archives were on the classpath. Too many here
+    means the value system property <tt>org.aspectj.weaver.openarchives</tt> (1,000 by default). The AspectJ compiler is
+    meant to close archives upon cache exhaustion and then re-open them if it needs them again later. Re-opening was
+    broken, now the compiler works reliably even for cache sizes as small as 20. See issue
+    <a href="https://github.com/eclipse/org.aspectj/issues/125">#125</a>.
+  </li>
+  <li>
+    Improvements for <tt>if()</tt> pointcuts in annotation syntax, see issues
+    <a href="https://github.com/eclipse/org.aspectj/issues/115">#115</a>,
+    <a href="https://github.com/eclipse/org.aspectj/issues/120">#120</a>,
+    <a href="https://github.com/eclipse/org.aspectj/issues/122">#122</a>.
+  </li>
+  <li>
+    Thanks to Andrey Turbanov for several clean code contributions.
+  </li>
+</ul>
+
+<h2>AspectJ usage hints</h2>
+
+<h3>AspectJ compiler build system requirements</h3>
+
+<p>
+  Since 1.9.7, the AspectJ compiler <tt>ajc</tt> (contained in the <tt>aspectjtools</tt> library) no longer works on
+  JDKs 8 to 10. The minimum compile-time requirement is now JDK 11 due to upstream changes in the Eclipse Java Compiler
+  (subset of JDT Core), which AspectJ is a fork of. You can still compile to legacy target versions as low as Java 1.3
+  when compiling plain Java code or using plain Java ITD constructs which do not require the AspectJ runtime
+  <tt>aspectjrt</tt>, but the compiler itself needs JDK 11+. Just like in previous AspectJ versions, both the runtime
+  <tt>aspectjrt</tt> and the load-time weaver <tt>aspectjweaver</tt> still only require JRE 8+.
+</p>
+
+<h3>Use LTW on Java 16+</h3>
+
+<p>
+  Please note that if you want to use load-time weaving on Java 16+, the weaving agent collides with
+  <a href="https://openjdk.java.net/jeps/396">JEP 396 (Strongly Encapsulate JDK Internals by Default)</a> and related
+  subsequent JEPs. Therefore, you need to set the JVM parameter <tt>--add-opens java.base/java.lang=ALL-UNNAMED</tt> in
+  order to enable aspect weaving. This is due to the fact that the weaver uses internal APIs for which we have not found
+  an adequate replacement yet when defining classes in different classloaders.
+</p>
+
+<h3>Compile with Java preview features</h3>
+
+<p>
+  For features marked as preview on a given JDK, you need to compile with <tt>ajc --enable-preview</tt> and run with
+  <tt>java --enable-preview</tt> on that JDK.
+</p>
+<p>
+  Please note that you cannot run code compiled with preview features on any other JDK than the one used for
+  compilation. For example, records compiled with preview on JDK 15 cannot be used on JDK 16 without recompilation. This
+  is a JVM limitation unrelated to AspectJ. Also, e.g. sealed classes are preview-1 on JDK 15 and preview-2 on JDK 16.
+  You still need to recompile, no matter what.
+</p>
+
+<hr>
+
+<p>
+  <b>Available:</b> 1.9.9 available DD-MMM-2022
+</p>
+
+</body>
+
+</html>
index a54d7ec22c076edaa224a1200b43c6196a18590c..153469df0e7e5e0657dc52b7136bf35ae64f7af0 100644 (file)
@@ -1,5 +1,5 @@
 compiler.name = AspectJ Compiler
-compiler.version = Eclipse Compiler f8768b6899a6a2 (15Sep2021) - Java17
+compiler.version = Eclipse Compiler a721c849b3f9d5 (18Mar2022) - Java18
 compiler.copyright =
 
 misc.version = {0} {1} - {2} {3}
diff --git a/pom.xml b/pom.xml
index ed9ec5fb12cc703bb8e15f8d36da9c46be1bde61..3e988779c9c75475c3a9fff275145e20a3f3cf79 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
                <maven.javadoc.skip>true</maven.javadoc.skip>
 
                <!-- Dependency versions -->
-               <jdt.core.version>1.9.9-SNAPSHOT</jdt.core.version>
+               <jdt.core.version>1.9.9.j18-SNAPSHOT</jdt.core.version>
                <asm.version>9.2</asm.version>
                <lib.ant.version>1.6.3</lib.ant.version>
                <lib.ant.xerces.version>2.6.2</lib.ant.xerces.version>
index e49580dbe262d2bee499bb119b5c7384277ab665..260d16d90e654bd2ed3a3a4709392c4e80df7d63 100644 (file)
@@ -250,9 +250,18 @@ public class AjcTask extends MatchingTask {
 
        public static final String COMMAND_EDITOR_NAME = AjcTask.class.getName() + ".COMMAND_EDITOR";
 
-       static final String[] TARGET_INPUTS = new String[] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
-       static final String[] SOURCE_INPUTS = new String[] { "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
-       static final String[] COMPLIANCE_INPUTS = new String[] { "-1.3", "-1.4", "-1.5", "-1.6", "-1.7", "-1.8", "-1.9", "-9", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17" };
+       static final String[] TARGET_INPUTS = new String[] {
+               "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9",
+               "10", "11", "12", "13", "14", "15", "16", "17", "18"
+       };
+       static final String[] SOURCE_INPUTS = new String[] {
+               "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9",
+               "10", "11", "12", "13", "14", "15", "16", "17", "18"
+       };
+       static final String[] COMPLIANCE_INPUTS = new String[] {
+               "-1.3", "-1.4", "-1.5", "-1.6", "-1.7", "-1.8", "-1.9", "-9",
+               "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18"
+       };
 
        private static final ICommandEditor COMMAND_EDITOR;
 
index 0c351c69a46bba8745419153a6a2a2cdab78832b..78941fcabbab7ef6f52a048b3b318f163d736b25 100644 (file)
@@ -20,21 +20,21 @@ public abstract class XMLBasedAjcTestCaseForJava17Only extends XMLBasedAjcTestCa
        @Override
        public void setUp() throws Exception {
                // Activate this block after upgrading to JDT Core Java 18
-               /*
                throw new IllegalStateException(
                        "These tests need a Java 17 level AspectJ compiler " +
                                "(e.g. because they use version-specific preview features). " +
                                "This compiler does not support preview features of a previous version anymore."
                );
-               */
                // Activate this block before upgrading to JDT Core Java 18
+               /*
                if (!LangUtil.is17VMOrGreater() || LangUtil.is18VMOrGreater()) {
                        throw new IllegalStateException(
                                "These tests should be run on Java 17 only " +
                                "(e.g. because they use version-specific preview features)"
                        );
-               }
                super.setUp();
+               }
+               */
        }
 
 }
diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java
new file mode 100644 (file)
index 0000000..ba4d006
--- /dev/null
@@ -0,0 +1,40 @@
+/* *******************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ * ******************************************************************/
+package org.aspectj.testing;
+
+import org.aspectj.util.LangUtil;
+
+/**
+ * Makes sure tests are running on the right level of JDK.
+ *
+ * @author Alexander Kriegisch
+ */
+public abstract class XMLBasedAjcTestCaseForJava18Only extends XMLBasedAjcTestCase {
+
+       @Override
+       public void setUp() throws Exception {
+               // Activate this block after upgrading to JDT Core Java 19
+               /*
+               throw new IllegalStateException(
+                       "These tests need a Java 18 level AspectJ compiler " +
+                               "(e.g. because they use version-specific preview features). " +
+                               "This compiler does not support preview features of a previous version anymore."
+               );
+               */
+               // Activate this block before upgrading to JDT Core Java 19
+               if (!LangUtil.is18VMOrGreater() || LangUtil.is19VMOrGreater()) {
+                       throw new IllegalStateException(
+                               "These tests should be run on Java 18 only " +
+                               "(e.g. because they use version-specific preview features)"
+                       );
+               }
+               super.setUp();
+       }
+
+}
diff --git a/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java b/testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java
new file mode 100644 (file)
index 0000000..9b9efdd
--- /dev/null
@@ -0,0 +1,27 @@
+/* *******************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ * ******************************************************************/
+package org.aspectj.testing;
+
+import org.aspectj.util.LangUtil;
+
+/**
+ * Makes sure tests are running on the right level of JDK.
+ *
+ * @author Alexander Kriegisch
+ */
+public abstract class XMLBasedAjcTestCaseForJava18OrLater extends XMLBasedAjcTestCase {
+
+       @Override
+       public void setUp() throws Exception {
+               if (!LangUtil.is18VMOrGreater())
+                       throw new IllegalStateException("These tests should be run on Java 18 or later");
+               super.setUp();
+       }
+
+}
diff --git a/tests/bugs198/github_115/A.java b/tests/bugs198/github_115/A.java
deleted file mode 100644 (file)
index 07df21f..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-
-public class A {
-
-       public static void main(String []argv) {
-               System.out.println("A.main");
-       }
-
-}
-
-@Aspect
-class Azpect {
-       
-       @Pointcut("if(false)")
-       public void isFalse() { }
-
-       @Pointcut("if(true)")
-       public void isTrue() { }
-
-       @Before("isTrue() && execution(* A.main(..))")
-       public void beforeTrue() {
-               System.out.println("Azpect.beforeTrue");
-       }
-
-       @Before("isFalse() && execution(* A.main(..))")
-       public void beforeFalse() {
-               System.out.println("Azpect.beforeFalse");
-       }
-}
-
diff --git a/tests/bugs198/github_115/B.java b/tests/bugs198/github_115/B.java
deleted file mode 100644 (file)
index eba199b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-
-public class B {
-
-       public static void main(String []argv) {
-               System.out.println("B.main");
-       }
-
-}
-
-@Aspect
-abstract class AbstractAzpect {
-
-       @Pointcut
-       public abstract void isTrue();
-       
-       @Before("isTrue() && execution(* B.main(..))")
-       public void beforeFalse() {
-               System.out.println("Azpect.beforeFalse");
-       }
-}
-
-@Aspect
-class Azpect extends AbstractAzpect {
-       
-       @Override
-       @Pointcut("if(true)")
-       public void isTrue() { }
-
-}
-
diff --git a/tests/bugs198/github_120/C.java b/tests/bugs198/github_120/C.java
deleted file mode 100644 (file)
index 4af57af..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-
-/**
- * This test is exploring situations where an if() pointcut is used with a parameter
- * and yet a reference pointcut referring to it is not binding the parameter.
- */
-public class C {
-       
-       int i;
-
-       C(int i) {
-               this.i = i;
-       }
-       
-       public static void main(String []argv) {
-               new C(1).run();
-       }
-
-       public void run() {
-               System.out.println("C.run() executing");
-       }
-       
-       public String toString() {
-               return "C("+i+")";
-       }
-
-}
-
-@Aspect
-abstract class Azpect1 {
-
-       @Pointcut("if(false)")
-       public void isCondition() {}
-       
-       @Before("isCondition() && execution(* C.run(..))")
-       public void beforeAdvice() {
-               System.out.println("Azpect1.beforeAdvice executing");
-       }
-       
-}
-
-@Aspect
-class Azpect2 extends Azpect1 {
-       @Pointcut("check(*)")
-       public void isCondition() { }
-       
-       @Pointcut("this(c) && if()")
-       public static boolean check(C c) {
-               System.out.println("check if() pointcut running on "+c.toString());
-               return true;
-       }
-}
-//
-//abstract aspect A {
-//     pointcut isCondition(): if(false);
-//     before(): isCondition() && execution(* C.run(..)) { System.out.println("A.before"); }
-//}
-//
-//aspect B extends A {
-//     pointcut isCondition(): check(*);
-//     pointcut check(Object o): this(o) && if(o.toString().equals("abc"));
-//}
\ No newline at end of file
diff --git a/tests/bugs198/github_120/D.java b/tests/bugs198/github_120/D.java
deleted file mode 100644 (file)
index 2ecdaa5..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-
-/**
- * This test is exploring situations where an if() pointcut is used with a parameter
- * and yet a reference pointcut referring to it is not binding the parameter.
- */
-public class D {
-       
-
-       public static void main(String []argv) {
-               new D().run();
-       }
-
-       public void run() {
-               System.out.println("D.run() executing");
-       }
-       
-       public boolean isTrue() {
-               return true;
-       }
-
-}
-
-@Aspect class Azpect {
-
-       @Pointcut("this(d) && if()") public static boolean method(D d) { return d.isTrue(); }
-
-       @Before("method(*) && execution(* D.run(..))") public void beforeAdvice() {
-               System.out.println("advice running");
-       }
-}
\ No newline at end of file
diff --git a/tests/bugs198/github_122/E.java b/tests/bugs198/github_122/E.java
deleted file mode 100644 (file)
index 29c8182..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-
-/**
- * Test !if() pointcuts
- */
-public class E {
-
-       public static void main(String []argv) {
-               new E().run();
-       }
-
-       public void run() {
-               System.out.println("E.run() executing");
-       }
-
-}
-
-@Aspect class Azpect {
-
-       @Pointcut("!bar()") 
-       public static void foo() {}
-       
-       @Pointcut("if()") public static boolean bar() { return false; }
-
-       @Before("foo() && execution(* E.run(..))") public void beforeAdvice() {
-               System.out.println("advice running");
-       }
-}
\ No newline at end of file
diff --git a/tests/bugs198/github_125/Application.java b/tests/bugs198/github_125/Application.java
deleted file mode 100644 (file)
index 7e893fc..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-public class Application {
-  public static void main(String[] argv) {
-    System.out.println("Hello world!");
-  }
-
-  static aspect MyAspect {
-    before(): execution(* Application.main(..)) {
-      System.out.println("Before advice");
-    }
-  }
-}
diff --git a/tests/bugs199/github_115/A.java b/tests/bugs199/github_115/A.java
new file mode 100644 (file)
index 0000000..07df21f
--- /dev/null
@@ -0,0 +1,32 @@
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+public class A {
+
+       public static void main(String []argv) {
+               System.out.println("A.main");
+       }
+
+}
+
+@Aspect
+class Azpect {
+       
+       @Pointcut("if(false)")
+       public void isFalse() { }
+
+       @Pointcut("if(true)")
+       public void isTrue() { }
+
+       @Before("isTrue() && execution(* A.main(..))")
+       public void beforeTrue() {
+               System.out.println("Azpect.beforeTrue");
+       }
+
+       @Before("isFalse() && execution(* A.main(..))")
+       public void beforeFalse() {
+               System.out.println("Azpect.beforeFalse");
+       }
+}
+
diff --git a/tests/bugs199/github_115/B.java b/tests/bugs199/github_115/B.java
new file mode 100644 (file)
index 0000000..eba199b
--- /dev/null
@@ -0,0 +1,33 @@
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+public class B {
+
+       public static void main(String []argv) {
+               System.out.println("B.main");
+       }
+
+}
+
+@Aspect
+abstract class AbstractAzpect {
+
+       @Pointcut
+       public abstract void isTrue();
+       
+       @Before("isTrue() && execution(* B.main(..))")
+       public void beforeFalse() {
+               System.out.println("Azpect.beforeFalse");
+       }
+}
+
+@Aspect
+class Azpect extends AbstractAzpect {
+       
+       @Override
+       @Pointcut("if(true)")
+       public void isTrue() { }
+
+}
+
diff --git a/tests/bugs199/github_120/C.java b/tests/bugs199/github_120/C.java
new file mode 100644 (file)
index 0000000..4af57af
--- /dev/null
@@ -0,0 +1,64 @@
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ * This test is exploring situations where an if() pointcut is used with a parameter
+ * and yet a reference pointcut referring to it is not binding the parameter.
+ */
+public class C {
+       
+       int i;
+
+       C(int i) {
+               this.i = i;
+       }
+       
+       public static void main(String []argv) {
+               new C(1).run();
+       }
+
+       public void run() {
+               System.out.println("C.run() executing");
+       }
+       
+       public String toString() {
+               return "C("+i+")";
+       }
+
+}
+
+@Aspect
+abstract class Azpect1 {
+
+       @Pointcut("if(false)")
+       public void isCondition() {}
+       
+       @Before("isCondition() && execution(* C.run(..))")
+       public void beforeAdvice() {
+               System.out.println("Azpect1.beforeAdvice executing");
+       }
+       
+}
+
+@Aspect
+class Azpect2 extends Azpect1 {
+       @Pointcut("check(*)")
+       public void isCondition() { }
+       
+       @Pointcut("this(c) && if()")
+       public static boolean check(C c) {
+               System.out.println("check if() pointcut running on "+c.toString());
+               return true;
+       }
+}
+//
+//abstract aspect A {
+//     pointcut isCondition(): if(false);
+//     before(): isCondition() && execution(* C.run(..)) { System.out.println("A.before"); }
+//}
+//
+//aspect B extends A {
+//     pointcut isCondition(): check(*);
+//     pointcut check(Object o): this(o) && if(o.toString().equals("abc"));
+//}
\ No newline at end of file
diff --git a/tests/bugs199/github_120/D.java b/tests/bugs199/github_120/D.java
new file mode 100644 (file)
index 0000000..2ecdaa5
--- /dev/null
@@ -0,0 +1,33 @@
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ * This test is exploring situations where an if() pointcut is used with a parameter
+ * and yet a reference pointcut referring to it is not binding the parameter.
+ */
+public class D {
+       
+
+       public static void main(String []argv) {
+               new D().run();
+       }
+
+       public void run() {
+               System.out.println("D.run() executing");
+       }
+       
+       public boolean isTrue() {
+               return true;
+       }
+
+}
+
+@Aspect class Azpect {
+
+       @Pointcut("this(d) && if()") public static boolean method(D d) { return d.isTrue(); }
+
+       @Before("method(*) && execution(* D.run(..))") public void beforeAdvice() {
+               System.out.println("advice running");
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs199/github_122/E.java b/tests/bugs199/github_122/E.java
new file mode 100644 (file)
index 0000000..29c8182
--- /dev/null
@@ -0,0 +1,30 @@
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ * Test !if() pointcuts
+ */
+public class E {
+
+       public static void main(String []argv) {
+               new E().run();
+       }
+
+       public void run() {
+               System.out.println("E.run() executing");
+       }
+
+}
+
+@Aspect class Azpect {
+
+       @Pointcut("!bar()") 
+       public static void foo() {}
+       
+       @Pointcut("if()") public static boolean bar() { return false; }
+
+       @Before("foo() && execution(* E.run(..))") public void beforeAdvice() {
+               System.out.println("advice running");
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs199/github_125/Application.java b/tests/bugs199/github_125/Application.java
new file mode 100644 (file)
index 0000000..7e893fc
--- /dev/null
@@ -0,0 +1,11 @@
+public class Application {
+  public static void main(String[] argv) {
+    System.out.println("Hello world!");
+  }
+
+  static aspect MyAspect {
+    before(): execution(* Application.main(..)) {
+      System.out.println("Before advice");
+    }
+  }
+}
diff --git a/tests/features199/java18/SwitchPatternPreview2Aspect.aj b/tests/features199/java18/SwitchPatternPreview2Aspect.aj
new file mode 100644 (file)
index 0000000..ee5dbbd
--- /dev/null
@@ -0,0 +1,28 @@
+import java.util.Locale;
+
+aspect SwitchPatternPreview2Aspect {
+  Object around(Object o): execution(* doSomethingWithObject(*)) && args(o) {
+    System.out.println(
+      switch (o) {
+        case -1, 1 -> "special case:" + o;
+        case Integer i && i > 0 -> "positive integer: " + o;
+        case Integer i -> "other integer: " + o;
+        default -> "non-integer: " + o;
+      }
+    );
+    return proceed(o);
+  }
+}
+
+class Application {
+  public static void main(String[] args) {
+    doSomethingWithObject(-1);
+    doSomethingWithObject(0);
+    doSomethingWithObject(42);
+    doSomethingWithObject(-99);
+    doSomethingWithObject("test");
+    doSomethingWithObject(null);
+  }
+
+  public static Object doSomethingWithObject(Object o) { return o; }
+}
diff --git a/tests/features199/java18/SwitchPatternPreview2Error.java b/tests/features199/java18/SwitchPatternPreview2Error.java
new file mode 100644 (file)
index 0000000..b1652aa
--- /dev/null
@@ -0,0 +1,31 @@
+/**
+ * Inspired by examples in https://openjdk.java.net/jeps/420
+ */
+public class SwitchPatternPreview2Error {
+  static void constantLabelMustAppearBeforePattern1(Object o) {
+    switch (o) {
+      case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+      case -1, 1 -> System.out.println("special case:" + o);
+      case Integer i -> System.out.println("other integer: " + o);
+      default -> System.out.println("non-integer: " + o);
+    }
+  }
+
+  static void constantLabelMustAppearBeforePattern2(Object o) {
+    switch (o) {
+      case -1, 1 -> System.out.println("special case:" + o);
+      case Integer i -> System.out.println("other integer: " + o);
+      case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+      default -> System.out.println("non-integer: " + o);
+    }
+  }
+
+  static void constantLabelMustAppearBeforePattern3(Object o) {
+    switch (o) {
+      case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+      case Integer i -> System.out.println("other integer: " + o);
+      case -1, 1 -> System.out.println("special case:" + o);
+      default -> System.out.println("non-integer: " + o);
+    }
+  }
+}
diff --git a/tests/features199/java18/SwitchPatternPreview2OK.java b/tests/features199/java18/SwitchPatternPreview2OK.java
new file mode 100644 (file)
index 0000000..859583b
--- /dev/null
@@ -0,0 +1,38 @@
+import java.util.List;
+
+/**
+ * Inspired by examples in https://openjdk.java.net/jeps/420
+ */
+public class SwitchPatternPreview2OK {
+  public static void main(String[] args) {
+    constantLabelMustAppearBeforePattern(-1);
+    constantLabelMustAppearBeforePattern(0);
+    constantLabelMustAppearBeforePattern(42);
+    constantLabelMustAppearBeforePattern(-99);
+    constantLabelMustAppearBeforePattern(Integer.valueOf(123));
+    constantLabelMustAppearBeforePattern(null);
+
+    System.out.println(testGenericSealedExhaustive(new B<Integer>()));
+  }
+
+  static String constantLabelMustAppearBeforePattern(Object o) {
+    switch (o) {
+      case -1, 1 -> System.out.println("special case:" + o);
+      case Integer i && i > 0 -> System.out.println("positive integer: " + o);
+      case Integer i -> System.out.println("other integer: " + o);
+      default -> System.out.println("non-integer: " + o);
+    }
+    return o.toString();
+  }
+
+  sealed interface I<T> permits A, B {}
+  final static class A<X> implements I<String> {}
+  final static class B<Y> implements I<Y> {}
+
+  static int testGenericSealedExhaustive(I<Integer> i) {
+    return switch (i) {
+      // Exhaustive as no A case possible!
+      case B<Integer> bi -> 42;
+    };
+  }
+}
index ef597c8f1acfc955c0bf7fb4edd1880dfa812753..3e6ead46744ccc02f995ad6982e17eb0429b685b 100644 (file)
@@ -17,35 +17,29 @@ import org.aspectj.testing.XMLBasedAjcTestCaseForJava17OrLater;
  */
 public class Ajc198TestsJava extends XMLBasedAjcTestCaseForJava17OrLater {
 
-       public void testSealedClassWithLegalSubclasses() {
-               runTest("sealed class with legal subclasses");
-               // TODO: replace 0 by Constants.PREVIEW_MINOR_VERSION after no longer using EA
-               // build, but final JDK version
-               checkVersion("Employee", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
-               checkVersion("Manager", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
-       }
-
-       public void testSealedClassWithIllegalSubclass() {
-               runTest("sealed class with illegal subclass");
-               // TODO: replace 0 by Constants.PREVIEW_MINOR_VERSION after no longer using EA
-               // build, but final JDK version
-               checkVersion("Person", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
-       }
-
-       public void testWeaveSealedClass() {
-               runTest("weave sealed class");
-               // TODO: replace 0 by Constants.PREVIEW_MINOR_VERSION after no longer using EA
-               // build, but final JDK version
-               checkVersion("PersonAspect", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
-       }
-
-       public static Test suite() {
-               return XMLBasedAjcTestCase.loadSuite(Ajc198TestsJava.class);
-       }
-
-       @Override
-       protected java.net.URL getSpecFile() {
-               return getClassResource("ajc198.xml");
-       }
+  public void testSealedClassWithLegalSubclasses() {
+    runTest("sealed class with legal subclasses");
+    checkVersion("Employee", Constants.MAJOR_17, Constants.MINOR_17);
+    checkVersion("Manager", Constants.MAJOR_17, Constants.MINOR_17);
+  }
+
+  public void testSealedClassWithIllegalSubclass() {
+    runTest("sealed class with illegal subclass");
+    checkVersion("Person", Constants.MAJOR_17, Constants.MINOR_17);
+  }
+
+  public void testWeaveSealedClass() {
+    runTest("weave sealed class");
+    checkVersion("PersonAspect", Constants.MAJOR_17, Constants.MINOR_17);
+  }
+
+  public static Test suite() {
+    return XMLBasedAjcTestCase.loadSuite(Ajc198TestsJava.class);
+  }
+
+  @Override
+  protected java.net.URL getSpecFile() {
+    return getClassResource("ajc198.xml");
+  }
 
 }
index 3cfc7a149e9028779d93a0f88af5798ace631967..929b5749d49406631beb1538f7bcf3ab6a517c96 100644 (file)
@@ -29,9 +29,12 @@ public class AllTestsAspectJ198 {
                        suite.addTest(SanityTestsJava17.suite());
                        suite.addTest(Ajc198TestsJava.suite());
                }
+               // Do not run tests using a previous compiler's preview features anymore. They would all fail.
+               /*
                if (LangUtil.is17VMOrGreater() && !LangUtil.is18VMOrGreater()) {
                        suite.addTest(Java17PreviewFeaturesTests.suite());
                }
+               */
                return suite;
        }
 }
index 7982ec630c59e97294697bb0c1272ccab8444345..cb3b781bb03cfd73510a5b417afc41b8e51d9211 100644 (file)
@@ -21,33 +21,6 @@ public class Bugs198Tests extends XMLBasedAjcTestCase {
     runTest("ITD annotation with mandatory parameter via aspectpath");
   }
 
-  public void testAnnotationStyleSpecialIfClauses() {
-    runTest("annotation style A");
-  }
-
-  public void testAnnotationStylePointcutInheritanceWithIfClauses() {
-    runTest("annotation style B");
-  }
-
-  public void testAnnotationStyleSpecialIfClauses2_gh120() {
-    runTest("annotation style C");
-  }
-
-  public void testAnnotationStyleSpecialIfClauses3_gh120() {
-    runTest("annotation style D");
-  }
-
-  public void testAnnotationStyleNegatedIf_gh122() {
-    runTest("annotation style negated if");
-  }
-
-  public void testGitHub_125() {
-    try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) {
-      env.setProperty("org.aspectj.weaver.openarchives", "20");
-      runTest("compiler can re-open closed JARs");
-    }
-  }
-
   public static Test suite() {
     return XMLBasedAjcTestCase.loadSuite(Bugs198Tests.class);
   }
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/Ajc199TestsJava.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/Ajc199TestsJava.java
new file mode 100644 (file)
index 0000000..7040deb
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc199;
+
+import junit.framework.Test;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.testing.XMLBasedAjcTestCaseForJava18OrLater;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class Ajc199TestsJava extends XMLBasedAjcTestCaseForJava18OrLater {
+
+  public void testDummyJava18() {
+    runTest("dummy Java 18");
+  }
+
+  public static Test suite() {
+    return XMLBasedAjcTestCase.loadSuite(Ajc199TestsJava.class);
+  }
+
+  @Override
+  protected java.net.URL getSpecFile() {
+    return getClassResource("ajc199.xml");
+  }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java
new file mode 100644 (file)
index 0000000..9cb01ee
--- /dev/null
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc199;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.aspectj.util.LangUtil;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class AllTestsAspectJ199 {
+
+       public static Test suite() {
+               TestSuite suite = new TestSuite("AspectJ 1.9.9 tests");
+    suite.addTest(Bugs199Tests.suite());
+               if (LangUtil.is18VMOrGreater()) {
+                       suite.addTest(SanityTestsJava18.suite());
+                       suite.addTest(Ajc199TestsJava.suite());
+               }
+               if (LangUtil.is18VMOrGreater() && !LangUtil.is19VMOrGreater()) {
+                       suite.addTest(Java18PreviewFeaturesTests.suite());
+               }
+               return suite;
+       }
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java
new file mode 100644 (file)
index 0000000..f72f3c4
--- /dev/null
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc199;
+
+import io.bmuskalla.system.properties.PropertyEnvironment;
+import io.bmuskalla.system.properties.ScopedSystemProperties;
+import junit.framework.Test;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class Bugs199Tests extends XMLBasedAjcTestCase {
+
+  public void testAnnotationStyleSpecialIfClauses() {
+    runTest("annotation style A");
+  }
+
+  public void testAnnotationStylePointcutInheritanceWithIfClauses() {
+    runTest("annotation style B");
+  }
+
+  public void testAnnotationStyleSpecialIfClauses2_gh120() {
+    runTest("annotation style C");
+  }
+
+  public void testAnnotationStyleSpecialIfClauses3_gh120() {
+    runTest("annotation style D");
+  }
+
+  public void testAnnotationStyleNegatedIf_gh122() {
+    runTest("annotation style negated if");
+  }
+
+  public void testGitHub_125() {
+    try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) {
+      env.setProperty("org.aspectj.weaver.openarchives", "20");
+      runTest("compiler can re-open closed JARs");
+    }
+  }
+
+  public static Test suite() {
+    return XMLBasedAjcTestCase.loadSuite(Bugs199Tests.class);
+  }
+
+  @Override
+  protected java.net.URL getSpecFile() {
+    return getClassResource("ajc199.xml");
+  }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java
new file mode 100644 (file)
index 0000000..8d586b4
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc199;
+
+import junit.framework.Test;
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.testing.XMLBasedAjcTestCaseForJava18Only;
+
+/**
+ * @author Alexander Kriegisch
+ */
+public class Java18PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava18Only {
+
+  public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
+    runTest("switch pattern matching error");
+  }
+
+  public void testSwitchPatternMatchingJava() {
+    runTest("switch pattern matching java");
+    checkVersion("SwitchPatternOK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+  }
+
+  public void testSwitchPatternMatchingAspect() {
+    runTest("switch pattern matching aspect");
+    checkVersion("SwitchPatternAspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+    checkVersion("Application", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+    checkVersion("Shape", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+    checkVersion("S", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+  }
+
+  // TODO:
+  //   JDT Core does not seem to have implemented JEP 420 yet,
+  //   see https://bugs.eclipse.org/bugs/show_bug.cgi?id=576746.
+  //   Therefore, deactivate the special tests for now.
+/*
+  public void testSwitchPatternMatchingPreview2Error() {
+    runTest("switch pattern matching preview 2 error");
+  }
+
+  public void testSwitchPatternMatchingPreview2Java() {
+    runTest("switch pattern matching preview 2 java");
+    checkVersion("SwitchPatternOK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+  }
+
+  public void testSwitchPatternMatchingPreview2Aspect() {
+    runTest("switch pattern matching preview 2 aspect");
+    checkVersion("SwitchPatternAspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+    checkVersion("Application", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+    checkVersion("Shape", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+    checkVersion("S", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
+  }
+*/
+
+  public static Test suite() {
+    return XMLBasedAjcTestCase.loadSuite(Java18PreviewFeaturesTests.class);
+  }
+
+  @Override
+  protected java.net.URL getSpecFile() {
+    return getClassResource("ajc199.xml");
+  }
+
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc199/SanityTestsJava18.java b/tests/src/test/java/org/aspectj/systemtest/ajc199/SanityTestsJava18.java
new file mode 100644 (file)
index 0000000..d86e114
--- /dev/null
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2021 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc199;
+
+import junit.framework.Test;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.testing.XMLBasedAjcTestCaseForJava18OrLater;
+
+/*
+ * Some very trivial tests that help verify things are OK.
+ * These are a copy of the earlier Sanity Tests created for 1.6 but these supply the -17 option
+ * to check code generation and modification with that version specified.
+ *
+ * @author Alexander Kriegisch
+ */
+public class SanityTestsJava18 extends XMLBasedAjcTestCaseForJava18OrLater {
+
+       public static final int bytecode_version_for_JDK_level = 62;
+
+       // Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
+       public void testSimpleJava_A() {
+               runTest("simple - a");
+       }
+
+       public void testSimpleJava_B() {
+               runTest("simple - b");
+       }
+
+       public void testSimpleCode_C() {
+               runTest("simple - c");
+       }
+
+       public void testSimpleCode_D() {
+               runTest("simple - d");
+       }
+
+       public void testSimpleCode_E() {
+               runTest("simple - e");
+       }
+
+       public void testSimpleCode_F() {
+               runTest("simple - f");
+       }
+
+       public void testSimpleCode_G() {
+               runTest("simple - g");
+       }
+
+       public void testSimpleCode_H() {
+               runTest("simple - h", true);
+       }
+
+       public void testSimpleCode_I() {
+               runTest("simple - i");
+       }
+
+       public void testVersionCorrect1() {
+               runTest("simple - j");
+               checkVersion("A", bytecode_version_for_JDK_level, 0);
+       }
+
+       public void testVersionCorrect2() {
+               runTest("simple - k");
+               checkVersion("A", bytecode_version_for_JDK_level, 0);
+       }
+
+       public void testVersionCorrect4() {
+               runTest("simple - m");
+               // Must be 49.0 when -1.5 is specified
+               checkVersion("A", 49, 0);
+       }
+
+       public static Test suite() {
+               return XMLBasedAjcTestCase.loadSuite(SanityTestsJava18.class);
+       }
+
+       @Override
+       protected java.net.URL getSpecFile() {
+               return getClassResource("sanity-tests-18.xml");
+       }
+
+}
index 0eb413baa7ff60371bb7d90bfaca34658b57d8e1..85bd872b362cb752bda863e4c954078a6486498f 100644 (file)
                </run>
        </ajc-test>
 
-       <!-- Javac/ECJ 9+ compiler option, but belated implementation in AJC 1.9.7 -->
+       <!-- Javac/ECJ 9+ compiler option, but belated implementation in AJC 1.9.8 -->
        <ajc-test dir="features198/compiler_release" vm="9" title="compile to older JDK release">
                <compile files="Buffers.java" options="--release 8"/>
        </ajc-test>
 
-       <ajc-test dir="bugs198/github_115" title="annotation style A">
-               <compile files="A.java" options="-1.5">
-                       <message kind="warning" line="28" text="advice defined in Azpect has not been applied [Xlint:adviceDidNotMatch]"/>
-               </compile>
-               <run class="A">
-                       <stdout>
-                               <line text="Azpect.before"/>
-                               <line text="A.main"/>
-                       </stdout>
-               </run>
-       </ajc-test>
-
-       <ajc-test dir="bugs198/github_115" title="annotation style B">
-               <compile files="B.java" options="-1.5"/>
-               <run class="B">
-                       <stdout>
-                               <line text="Azpect.before"/>
-                               <line text="B.main"/>
-                       </stdout>
-               </run>
-       </ajc-test>
-
-       <ajc-test dir="bugs198/github_120" title="annotation style C">
-               <compile files="C.java" options="-1.5"/>
-               <run class="C">
-                       <stdout>
-                               <line text="check if() pointcut running on C(1)"/>
-                               <line text="Azpect1.beforeAdvice executing"/>
-                               <line text="C.run() executing"/>
-                       </stdout>
-               </run>
-       </ajc-test>
-
-       <ajc-test dir="bugs198/github_120" title="annotation style D">
-               <compile files="D.java" options="-1.5"/>
-               <run class="D">
-                       <stdout>
-                               <line text="advice running"/>
-                               <line text="D.run() executing"/>
-                       </stdout>
-               </run>
-       </ajc-test>
-
-       <ajc-test dir="bugs198/github_122" title="annotation style negated if">
-               <compile files="E.java" options="-1.5"/>
-               <run class="E">
-                       <stdout>
-                               <line text="advice running"/>
-                               <line text="E.run() executing"/>
-                       </stdout>
-               </run>
-       </ajc-test>
-
-       <ajc-test dir="bugs198/github_125" title="compiler can re-open closed JARs">
-               <!--
-                       Here the Java test sets system property org.aspectj.weaver.openarchives to 20 in order to provoke
-                       open JAR limit exhaustion
-               -->
-               <compile files="Application.java" options="-1.5" />
-               <run class="Application">
-                       <stdout>
-                               <line text="Before advice"/>
-                               <line text="Hello world!"/>
-                       </stdout>
-               </run>
-       </ajc-test>
-
 </suite>
diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml
new file mode 100644 (file)
index 0000000..f76858a
--- /dev/null
@@ -0,0 +1,177 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+
+<suite>
+
+       <!-- Java 18 final: no new features, only 2nd preview for "JEP 420: Pattern Matching for switch (Second Preview)" -->
+       <ajc-test dir="features199/java18" vm="18" title="dummy Java 18">
+       </ajc-test>
+
+       <!-- Java ?? final, Java 17, 18 preview -->
+       <ajc-test dir="features198/java17" vm="18" title="switch pattern matching error">
+               <compile files="SwitchPatternError.java" options="--enable-preview -18">
+                       <!-- TODO: Add correct compiler error message, as soon as JDT Core supports it -->
+                       <message kind="error" file="SwitchPatternError.java" text="This case label is dominated by one of the preceding case label"/>
+               </compile>
+       </ajc-test>
+
+       <!-- Java ?? final, Java 17, 18 preview -->
+       <ajc-test dir="features198/java17" vm="18" title="switch pattern matching java">
+               <compile files="SwitchPatternOK.java" options="--enable-preview -18" />
+               <run class="SwitchPatternOK" vmargs="--enable-preview">
+                       <stdout>
+                               <line text="null" />
+                               <line text="int 123" />
+                               <line text="long 999" />
+                               <line text="double 12.340000" />
+                               <line text="String foo" />
+                               <line text="[123, foo, 999, 12.34]" />
+                               <line text="Non-circle" />
+                               <line text="Small circle" />
+                               <line text="Large circle" />
+                               <line text="Sealed sub-class A" />
+                               <line text="Sealed sub-class B" />
+                               <line text="Sealed sub-record C" />
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <!-- Java ?? final, Java 17, 18 preview -->
+       <ajc-test dir="features198/java17" vm="18" title="switch pattern matching aspect">
+               <compile files="SwitchPatternAspect.aj" options="--enable-preview -18" />
+               <run class="Application" vmargs="--enable-preview">
+                       <stdout>
+                               <line text="null" />
+                               <line text="int 123" />
+                               <line text="long 999" />
+                               <line text="double 12.340000" />
+                               <line text="String foo" />
+                               <line text="[123, foo, 999, 12.34]" />
+                               <line text="Non-circle" />
+                               <line text="Small circle" />
+                               <line text="Large circle" />
+                               <line text="Sealed sub-class A" />
+                               <line text="Sealed sub-class B" />
+                               <line text="Sealed sub-record C" />
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <!-- Java ?? final, Java 17, 18 preview -->
+       <ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 error">
+               <compile files="SwitchPatternPreview2Error.java" options="--enable-preview -18">
+                       <!-- TODO: Add correct compiler error message, as soon as JDT Core supports it -->
+                       <message kind="error" file="SwitchPatternError.java" text="This case label is dominated by one of the preceding case label"/>
+               </compile>
+       </ajc-test>
+
+       <!-- Java ?? final, Java 17, 18 preview -->
+       <ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 java">
+               <compile files="SwitchPatternPreview2OK.java" options="--enable-preview -18" />
+               <run class="SwitchPatternOK" vmargs="--enable-preview">
+                       <stdout>
+                               <line text="null" />
+                               <line text="int 123" />
+                               <line text="long 999" />
+                               <line text="double 12.340000" />
+                               <line text="String foo" />
+                               <line text="[123, foo, 999, 12.34]" />
+                               <line text="Non-circle" />
+                               <line text="Small circle" />
+                               <line text="Large circle" />
+                               <line text="Sealed sub-class A" />
+                               <line text="Sealed sub-class B" />
+                               <line text="Sealed sub-record C" />
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <!-- Java ?? final, Java 17, 18 preview -->
+       <ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 aspect">
+               <compile files="SwitchPatternPreview2Aspect.aj" options="--enable-preview -18" />
+               <run class="Application" vmargs="--enable-preview">
+                       <stdout>
+                               <line text="null" />
+                               <line text="int 123" />
+                               <line text="long 999" />
+                               <line text="double 12.340000" />
+                               <line text="String foo" />
+                               <line text="[123, foo, 999, 12.34]" />
+                               <line text="Non-circle" />
+                               <line text="Small circle" />
+                               <line text="Large circle" />
+                               <line text="Sealed sub-class A" />
+                               <line text="Sealed sub-class B" />
+                               <line text="Sealed sub-record C" />
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_115" title="annotation style A">
+               <compile files="A.java" options="-1.5">
+                       <message kind="warning" line="28" text="advice defined in Azpect has not been applied [Xlint:adviceDidNotMatch]"/>
+               </compile>
+               <run class="A">
+                       <stdout>
+                               <line text="Azpect.before"/>
+                               <line text="A.main"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_115" title="annotation style B">
+               <compile files="B.java" options="-1.5"/>
+               <run class="B">
+                       <stdout>
+                               <line text="Azpect.before"/>
+                               <line text="B.main"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_120" title="annotation style C">
+               <compile files="C.java" options="-1.5"/>
+               <run class="C">
+                       <stdout>
+                               <line text="check if() pointcut running on C(1)"/>
+                               <line text="Azpect1.beforeAdvice executing"/>
+                               <line text="C.run() executing"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_120" title="annotation style D">
+               <compile files="D.java" options="-1.5"/>
+               <run class="D">
+                       <stdout>
+                               <line text="advice running"/>
+                               <line text="D.run() executing"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_122" title="annotation style negated if">
+               <compile files="E.java" options="-1.5"/>
+               <run class="E">
+                       <stdout>
+                               <line text="advice running"/>
+                               <line text="E.run() executing"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs199/github_125" title="compiler can re-open closed JARs">
+               <!--
+                       Here the Java test sets system property org.aspectj.weaver.openarchives to 20 in order to provoke
+                       open JAR limit exhaustion
+               -->
+               <compile files="Application.java" options="-1.5" />
+               <run class="Application">
+                       <stdout>
+                               <line text="Before advice"/>
+                               <line text="Hello world!"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+</suite>
diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc199/sanity-tests-18.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc199/sanity-tests-18.xml
new file mode 100644 (file)
index 0000000..30c9660
--- /dev/null
@@ -0,0 +1,70 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<suite>
+
+    <!-- empty class -->
+    <ajc-test dir="bugs160/simplejava" title="simple - a">
+      <compile files="SimpleA.java" options="-18"/>
+    </ajc-test>
+
+    <!-- class with one method -->
+    <ajc-test dir="bugs160/simplejava" title="simple - b">
+      <compile files="SimpleB.java" options="-18"/>
+      <run class="SimpleB"/>
+    </ajc-test>
+
+    <!-- empty aspect -->
+    <ajc-test dir="bugs160/simplejava" title="simple - c">
+      <compile files="SimpleC.java" options="-18"/>
+    </ajc-test>
+
+    <!-- simple before -->
+    <ajc-test dir="bugs160/simplejava" title="simple - d">
+      <compile files="SimpleD.java" options="-18"/>
+    </ajc-test>
+
+    <!-- simple itd field -->
+    <ajc-test dir="bugs160/simplejava" title="simple - e">
+      <compile files="SimpleE.java" options="-18"/>
+    </ajc-test>
+
+    <!-- aspect with main calling a static method -->
+    <ajc-test dir="bugs160/simplejava" title="simple - f">
+      <compile files="SimpleF.java" options="-18"/>
+    </ajc-test>
+
+    <!-- pertarget -->
+    <ajc-test dir="bugs160/simplejava" title="simple - g">
+      <compile files="SimpleG.java" options="-18"/>
+    </ajc-test>
+
+    <!-- generic ctor itds -->
+    <ajc-test dir="bugs160/simplejava" title="simple - h">
+      <compile files="SimpleH.java" options="-18"/>
+    </ajc-test>
+
+    <!-- overriding generic itd methods -->
+    <ajc-test dir="bugs160/simplejava" title="simple - i">
+      <compile files="SimpleI.java" options="-18"/>
+    </ajc-test>
+
+    <!-- check class file version is 62.0 (Java 18) -->
+    <ajc-test dir="bugs160/simplejava" title="simple - j">
+      <compile files="SimpleJ.java" options="-18"/>
+    </ajc-test>
+
+    <!-- check class file version is 62.0 (Java 18) -->
+    <ajc-test dir="bugs160/simplejava" title="simple - k">
+      <compile files="SimpleJ.java" options="-source 18"/>
+    </ajc-test>
+
+    <!-- check class file version is 49.0 -->
+    <ajc-test dir="bugs160/simplejava" title="simple - m">
+      <compile files="SimpleJ.java" options="-1.5"/>
+    </ajc-test>
+
+    <ajc-test dir="bugs160/simplejava" title="simple - n">
+      <compile files="SimpleN.java" options="-18"/>
+    </ajc-test>
+
+</suite>
index af1e21d29ef7bb7bc9a1499bcb4dc5c0f84193de..7e1c2a253da77076b8edfeb5c3473395eeecfc68 100644 (file)
@@ -194,6 +194,10 @@ public class LangUtil {
                return 18 <= vmVersion;
        }
 
+       public static boolean is19VMOrGreater() {
+               return 19 <= vmVersion;
+       }
+
        /**
         * Shorthand for "if null, throw IllegalArgumentException"
         *