aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2024-02-13 17:05:04 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2024-02-13 17:05:04 +0700
commitc028a472697a6934a538f2d61cb9974a66421fb1 (patch)
treebd70e5b647c2e1ad6fee7d6b983d82416b36d4be /tests
parent8478d33a68781b3dd950224eb3ebbec6727bfc8e (diff)
downloadaspectj-c028a472697a6934a538f2d61cb9974a66421fb1.tar.gz
aspectj-c028a472697a6934a538f2d61cb9974a66421fb1.zip
Add tests for underscores in pointcuts on Java 21+
See also: https://github.com/eclipse-aspectj/eclipse.jdt.core/commit/5d2f2aecd2 Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'tests')
-rw-r--r--tests/features1921/java21/UnderscoreInPointcutAspect.aj53
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java12
-rw-r--r--tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml35
3 files changed, 100 insertions, 0 deletions
diff --git a/tests/features1921/java21/UnderscoreInPointcutAspect.aj b/tests/features1921/java21/UnderscoreInPointcutAspect.aj
new file mode 100644
index 000000000..41ed65d15
--- /dev/null
+++ b/tests/features1921/java21/UnderscoreInPointcutAspect.aj
@@ -0,0 +1,53 @@
+public aspect UnderscoreInPointcutAspect {
+ public static void main(String[] args) {
+ UnderTest u = new UnderTest();
+ System.out.println(u._add(12, 4));
+ System.out.println(u._subtract(12, 4));
+ System.out.println(u.multiply_(12, 4));
+ System.out.println(u.divide_(12, 4));
+ System.out.println(u.power_of(3, 3));
+ System.out.println(u.squareRoot(49));
+ }
+
+ before(int a, int b) : execution(* _*(..)) && args(a, b) {
+ System.out.println("[starts with underscore] " + thisJoinPoint + " -> " + a + ", " + b);
+ }
+
+ before(int a, int b) : execution(* *_(..)) && args(a, b) {
+ System.out.println("[ends with underscore] " + thisJoinPoint + " -> " + a + ", " + b);
+ }
+
+ before(int a, int b) : execution(* *_*(..)) && args(a, b) {
+ System.out.println("[contains underscore] " + thisJoinPoint + " -> " + a + ", " + b);
+ }
+
+ before(int a) : execution(* *(..)) && !execution(* *_*(..)) && args(a) {
+ System.out.println("[no underscore] " + thisJoinPoint + " -> " + a);
+ }
+}
+
+class UnderTest {
+ int _add(int a, int b) {
+ return a + b;
+ }
+
+ int _subtract(int a, int b) {
+ return a - b;
+ }
+
+ int multiply_(int a, int b) {
+ return a * b;
+ }
+
+ int divide_(int a, int b) {
+ return a / b;
+ }
+
+ int power_of(int base, int exponent) {
+ return (int) Math.pow(base, exponent);
+ }
+
+ int squareRoot(int a) {
+ return (int) Math.sqrt(a);
+ }
+}
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java
index 79ce4c6cb..255583efd 100644
--- a/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java
+++ b/tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java
@@ -8,6 +8,7 @@
package org.aspectj.systemtest.ajc1921;
import junit.framework.Test;
+import org.aspectj.systemtest.ajc10x.Ajc10xTests;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.testing.XMLBasedAjcTestCaseForJava21Only;
@@ -46,6 +47,17 @@ public class Java21PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava21Only
System.out.println("Unnamed patterns still are not implemented with the Java 21 release Eclipse 2023-12 (4.30)");
}
+ /**
+ * Same as {@link Ajc10xTests#test052()}, but compiled to target 21 instead of 1.4
+ */
+ public void testUnderscoreInPointcutPattern1() {
+ runTest("underscore can still be used in pointcut patterns on Java 21+ - 1");
+ }
+
+ public void testUnderscoreInPointcutPattern2() {
+ runTest("underscore can still be used in pointcut patterns on Java 21+ - 2");
+ }
+
public void testNamedClassWithSimpleMainMethod() {
runTest("named class with simple main method");
}
diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml
index bac8a1576..d5d4c1c69 100644
--- a/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml
+++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml
@@ -297,6 +297,41 @@
</ajc-test>
<!-- Java 21 preview -->
+ <ajc-test dir="new" vm="21" title="underscore can still be used in pointcut patterns on Java 21+ - 1">
+ <compile files="NotCharInPointcut.java" options="--enable-preview -21">
+ <message kind="warning" line="51" text="advice defined in A has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="warning" line="52" text="advice defined in A has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="warning" line="53" text="advice defined in A has not been applied [Xlint:adviceDidNotMatch]"/>
+ </compile>
+ <run class="NotCharInPointcut" vmargs="--enable-preview"/>
+ </ajc-test>
+
+ <!-- Java 21 preview -->
+ <ajc-test dir="features1921/java21" vm="21" title="underscore can still be used in pointcut patterns on Java 21+ - 2">
+ <compile files="UnderscoreInPointcutAspect.aj" options="--enable-preview -21"/>
+ <run class="UnderscoreInPointcutAspect" vmargs="--enable-preview">
+ <stdout>
+ <line text="[starts with underscore] execution(int UnderTest._add(int, int)) -> 12, 4"/>
+ <line text="[contains underscore] execution(int UnderTest._add(int, int)) -> 12, 4"/>
+ <line text="16"/>
+ <line text="[starts with underscore] execution(int UnderTest._subtract(int, int)) -> 12, 4"/>
+ <line text="[contains underscore] execution(int UnderTest._subtract(int, int)) -> 12, 4"/>
+ <line text="8"/>
+ <line text="[ends with underscore] execution(int UnderTest.multiply_(int, int)) -> 12, 4"/>
+ <line text="[contains underscore] execution(int UnderTest.multiply_(int, int)) -> 12, 4"/>
+ <line text="48"/>
+ <line text="[ends with underscore] execution(int UnderTest.divide_(int, int)) -> 12, 4"/>
+ <line text="[contains underscore] execution(int UnderTest.divide_(int, int)) -> 12, 4"/>
+ <line text="3"/>
+ <line text="[contains underscore] execution(int UnderTest.power_of(int, int)) -> 3, 3"/>
+ <line text="27"/>
+ <line text="[no underscore] execution(int UnderTest.squareRoot(int)) -> 49"/>
+ <line text="7"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <!-- Java 21 preview -->
<ajc-test dir="features1921/java21" vm="21" title="named class with simple main method">
<!-- Compiles without preview mode, but needs preview mode to run -->
<compile files="NamedClassWithSimpleMainMethodPreview1.java" options="-21"/>