[
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 | 
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