[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] getting varargs to work in args and advise
|
Hello Ramnivas and Mathew,
Thank you very much for the answers! Ramnivas' solution worked like a charm
and suits my requirement. I tried out mathew's solution also as follows.
Showing only the relevant aspect:
aspect testProceed extends InitAspect{
pointcut catchAllMethods(String myStr, int[] intArr): catchClasses()&&
call(* myTestClass.setStrFld(String,int...)) && args(myStr, intArr) &&
within(myTestClass);
Object around(String myStr, int[] intArr):catchAllMethods(myStr, intArr) {
System.out.println("------------------------------------------------------------------");
System.out.println(thisJoinPoint);
System.out.println("around Advice: before proceed: ");
System.out.println("First string argument is " + myStr + ". Executing the
method now...");
Object result = proceed(myStr, intArr);
System.out.println("Result is " + result);
System.out.println("around Advice: After proceed: ");
System.out.println("------------------------------------------------------------------");
return result;
}
}
However, it doesn't seem to weave anything. Its probably due to what
Ramnivas was talking about that the pointcut call(*
myTestClass.setStrFld(String,int...)) will only match a method declared
'<ANY TYPE> myTestClass.setStrFld(String,int...)' and so my methods got
skipped.
Thanks to you guys again.
-Arvind
Couldn't you just bind directly in the expression with the following?
pointcut myPointcut(String aString, int[] anIntArray) :
call(* myTestClass.setStrFld(String,int...)) && args(aString,anIntArray);
I mean, you could still use thisJoinPoint.getArgs(), but you could
also just bind the arguments and let AspectJ do the work, right?
After all, int... gets compiled by Java to int[].
-matthew
On Mon, Mar 22, 2010 at 11:11 AM, Ramnivas Laddad
<ramnivas@xxxxxxxxxxxxxxx> wrote:
> call(* myTestClass.setStrFld(String,int...)) will select the following
> method
> class myTestClass {
> <ANY TYPE> setStrFld(String a, int... b) {
> }
> }
> You probably want to use thisJoinPoint.getArgs() in the advice to access
> all
> arguments.
> -Ramnivas>
--
View this message in context: http://old.nabble.com/getting-varargs-to-work-in-args-and-advise-tp27984480p27996324.html
Sent from the AspectJ - users mailing list archive at Nabble.com.