Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Instanciate an aspect for each object with specific annotation


Without testing it myself, I wouldn't be at all surprised if this was a bug. We haven't completed work on generics in AspectJ 5 yet, so whilst uses of generics in fields, methods, and advice bodies I would expect to be working fine, matching generic signatures using pointcuts is not yet possible and we have not yet done any testing on ITDs with generic types. I suspect your ITD of XmlState._fields is the problem. We plan to provide full support for generics in the M3 build.

Peddling hard!

-- Adrian
Adrian_Colyer@xxxxxxxxxx



Rifflard Mickaël <Mickael.Rifflard@xxxxxxxxxxxxxx>
Sent by: aspectj-users-admin@xxxxxxxxxxx

08/02/2005 17:20

Please respond to
aspectj-users@xxxxxxxxxxx

To
<aspectj-users@xxxxxxxxxxx>
cc
Subject
RE: [aspectj-users] Instanciate an aspect for each object with specific annotation





Hi Ramnivas,

I tested your solution.

public aspect Persistence {

                declare parents: @Xml * implements XmlState;

                public interface XmlState {}
               
                private HashMap<String,Object> XmlState._fields = new HashMap<String,Object>(5);

                after(XmlState xmls) : @this(@Xml) && this(xmls) {
                                 xmls._fields.put("testKey",new Object());
                }
}

This one seems to be correct in a syntax point of view but when I compile it, I receive this error :

                The method put(K, V) in the type HashMap<K,V> is not applicable for the arguments (String, Object)

I will search if I find something but if somenone have got an idea...
               
Thanks,

Mickaël Rifflard
(Atos Origin)


-----Message d'origine-----
De : aspectj-users-admin@xxxxxxxxxxx [mailto:aspectj-users-admin@xxxxxxxxxxx]De la part de Ramnivas Laddad
Envoyé : lundi 7 février 2005 18:41
À : aspectj-users@xxxxxxxxxxx
Objet : Re: [aspectj-users] Instanciate an aspect for each object with specific annotation


Hi Rifflard,

I think ITD will work better for your situation. Perthis() association is a powerful concepts, especially when creating reusable aspects, but it is more complex construct for what you are trying to achieve.

Here is what I would do (assuming it works in the latest milestone version):

public aspect MyAspect {
                declare parents: @Xml * implements XmlState;

                public interface XmlState {
                }

                private Map XmlState._m;
                private long XmlState._l;

                // advice etc...
}
-Ramnivas


===
Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com


Rifflard Mickaël wrote:
Hi Ramnivas,

Thanks for your response.

My goal is simple :
               
                I want to add a Map and a long fields to all objects instance with specific annotation.
                This fields must be instance fields, not class fields.

Here is my current implementation :

                @Xml
                public class MyClass {

                                 ...

                                 (private Map _m;                 <- Added with an aspect because MyClass contains @Xml annotation)
                                 (private long _l;                 <- Added with an aspect because MyClass contains @Xml annotation)
                }

                public aspect MyAspect perthis(within(@Xml *)) {

                                 private Map _m;
                                 private long _l;
                                 
                                 ...
                }

Your solution is it the following one :

                public aspect MyAspect {

                                 private Map MyClass._m;
                                 private long MyClass._l;

                                 pointcut myPointcut : this(@Xml *) && ... { ... }

                                 ...
                }

Then, what is the best pattern ? Wich solution is better from a performance point of view ?

Best regards,

Mickaël Rifflard
(Atos Origin)


-----Message d'origine-----
De : aspectj-users-admin@xxxxxxxxxxx
[mailto:aspectj-users-admin@xxxxxxxxxxx]De la part de Ramnivas Laddad
Envoyé : vendredi 4 février 2005 19:21
À : aspectj-users@xxxxxxxxxxx
Objet : Re: [aspectj-users] Instanciate an aspect for each object with
specific annotation


I will probably use the following _expression_:

public aspect A perthis(this(@MyAnnotation *)) { ... }

I guess the following should work, too:
public aspect A perthis(@this(@MyAnnotation)) { ... }

(or if the syntax change per my email a few days back is accepted:
public aspect A perthis(@this(MyAnnotation)) { ... }
)

This will spare the nested and inner types defined within classes that carry @MyAnnotations.

Can you provide background of why you need per-instance association? In many cases, you are better of using inter-type declarations instead of perthis() and pertarget().

-Ramnivas

===

Ramnivas Laddad,
Author, AspectJ in Action
http://ramnivas.com


Rifflard Mickaël wrote:

 
Hi all,

I want to instanciate an aspect instance with each instance of an object with specific annotation.

Exemple :

                @MyAnnotation
                public class O { ... }

                public class Main {

                                 public static void main(String[] args) {
                                                  new O();                 => New aspect instance
                                                  new O();                 => New aspect instance
                                 }
                }

To express this, I write

                public aspect A perthis(within(@MyAnnotation *)) { ... }

This _expression_ works but I wonder if this one is always the best with the addition of @this, @annotation , ...

What do you think about it ?

Regards,

Mickaël Rifflard
(Atos Origin)


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users



   
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users

 
_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx http://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top