Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Adding fields to a Class

No you can't do that.

However, if all your "classes that implement the run method" actually
implement Runnable and are weavable then you can just put an ITD on
Runnable.

Eric


2008/7/7 100ji <itz100ji@xxxxxxxxx>:
> Hi all,
>
> I want to add a ThreadLocal field to all the classes that contain the
> run method using aspects. Currently, I have the following aspect code
> that gives me a list of all classes that have the run method.
>
> public aspect AddTaintVarToThread {
>       pointcut startThreads(): execution(void *.run());
>
>       before(Object o) : startThreads() && target(o){
>       System.out.println("Hurray! Thread advice works!" +
> o.getClass().getName());
>       }
> }
>
> Once I get the class name, can I add a field to the class inside a
> method call in aspectj? Or more specifically, can I perform a
> inter-type declaration inside the advice? If I can't do it this way,
> are there better ways? I tried googling list archives but found
> nothing. Any pointers will prove helpful.
>
> TIA,
> -S-
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>



-- 
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada


Back to the top