« 1427/1427 | Main | AspectJ launches campaign for world peace ;) »

January 17, 2005

AspectJ 5 now supports full source compilation of Java 5 programs

At last, all changes checked in and a healthy build report.

The latest AspectJ 5 development build (available from the download page at http://www.eclipse.org/aspectj now supports full source compilation of Java 5 programs. I've included below the source code for a simple aspect that exercises many of the new Java 5 features. If you cut-and-paste this into a file "SimpleAspect.aj" and then compile it with the latest AspectJ build:

ajc -1.5 SimpleAspect.aj

You'll see the output:

execution(void C.whatCsDoBest()) has an annotation. Varargs match: Autoboxing match Varargs match: java.lang.Object@1fee6fc java.lang.Object@1eed786 Covariant match on execution(C whoAmI()) Covariant match on execution(C whoAmI()) Covariant match on execution(D whoAmI())

(you need to look at the source of the program to make sense of this). Have fun reading through the sample and seeing how many Java 5 features you can spot!

Oh, and for those of you who were wondering about AJDT, Andy and Matt just sent me this screenshot. It shows AspectJ 5 integrated in Eclipse 3.1 M4 with full Java 5 support, eager parsing, and early error indications all working happily.


Here's the source for SimpleAspect.aj:

import java.util.List; @MyAnnotation public aspect SimpleAspect { int x; static List<String> myStringList; public static void main(String[] args) { for(String s:args) { System.out.println(s); myStringList.add(s); } C c = new C(); c.whatCsDoBest(); c.somethingElse(); c.myInt(5); c.somethingElse(new Object(), new Object()); c.whoAmI(); D d = new D(); d.whoAmI(); } pointcut annotatedExecution() : execution(@MyAnnotation * *(..)); before() : annotatedExecution() { System.out.println(thisJoinPoint + " has an annotation."); } before() : call(* myInt(..)) && args(int) { System.out.println("Autoboxing match"); } before(Object[] objects) : call(* somethingElse(Object...)) && args(objects) { System.out.print("Varargs match: "); for (Object o:objects) { System.out.print(o + " "); } System.out.println(); } before() : execution(C whoAmI()) { System.out.println("Covariant match on execution(C whoAmI())"); } before() : execution(D whoAmI()) { System.out.println("Covariant match on execution(D whoAmI())"); } } class C { @MyAnnotation public void whatCsDoBest() { } public void somethingElse(Object... objects) { } public C whoAmI() { return this; } Progress getAspectJ5Progress() { return Progress.EXCELLENT; } public int myInt(Integer i) { return i; } } class D extends C { public D whoAmI() { return this; } } @interface MyAnnotation {} enum Progress { OK, GOOD, VERYGOOD, EXCELLENT }

Posted by adrian at January 17, 2005 06:57 PM [permalink]

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?