Browse Source

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>
tags/V1_9_21_1
Alexander Kriegisch 2 months ago
parent
commit
c028a47269

+ 53
- 0
tests/features1921/java21/UnderscoreInPointcutAspect.aj View File

@@ -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);
}
}

+ 12
- 0
tests/src/test/java/org/aspectj/systemtest/ajc1921/Java21PreviewFeaturesTests.java View File

@@ -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");
}

+ 35
- 0
tests/src/test/resources/org/aspectj/systemtest/ajc1921/ajc1921.xml View File

@@ -296,6 +296,41 @@
</run>
</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 -->

Loading…
Cancel
Save