Skip to content

Commit

Permalink
Add regression test for #257
Browse files Browse the repository at this point in the history
Relates to #257.

Signed-off-by: Alexander Kriegisch <[email protected]>
  • Loading branch information
kriegaex committed Aug 23, 2023
1 parent 2af1b06 commit c708962
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
124 changes: 124 additions & 0 deletions tests/bugs1921/gh_257/NegatedTypeAspect.aj
Original file line number Diff line number Diff line change
@@ -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 + '\'' + ')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public void test_Spring_GitHub_27761() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit c708962

Please sign in to comment.