From c708962d7e0341133790bf7315257db7aa5acc86 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Wed, 23 Aug 2023 09:23:38 +0700 Subject: Add regression test for #257 Relates to #257. Signed-off-by: Alexander Kriegisch --- tests/bugs1921/gh_257/NegatedTypeAspect.aj | 124 +++++++++++++++++++++ .../aspectj/systemtest/ajc1920/Bugs1920Tests.java | 9 ++ .../org/aspectj/systemtest/ajc1920/ajc1920.xml | 41 +++++++ 3 files changed, 174 insertions(+) create mode 100644 tests/bugs1921/gh_257/NegatedTypeAspect.aj diff --git a/tests/bugs1921/gh_257/NegatedTypeAspect.aj b/tests/bugs1921/gh_257/NegatedTypeAspect.aj new file mode 100644 index 000000000..8bb6a18b3 --- /dev/null +++ b/tests/bugs1921/gh_257/NegatedTypeAspect.aj @@ -0,0 +1,124 @@ +import java.util.Arrays; + +public aspect NegatedTypeAspect { + before(): execution(!void get*()) { + System.out.println("[GETTER] " + thisJoinPoint); + } + + before(): execution(!String get*()) { + System.out.println("[NON-STRING GETTER] " + thisJoinPoint); + } + + before(): execution(String[] get*()) { + System.out.println("[STRING-ARRAY GETTER] " + thisJoinPoint); + } + + before(): execution(!String[] get*()) { + System.out.println("[NON-STRING-ARRAY GETTER] " + thisJoinPoint); + } + + before(): execution(!String[][] get*()) { + System.out.println("[NON-STRING-ARRAY-ARRAY GETTER] " + thisJoinPoint); + } + + before(): execution(void set*(*)) { + System.out.println("[SETTER] " + thisJoinPoint); + } + + public static void main(String[] args) { + Person person = new Person(); + person.setId(11); + person.setFirstName("Marie"); + person.setLastName("Curie"); + System.out.println(person); + person.getId(); + person.getFirstName(); + person.getLastName(); + System.out.println(person.getFullName(false)); + person.setFullName("Albert Einstein"); + person.setId(22); + System.out.println(person); + System.out.println(person.getFullName(true)); + person.getVoid(); + System.out.println(Arrays.deepToString(person.getStringArray())); + System.out.println(Arrays.deepToString(person.getStringArrayArray())); + System.out.println(person.setSomething("something")); + } +} + +class Person { + private int id; + private String lastName; + private String firstName; + + // Bean getters/setters, matched by aspect + + // Non-string getter, matched by corresponding pointcut + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + // Non-string getter (String[] != String) + public String[] getStringArray() { + return new String[] {"Hello", "world"}; + } + + // Non-string, non-string-array getter (String[] != String, String[] != String[][]) + public String[][] getStringArrayArray() { + return new String[][] {{"Hello", "world"}, {"Hallo", "Welt"}}; + } + + // Non-bean getters/setters, not matched by aspect + + public String getFullName(boolean lastNameFirst) { + return lastNameFirst + ? lastName + ", " + firstName + : firstName + " " + lastName; + } + + public void setFullName(String fullName) { + boolean lastNameFirst = fullName.contains(","); + String[] nameParts = fullName.split("[, ]+"); + if (lastNameFirst) { + firstName = nameParts[1]; + lastName = nameParts[0]; + } else { + firstName = nameParts[0]; + lastName = nameParts[1]; + } + } + + public String setSomething(String something) { + return "AspectJ rules!"; + } + + // Non-string getter, matched by corresponding pointcut + public void getVoid() {} + + // Other methods, not matched by aspect + + @Override + public String toString() { + return "Person(" + "id=" + id + ", lastName='" + lastName + '\'' + ", firstName='" + firstName + '\'' + ')'; + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java index e1f3fa1ca..b1942f11b 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java @@ -79,6 +79,15 @@ public class Bugs1920Tests extends XMLBasedAjcTestCase { runTest("do not match bridge methods"); } + /** + * In 1.9.20, a regression bug occurred, matching negated types like '!void' and '!String' incorrectly. + *

+ * See GitHub issue 257. + */ + public void test_GitHub_257() { + runTest("handle negated type patterns correctly"); + } + public static Test suite() { return XMLBasedAjcTestCase.loadSuite(Bugs1920Tests.class); } diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml index 89c9b5f41..86fa7db02 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml @@ -434,4 +434,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3