[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Binary-weaving method annotation into a class in a jar not working - is this a bug?
|
It sounds like a bug worth reporting.
http://dev.eclipse.org/bugs/enter_bug.cgi?product=AspectJ
I reproduced it on the command-line with junit.jar, but not using
the simple test case below. Perhaps someone could isolate the
difference...
Wes
src $ cat t/Super.java
package t;
public class Super {
public void setUp() {}
}
src $ cat t/TC.java
package t;
public class TC extends Super {
public static void main(String[] a) { new TC().setUp(); }
}
aspect MyTestAspect {
public @interface MyAnnotation {}
declare @method : void Super.setUp() : @MyAnnotation;
before() : execution(@MyAnnotation void *()) {
System.err.println("here: " + thisJoinPoint);
}
}
src $ aspectj-1.5 -1.5 t/Super.java -outjar super.jar
src $ aspectj-1.5 -1.5 t/TC.java -injars super.jar -outjar app.jar
src $ j5 -classpath "app.jar;$CLASSPATH" t.TC
here: execution(void t.Super.setUp())
> ------------Original Message------------
> From: "Monal Daxini" <monaldax@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Sun, Sep-24-2006 9:37 PM
> Subject: [aspectj-users] Binary-weaving method annotation into a class in a jar not working - is this a bug?
>
> Hi,
>
> Environment:
> AspectJ 1.5.2, AspectJ Eclipse Plugin 1.4, Eclipse 3.2, Sun JDK 1.5
>
> I am trying to add my custom annotation @MyAnnotation on the
> junit.framework.TestCase.setUp() method. I have tried both Load Time
> Weaving and compile time weaving but I was unsuccessful in weaving the
> annotation. However, I was able to add a new method into the
> junit.framework.TestCase. Details as below...
>
> import junit.framework.TestCase;
> 1 public aspect MyTestAspect {
> 2 @MyAnnotation
> 3 public static void TestCase.testCaseSetUp() {
> 4 }
> 5 // declare @method : * TestCase.testCaseSetUp() :
> @MyAnnotation;
> 6 declare @method : * TestCase.setUp() : @MyAnnotation;
> 7 }
> 8 }
>
> Line number 3 adds a method into the TestCase class (see the test code
> below that uses reflection to verify this). However it does not add
> the annotation on line 1 to the testCaseSetUp method. Now commenting
> line 2 and un-commenting line 5 does not add the annotation either.
> This true even when testCaseSetUp method is non-static. Along the same
> lines line 6 does not add the annotation to the TestCase.setUp method.
> I added junit.jar to AspectJ inpath, I also attached the junit source,
> but no luck. I also tried using an expanded version of the junit.jar
> classes.
>
> INTERESTING: I then added the junit source directly as a source folder
> to my project, and then it works - testCaseSetUp() method is added to
> TestCase along with the @MyAnnotation. Commenting line 2 and
> uncommenting line 3 also results in the @MyAnnotation being
> introduced.
>
> So is there a bug currently that prevents the @MyAnnotation from being
> introduced while binary-weaving stand alone classes or classes in a
> jar? If not, could you please tell me what I need to do to make it
> work so that I can weave my custom method-level annotations in a class
> file.
>
> // Aspect verification class
> public class InheritAnnot extends TestCase {
>
> public static void main(String[] args) throws Throwable {
> InheritAnnot ia = new InheritAnnot();
> Class curClazz = ia.getClass();
> do {
> System.out.println("Current Class: " +
> curClazz.getName());
> Method[] ms = curClazz.getDeclaredMethods();
> for(Method m : ms) {
>
> if(m.getName().equalsIgnoreCase("testCaseSetUp")) {
> System.out.println(" ----
> Method Name: " + m.getName());
> m.invoke(curClazz, new
> Object[0]);
> }
> Annotation[] mannots =
> m.getAnnotations();
> for(Annotation ma : mannots) {
> System.out.println("@ Found
> annotation - " + ma
>
> + " in Class: " + curClazz.getName()
>
> + " on method: " + m.getName());
> }
> }
> } while((curClazz = curClazz.getSuperclass()) != null);
> }
> }
>
> Thank you
> Monal
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>