From c028a472697a6934a538f2d61cb9974a66421fb1 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Tue, 13 Feb 2024 17:05:04 +0700 Subject: [PATCH] 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 --- .../java21/UnderscoreInPointcutAspect.aj | 53 +++++++++++++++++++ .../ajc1921/Java21PreviewFeaturesTests.java | 12 +++++ .../aspectj/systemtest/ajc1921/ajc1921.xml | 35 ++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 tests/features1921/java21/UnderscoreInPointcutAspect.aj 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 @@ -296,6 +296,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5