[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] How to resolve real execution signature for call joinpoint
|
>> Actually and unfortunately, contrary to your assumption
>> Signature.getDeclaringType() does not yield the same type as
>> thisJoinPoint.getTarget().getClass().
>
> That isn't exactly what I was saying. I was saying this new method
> you wanted to add, how would its return value differ from
> thisJoinPoint.getTarget().getClass() - I know that getDeclaringType()
> would be different from thisJoinPoint.getTarget() since the former is
> based on the type referenced in the invoke instruction (it is not
> based on the type of the target, even if that could be statically
> analyzed) whilst the second is based on the runtime types flowing
> around. From your test program it seems you want this new method on
> tip to return the actual declaring class of the method involved?
>
> It all depends what you want at the join point - as your test program
> shows you can dig around for whatever you want (if you really want
> the declaring class of the method involved, you can find it). I could
> push helper code into thisJoinPoint for some of this but I need
> concrete use cases and votes on requests for it.
Well, I thought my sample code exactly shows what I need (last table
column) and also a use case. Your guess is right, I would like to be
able to call something like
Class<?> thisJoinPointStaticPart.getActualDeclaringClass()
in order to determine which method is actually targeted by e.g. the call
joinpoint. The use case is quite trivial: I can log it. As can be seen
when running my sample code - feel free to re-use it as a test case -
neither target.getClass().getName() nor
methodSignature.getDeclaringTypeName() actually tell me the truth. E.g.
in my code for the call
jdkList.add("one");
target.getClass().getName() yields de.scrum_master.app.MyList because we
are dealing with an instance of MyList. But the result is wrong because
there is no such method as de.scrum_master.app.MyList.add(*).
methodSignature.getDeclaringTypeName() yields java.util.List because the
MyList instance is actually assigned to a variable of type List. But the
result is also wrong because there is no such method as
java.util.List.add(*).
What actually gets executed is what I determine tediously via reflection
and print in column "Real method declaring type":
java.util.ArrayList.add(*) - that is where the executed code is really
defined. If I as a user want to know that, currently I have no other
choice but to use reflection. I might not even notice the incorrect
result if I do not pay attention and naively expect
thisJoinPointStaticPart.toString() to yield the desired result.
I hope it gets clearer now. :-)