Ver código fonte

Add regression test for #257

Relates to #257.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tags/V1_9_20_1
Alexander Kriegisch 9 meses atrás
pai
commit
c708962d7e

+ 124
- 0
tests/bugs1921/gh_257/NegatedTypeAspect.aj Ver arquivo

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

+ 9
- 0
tests/src/test/java/org/aspectj/systemtest/ajc1920/Bugs1920Tests.java Ver arquivo

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

+ 41
- 0
tests/src/test/resources/org/aspectj/systemtest/ajc1920/ajc1920.xml Ver arquivo

@@ -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>

Carregando…
Cancelar
Salvar