mirror of
https://github.com/eclipse-aspectj/aspectj.git
synced 2024-07-25 22:34:45 +02:00
47 lines
1.1 KiB
Java
47 lines
1.1 KiB
Java
import java.lang.reflect.Method;
|
|
|
|
public class StackError {
|
|
public static void main(String args[]) {
|
|
new StackError().testEqualsNull();
|
|
}
|
|
|
|
void assertTrue(String msg, boolean b) {}
|
|
|
|
public void testEqualsNull() {
|
|
StackError one = new StackError();
|
|
StackError two = new StackError();
|
|
assertTrue("equal", one.equals(two)); // does not work
|
|
//boolean yes = one.equals(two); // works
|
|
}
|
|
|
|
public boolean equals(Object other) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
aspect EqualsContract {
|
|
pointcut equalsCall(Object thisOne, Object otherOne):
|
|
target(Object+) &&
|
|
|
|
target(thisOne) &&
|
|
call(public boolean equals(Object+)) &&
|
|
args(otherOne) &&
|
|
!within(EqualsContract);
|
|
|
|
boolean around(Object thisOne, Object otherOne):
|
|
equalsCall(thisOne, otherOne) {
|
|
boolean result = proceed(thisOne, otherOne);
|
|
Class cls = thisOne.getClass();
|
|
String name = cls.getName();
|
|
boolean hasHashCode = false;
|
|
try {
|
|
Method m = cls.getDeclaredMethod("hashCode", null);
|
|
String lookFor = "public int " + name + ".hashCode()";
|
|
hasHashCode = lookFor.equals(m.toString());
|
|
}
|
|
catch (NoSuchMethodException nsme) {
|
|
}
|
|
return result;
|
|
}
|
|
}
|