Community
Participate
Working Groups
I recognized following problem, while writing some aspects for easy creation of mocks. Sometimes the static parts of two joinpoints do not equal, even if they were captured from the same joinpoints. (e.g. by an before after and around advice). After a short look in the codebase of staticpart, I recognized that there is no equals method defined there. So my naïve suggestion would be to overwrite the equals method, relying on an equivalence of the toString() method. This would conclude that also the .hashcode must be overwritten. This method could simply retrun the hascode of the toString() method. My second suggestions would be to cache the result of the toString method in this class, if the creation of the toString method is expensive. If you would be interested in a patch following one or the other approach please let me know. Cheers Arno Schmidmeier http:://www.aspectsoft.com blog: arno@blogger.de
There has been a lengthy discussion on this subject http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg06808.html and there are two enhancements as well: Bug 89009 "Add ability to associate user object to join point" and Bug 160296 "Custom JoinPoint factory". The issue of staticpart equality has been raised before (http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg06926.html) but I don't quite understand your problem. Can you post an example?
The problem seems to be: -that joinPointStaticPart does not implement the equals method -and that multiple staticJoinpoint-objects for each Joinpoint might created, if several aspects advice the same join point. So my naive suggestion would look like //written without a compiler at hand. public boolean equals(Object target){ if (target==null) return false; if (target instanceof thisJoinPointStaticPart) return (toString().equals(target.toString())); return super(target); } //required by some Java Specification public integer hashcode(){ return toString().hashcode(); }
(In reply to comment #2) > The problem seems to be: > -that joinPointStaticPart does not implement the equals method > -and that multiple staticJoinpoint-objects for each Joinpoint might created, if > several aspects advice the same join point. As I said in the aspectj-users discussion JoinPoint.StaticPart instances are transient singletons created and managed by AspectJ (in fact by code generated by the weaver). You should never get 2 instances of an object that represents a join point so there should be no reason to compare them. The situation is different for JoinPoint instances.