aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2023-08-23 09:23:38 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2023-08-23 10:39:24 +0700
commitc708962d7e0341133790bf7315257db7aa5acc86 (patch)
tree3ec1d766c31843dab259ac4f1a4ac0790b0d380c
parent2af1b06b6a9439109520b249b5e44dfc1375c199 (diff)
downloadaspectj-c708962d7e0341133790bf7315257db7aa5acc86.tar.gz
aspectj-c708962d7e0341133790bf7315257db7aa5acc86.zip
Add regression test for #257
Relates to #257. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
-rw-r--r--tests/bugs1921/gh_257/NegatedTypeAspect.aj124
-rw-r--r--tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java9
-rw-r--r--tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml41
3 files changed, 174 insertions, 0 deletions
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.
+ * <p>
+ * See <a href="https://github.com/eclipse-aspectj/aspectj/issues/257">GitHub issue 257</a>.
+ */
+ 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 @@
</run>
</ajc-test>
+ <!-- https://github.com/eclipse-aspectj/aspectj/issues/257 -->
+ <ajc-test dir="bugs1921/gh_257" vm="8" title="handle negated type patterns correctly">
+ <compile files="NegatedTypeAspect.aj" options="-8"/>
+ <run class="NegatedTypeAspect">
+ <stdout>
+ <line text="[SETTER] execution(void Person.setId(int))"/>
+ <line text="[SETTER] execution(void Person.setFirstName(String))"/>
+ <line text="[SETTER] execution(void Person.setLastName(String))"/>
+ <line text="Person(id=11, lastName='Curie', firstName='Marie')"/>
+ <line text="[GETTER] execution(int Person.getId())"/>
+ <line text="[NON-STRING GETTER] execution(int Person.getId())"/>
+ <line text="[NON-STRING-ARRAY GETTER] execution(int Person.getId())"/>
+ <line text="[NON-STRING-ARRAY-ARRAY GETTER] execution(int Person.getId())"/>
+ <line text="[GETTER] execution(String Person.getFirstName())"/>
+ <line text="[NON-STRING-ARRAY GETTER] execution(String Person.getFirstName())"/>
+ <line text="[NON-STRING-ARRAY-ARRAY GETTER] execution(String Person.getFirstName())"/>
+ <line text="[GETTER] execution(String Person.getLastName())"/>
+ <line text="[NON-STRING-ARRAY GETTER] execution(String Person.getLastName())"/>
+ <line text="[NON-STRING-ARRAY-ARRAY GETTER] execution(String Person.getLastName())"/>
+ <line text="Marie Curie"/>
+ <line text="[SETTER] execution(void Person.setFullName(String))"/>
+ <line text="[SETTER] execution(void Person.setId(int))"/>
+ <line text="Person(id=22, lastName='Einstein', firstName='Albert')"/>
+ <line text="Einstein, Albert"/>
+ <line text="[NON-STRING GETTER] execution(void Person.getVoid())"/>
+ <line text="[NON-STRING-ARRAY GETTER] execution(void Person.getVoid())"/>
+ <line text="[NON-STRING-ARRAY-ARRAY GETTER] execution(void Person.getVoid())"/>
+ <line text="[GETTER] execution(String[] Person.getStringArray())"/>
+ <line text="[NON-STRING GETTER] execution(String[] Person.getStringArray())"/>
+ <line text="[STRING-ARRAY GETTER] execution(String[] Person.getStringArray())"/>
+ <line text="[NON-STRING-ARRAY-ARRAY GETTER] execution(String[] Person.getStringArray())"/>
+ <line text="[Hello, world]"/>
+ <line text="[GETTER] execution(String[][] Person.getStringArrayArray())"/>
+ <line text="[NON-STRING GETTER] execution(String[][] Person.getStringArrayArray())"/>
+ <line text="[NON-STRING-ARRAY GETTER] execution(String[][] Person.getStringArrayArray())"/>
+ <line text="[[Hello, world], [Hallo, Welt]]"/>
+ <line text="AspectJ rules!"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
</suite>