Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] AspectJ 5 now supports full source compilation of Java 5 programs

I don't normally post about developer builds, but we just got a successful 
build report through for one that might be of interest to many of you....

The most recent AspectJ 5 development build (available from the AspectJ 
download page) includes a full Java 5 compiler. This is a significant 
milestone on the road to the AspectJ 5 release. As an example of what we 
can now do, if you copy the contents attached below into a source file 
"SampleAspect.aj" and type at the command-line:

$> ajc -1.5 SimpleAspect.aj

$> java SimpleAspect

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())

Have fun seeing how many new Java 5 features you can spot in the program 
:)

We're well on our way now to an AspectJ 5 M2 release. We want to put some 
more testing in place around our annotation support (much easier now we 
can source compile), complete the binding of annotations as formals, and 
quite possibly add support for pertypewithin too (Andy's been busy whilst 
I've been working on the Java 5 integration....).

After M2, we'll be concentrating on pointcut, advice, and ITD support for 
generics as the last major Java 5 feature outstanding.

Have fun, Adrian.

============= Contents of file 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 }

============= End of file SimpleAspect.aj ========================

-- Adrian
Adrian_Colyer@xxxxxxxxxx


Back to the top