[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Retrieving value whilst using the "get" primitive
|
I feel there ought to be a neater way I can't quite think of, but
these are options:
import org.aspectj.lang.reflect.*;
public aspect Foo {
boolean around(): get(boolean value) {
boolean b = proceed();
System.out.println("around advice: "+b);
return b;
}
after(C target): get(boolean C.value) && target(target) {
try {
boolean b =
((FieldSignature)thisJoinPoint.getSignature()).getField().getBoolean(target);
System.out.println("before advice: "+b);
} catch (Exception e) {}
}
public static void main(String []argv) {
new C().run();
}
}
class C {
boolean value = true;
public void run() {
boolean b = value;
value= false;
b = value;
}
}
Andy
On 7 January 2011 08:10, tomansley <tomansley@xxxxxxxxx> wrote:
>
> (NOTE: If anybody has a way of being able to do meaningful searches on "get"
> and "set" then let me know. I have searched the web for my question below
> and am stymied by how to actually perform the search)
>
> Hi all,
>
> I am playing around with the "get" and "set" primitives and am not having
> luck gaining access to the variable that is being retrieved with the "get".
> The set works fine. The following code allows me to gain access to the
> variable (isCacheEnabled) that is being set along with the new value that
> the value is being set to.
>
> before(Boolean newval): set(Boolean ReferenceDataWorker+.isCacheEnabled) &&
> args(newval) {
> System.out.println("isCacheEnabled has been set and the new value is " +
> newval);
> }
>
> This works great and I am able to print out the new value that
> isCacheEnabled is being set to. The same cannot be said for when I use the
> "get" primitive. Obviously I do not have the argument available since there
> is no argument. I am trying to print out the value of isCacheEnabled before
> (or after for that matter) its retrieved.
>
> before(): get(Boolean ReferenceDataWorker+.isCacheEnabled) {
> System.out.println("isCacheEnabled has been retrieved and the value is " +
> isCacheEnabled);
> }
>
> My question is: How do I gain access to the "isCacheEnabled" variable when
> using the "get" primitive? If anyone has anymore useful tips on gaining
> access to variables then that would be great as well. I have tried
> understanding "this", "target" etc but I think I am missing something
> fundamental.
>
> Any help greatly appreciated.
>
> Cheers
> Tom
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/Retrieving-value-whilst-using-the-get-primitive-tp3179362p3179362.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>