[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [aspectj-users] method call and annotated field
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Rifflard Mickaël wrote:
> How to express this : Match a method call when this one is perform
> on an annotated field ?
Hi, Rifflard. Correct me if I am wrong, but did we not discuss the
same question about 6 weeks ago, when you posted the very same code
snippet?
- ----------------------------------------------------------------------
- ----------
From: aspectj-users-admin@xxxxxxxxxxx
[mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Adrian Colyer
Sent: Donnerstag, 24. Februar 2005 16:53
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Match a method call on a class field
with specific annotation
This is an interesting use case because.... there's no easy way to do
this.
At a call join point, we know about the the *caller*, and the
*callee*, we know the static context in which the call is being made
(within, withincode), and the dynamic context in which the call is
being made (cflow[below]), so whilst we can say:
"any call where the type of the target of the call has an annotation
@ABC..."
we don't have a way to say:
"any call where the target of the call is currently refered to by a
member variable, and that member variable has an annotation of type
@ABC..."
The closest thing you can say is
"any access to a field with annotation @MyAnnotation" :
get(@MyAnnotation * *)
Using reflection it should be possible, but awkward to get closer
what you want:
pointcut annotatedFieldCall() : call(* *(..)) &&
if(calleeIsAFieldWithMyAnnotation(thisJoinPoint);
private static boolean calleeIsAFieldWithMyAnnotation(JoinPoint tjp)
{
/ / pseudo-code...
Object obj = tjp.getThis();
for-all (Field field : obj.getClass().getDeclaredFields()) {
if (field.hasAnnotation(MyAnnotation.class) return true;
}
return false;
}
but it's not pretty.... (and only works for fields defined within the
calling class).
If you *could* write a pointcut to match this, how would you want it
to look?
Eric
- --
Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3
iQA/AwUBQlb++cwiFCm7RlWCEQK0FQCeLwPKARAzcpP3jWXjPQPfadEhrMoAoMB5
NFrcc8SAGAiyQxT2Bpl5V2/G
=aJGe
-----END PGP SIGNATURE-----