[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
Re: [aspectj-users] How to trace a static method with varargs ?
|
- From: Andy Clement <andrew.clement@xxxxxxxxx>
- Date: Tue, 18 May 2010 08:52:25 -0700
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=Osabn7Vautb0GpnCyBSswEAxdmTXY5C+KnXHiR7SqB8=; b=tqRCnGgEt1wa3/6i6tqki2zPvT6rkNxNihhSfDi5JW4UfHzwNe620R51NM7Ref77bt GHItX8nxcG/XEx8TX6jliuj393EeAl7xz8yAvy1A9tIkj7XGT5iez+tSfVTOqKD9Hr6d ooRY1mBaG3KSeGls4SJJPfo/V1igG2KUOGTv8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=aEJBM0xZYq831vrFoCkq5anyCmo94pSbvJnshwo256wmZGCHx4Z+q0LJuoOEmZqzO9 2cOjI8zD90hlvIarPSD20e1Svvw4Ws/NMohoeq7bXJZ2+zFw9ZGfUokW15SKozWSqOKn Jak8j6/pExBjgS1jfJnEFYgP0AqYd82/vM9QM=
the pointcuts execution/call/etc take a method declaration signature -
so you need to specify the signature as it is declared. This means
not:
call(Object[][] LibUtil,getResultSetBound(Connection, String, JdbcParm []))
but
call(Object[][] LibUtil,getResultSetBound(Connection, String, JdbcParm...))
(as Mohan has in his example).
The binding pointcuts like args/this/target use the runtime type, and
at runtime the varargs is represented as an array so you use the
JdbcParm[] in args binding.
This complete program compiles and weaves for me:
public aspect Ooo {
pointcut traceGetSQLResultset(Connection dbConn, String sql,
JdbcParm[] values) :
call(Object[][] LibUtil.getSQLResultSetBound(Connection, String,
JdbcParm...)) &&
args(dbConn, sql, values);
Object[][] around(Connection dbConn, String sql, JdbcParm[] values) :
traceGetSQLResultset(dbConn, sql, values) {
System.out.println(sql);
return proceed(dbConn, sql, values);
}
public static void main(String[] args) {
LibUtil.getSQLResultSetBound(null,null);
}
}
class LibUtil {
public static Object[][] getSQLResultSetBound(Connection c,String s,
JdbcParm... jdbcParms) {
return null;
}
}
class Connection {}
class JdbcParm {}
Andy
On 18 May 2010 06:48, Roger Gilliar <roger@xxxxxxxxxx> wrote:
> Ok,
>
> after correcting my typo I'm now sure that JdbcParm [] doesn't match
> JdbcParm... values since I get a match if I change the signature of my
> method to getResultSetBound(final Connection dbConn, final String sql,
> JdbcParm[] values).
>
> The question remains: How do I write a pointcut for a method with varargs.
>
> Regards
> Roger
>
>> I would like to trace the following method. But I can't figure out how to
>> handle the varargs:
>>
>> public Object[][] getResultSetBound(final Connection dbConn, final String
>> sql, final JdbcParm... values) {
>> return getResultSetBound(dbConn, sql, null, values);
>> }
>>
>> My aspect is:
>>
>> pointcut traceGetSQLResultset(Connection dbConn, String sql, JdbcParm[]
>> values) :
>> call(Object[][] LibUtil,getResultSetBound(Connection, String,
>> JdbcParm [])) &&
>> args(dbConn, sql, values);
>>
>>
>> Object[][] around(Connection dbConn, String sql, JdbcParm[] values) :
>> traceGetSQLResultset(dbConn, sql, values) {
>> System.out.println(sql);
>> return proceed(dbConn, sql, values);
>> }
>>
>> But the advice is not applied.
>>
>> What I'm doing wrong ?
>>
>> Regards
>> Roger
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>