Note: Some of the following items, especially items in red, are based on my experience with aspectj 1.5.3.200611221118 (AJDT 1.4.1.200611230655) , JVM 1.5.0-b64, and JDT 3.2.0.v20060609m-F7snq1fxia-Z4XP.
- [Nested/Inner Aspect] Nested aspects must be static. An inner aspect has to be static, in order to get rid of the implicit “&& this()” which you get on a perthis-Aspect.
- [Aspect Extension] aspects may only extend abstract aspects. It is an error for a concrete aspect to extend another concrete aspect.
- [Aspect Instantiation] Because advice only runs in the context of an aspect instance, aspect instantiation indirectly controls when advice runs.
- [Aspect Instantiation] The criteria used to determine how an aspect is instantiated is inherited from its parent aspect. If the aspect has no parent aspect, then by default the aspect is a singleton aspect.
- [Aspect Instantiation] Static initialization occurs when the type is loaded (i.e., the Java VM
loads the resulting class file for Lolo). At that point, the implementation of the before calls the static method aspectOf to access the singleton instance of Lolo. - [Aspect Instantiation] You can get a NoAspectBoundException when there is a cycle in aspect initialization or static initialization (within one aspect, or between a chain of several aspects), most commonly when an aspect advises its own initializer.
- [Aspect Instantiation] During the constructor of an aspect, calling aspectOf() on that aspect would fail. Because at that moment, no aspect instance has been bound. It is the same reason why in an after() :(execution(AspectA.new())) advice, calling AspectA.aspectOf() would fail. In this case, instead, target can be used to expose the instance of AspectA.
- [Aspect Instantiation] ! Do not advise join points in cflowbelow(execution(AspectA.new())), there are bugs or flaws with aspectj which your advice may reproduce, especially when dynamically determined variable are involved in your advice body. Or don’t define your own aspect constructor, but just use the default aspect constructor, which would make your aspectj code more robust.
- [Advice Execution] ! Exception or Error thrown in advice “before(String[] args) : execution(public static void *.main(String[]))” can’t be captured!
- [Declaration] ! How to declare an error if some join points that are supposed to be captured are actually not captured?
- [PCD] A named pointcut may be defined in either a class or aspect, and is treated as a member of the class or aspect where it is found. As a member, it may have an access modifier such as public or private. Abstract pointcuts may only be declared within abstract aspects. For completeness, a pointcut with a declaration may be declared final. Though named pointcut declarations appear somewhat like method declarations, and can be overridden in subaspects, they cannot be overloaded.
- [PCD] call(Foo.new(..)) can’t be used together with target(*).
- [PCD] Rather than cflow, use lexical-structure based pointcuts, within or withincode, preferablely. It will make the cross-reference view of the AJDT more accurate and less time consuming.
to be continued…
Resources:
- aspectj doc
- aspectj-user-request mailing list

No comments:
Post a Comment