Summary: | @DeclareMixin feature | ||
---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | Andrew Clement <aclement> |
Component: | Compiler | Assignee: | aspectj inbox <aspectj-inbox> |
Status: | NEW --- | QA Contact: | |
Severity: | enhancement | ||
Priority: | P3 | ||
Version: | DEVELOPMENT | ||
Target Milestone: | 1.6.4 | ||
Hardware: | PC | ||
OS: | Windows NT | ||
Whiteboard: |
Description
Andrew Clement
2009-02-27 15:07:16 EST
First testcases are in and are passing. An example is attached below. It already supports the optional inclusion of an argument to the factory method - and if there is an argument specified (either Object or the type of the mixin target - which would be CaseA below) then the instance for which a delegate is being created will be passed in. Also the factory method can optionally be static or an instance method. For an instance method X.aspectOf() would be called to get the right instance for which to invoke the factory method. Although the basics are working, it is easy to make it fail as it is not policing much at the moment... --- import org.aspectj.lang.annotation.*; public class CaseA { public static void main(String[]argv) { CaseA ca = new CaseA(); ((I)ca).methodOne(); // will only succeed if mixin applied } } aspect X { @DeclareMixin("CaseA") public static I createImplementation() { System.out.println("Delegate factory invoked"); return new Implementation(); } } interface I { void methodOne(); } class Implementation implements I { public void methodOne() { System.out.println("methodOne running"); } } The code so far is in the AJDT 1.6.4 release candidate. There appears to be a problem with incremental compilation. The mixin maps to the creation under the covers of a declare parents, multiple method type mungers, and a method field munger. This is the same as for @DeclareParents. On the secondary compile it appears the class is still marked as implementing the interface but doesn't provide the implementation - so there is an error. I imagine @DeclareParents fails in the same way. Not currently sure of the fix. It seems that we are in trouble when we have this mixture of constructs that modify the type system (declare parents) and constructs that just weave (delegate mungers). Hmm, maybe the appropriate fix here is a new kind of type munger that doesn't affect the type system. It would be similar to declare parents but not applied until weaving. I imagine @DeclareParents, if it is kept, would need changing to use this new munger too. Incremental analysis modified in 2 ways: - created a subtype of DeclareParents called DeclareParentsMixin - this is created when @DeclareMixin is processed and only affects weaving, NOT compilation. - marked the MethodDelegateTypeMunger and associated delegate field host munger as being 'harmless' for compilation. incremental support committed for @DeclareMixin - only basic testing though. ought to move fixes into place for @DeclareParents too.. basic documentation written at : http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-itds.html needs another review before marking complete though, the Engleesh is dreadful it now polices that the instance target type for a mixin is compatible with the parameter type of the factory method (although it might put out an error once per method on the interface rather than just once for the declaration...). New weaveinfo message for a mixin. |