Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] declare annotations within aop.xml

Hi Andy,

Thank you so much!

Unfortunately we have a little ltw vs. source weaving problem. Consider I have the following setup:

Source Weaving:
##############

package ch.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Anno {

}

package ch.aspects;

import ch.annotation.Anno;

public aspect TriggerAll {
declare @field : * *.myInt : @Anno;
before(Anno anno) : @annotation(anno) && set(* *.myInt) {
      System.out.println("Triggered");
    }
}

package ch.tests;

public class MyObject {
public int myInt;

public int getMyInt() {
return myInt;
}

public void setMyInt(int myInt) {
this.myInt = myInt;
}
}

package ch.tests;

public class Main {

public static void main(String[] args) {
MyObject mo = new MyObject();
mo.myInt = 13;
mo.setMyInt(13);
}
}

This outputs:
Triggered
Triggered

// two times "Triggered". As expected.

Now LTW:
########

Infos: 
- -javaagent:lib/aspectjweaver.jar is set
- the compiled aspect "TriggerAll.aj" is in the class searchpath (classpath) packed within a jar file.

public class MyObject2 {
public int myInt;

public int getMyInt() {
return myInt;
}

public void setMyInt(int myInt) {
this.myInt = myInt;
}
}

public class Main {

public static void main(String[] args) {
MyObject2 mo = new MyObject2();
mo.myInt = 13;
mo.setMyInt(13);
}
}

This outputs:
Triggered
// just one "Triggered" message. And this comes from mo.setMyInt(13). 

So mo.myInt = 13 does not trigger the pointcut!

Note: It has nothing to do with your recent changes. This happens on AspectJ 1.6.12.

Output form the weaving "process":

[AppClassLoader@5acac268] info AspectJ Weaver Version 1.6.12 built on Tuesday Oct 18, 2011 at 17:52:06 GMT
[AppClassLoader@5acac268] info register classloader sun.misc.Launcher$AppClassLoader@5acac268
[AppClassLoader@5acac268] info using configuration /path/META-INF/aop.xml
[AppClassLoader@5acac268] info using configuration /other-path/lib/TriggerAll.jar!/META-INF/aop-ajc.xml
[AppClassLoader@5acac268] info register aspect ch.aspects.TriggerAll
[AppClassLoader@5acac268] info weaver operating in reweavable mode.  Need to verify any required types exist.
[AppClassLoader@5acac268] debug weaving 'Main'
[AppClassLoader@5acac268] debug weaving 'MyObject2'
[AppClassLoader@5acac268] weaveinfo 'public int myInt' of type 'MyObject2' (MyObject2.java) is annotated with @Anno field annotation from 'ch.aspects.TriggerAll' (TriggerAll.aj:6)
[AppClassLoader@5acac268] weaveinfo Join point 'field-set(int MyObject2.myInt)' in Type 'MyObject2' (MyObject2.java:11) advised by before advice from 'ch.aspects.TriggerAll' (TriggerAll.aj:8)
[AppClassLoader@5acac268] debug weaving 'ch.aspects.TriggerAll'
[AppClassLoader@5acac268] info processing reweavable type ch.aspects.TriggerAll: ch\aspects\TriggerAll.aj
[AppClassLoader@5acac268] debug cannot weave 'org.aspectj.lang.NoAspectBoundException'
[AppClassLoader@5acac268] debug weaving 'ch.annotation.Anno'
[AppClassLoader@5acac268] debug weaving '$Proxy3'
Triggered

But again: Thanks very much for you effort,
domi


On Mon, Apr 2, 2012 at 11:28 PM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
Ok, implemented under https://bugs.eclipse.org/bugs/show_bug.cgi?id=375881

Dev build is on the downloads page or here:
http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/dev/aspectj-DEVELOPMENT-20120402142200.jar

It enables you to write declare-annotation segments in the
concrete-aspect section of aop.xml.  Here is one of my testcase XMLs:

<aspectj>
 <aspects>
   <concrete-aspect name="ConjuredUp">
     <declare-annotation field="* field1"
annotation="@Annot(someBoolean = false,   'abc'  )"/>
   </concrete-aspect>
 </aspects>

 <weaver options="-Xreweavable -verbose -XlazyTjp -showWeaveInfo">
   <include within="Hello6"/>
 </weaver>
</aspectj>

You can use field or method (to indicate declare @field or declare
@method), you cannot specify type yet.  All annotation value types are
supported apart from arrays and nested annotations.  Notice to avoid
the need to write double quotes as &quot;, you can use single quotes
for strings.  If you are using a class reference it must either be in
java.lang or fully qualified.

There is still more error checking code to go in but hopefully you can
use it as it is now.

cheers,
Andy

On 1 April 2012 07:51, Dominik Mengelt <dominik.mengelt@xxxxxxxxx> wrote:
> Andy,
>
> Thanks for your efforts. It is really appreciated.
>
>> I suspect markers wont be enough for you?  If so if you can tell me
>> the types of value (string,int, etc) you need to specify in the
>> annotation I'll do those first.
>
>
> Thats correct. I need the following types:
>
> - string
> - long
> - boolean
> - class
>
> It would be great to have a dev / nightly build with the ability to define
> annotations within the aop.xml
>
> thanks again,
> domi
>
>
> On Fri, Mar 30, 2012 at 8:58 PM, Andy Clement <andrew.clement@xxxxxxxxx>
> wrote:
>>
>> > So I'm curious if there are currently any plans to implement this
>> > feature or
>> > can anybody provide an alternate solution to this problem?
>>
>> I didn't have plans but as you are asking for it I've done a bit of
>> hacking this morning.  I can currently add annotations to
>> fields/methods but only simple marker annotations.
>>
>> I can do this
>>
>> <declare-annotation method="* foo(..))" annotation="@Marker"/>
>>
>> you cannot say
>>
>> annotation="@Marker(x=y,z=a)"
>>
>> I suspect markers wont be enough for you?  If so if you can tell me
>> the types of value (string,int, etc) you need to specify in the
>> annotation I'll do those first. (Obviously supporting all of them
>> would be nice, but not sure i have time to do that right now).
>>
>> Also declare @type won't work right now.
>>
>> cheers,
>> Andy
>>
>> On 30 March 2012 04:30, Dominik Mengelt <dominik.mengelt@xxxxxxxxx> wrote:
>> > Hi all,
>> >
>> > I'm interested in the possibility to declare field and method
>> > annotations
>> > directly on concrete aspects in an aop.xml. Basically I have the same
>> > "problem / feature request" as Thomas on the following post:
>> >
>> > http://aspectj.2085585.n4.nabble.com/abstract-quot-declare-method-quot-td3823887.html
>> >
>> > What I also found is the following enhancement request from Andrew:
>> > https://bugs.eclipse.org/bugs/show_bug.cgi?id=359159
>> >
>> > On the end of comment 1 Andrew says:
>> >
>> >> "A similar model could be extended to
>> >> support any declares too (anntation/parents)".
>> >
>> >
>> > So I'm curious if there are currently any plans to implement this
>> > feature or
>> > can anybody provide an alternate solution to this problem?
>> >
>> > Thanks in advance.
>> >
>> > Domi
>> >
>> > _______________________________________________
>> > aspectj-users mailing list
>> > aspectj-users@xxxxxxxxxxx
>> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
>> >
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top