| 
| Accessing parameter names in advice [message #49540] | Mon, 07 March 2005 06:01  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: simon.heinzle.adnovum.ch 
 SORRY about the post before, something went wrong....
 
 I'm currently writing an Enter/Leave tracing aspect for Debugging. The
 output of it should be somewhat like "Entering method m_name(p_name =
 p_value,...)".
 
 Is there a way of getting the names(identifiers) of the parameters in an
 advice generic?
 
 With thisJoinPoint only the parameter values and their types can be
 queried. A solution like
 
 
 before (String target, int count) :
 execution(* *.calculateValue(String, int))
 &&  args(target, count)
 {
 // Output: "Entering method calculateValue(target="+target ...
 }
 
 
 is too bulky.
 |  |  |  | 
|  | 
| 
| Re: Accessing parameter names in advice [message #49658 is a reply to message #49540] | Tue, 08 March 2005 08:32  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: adrian_colyer.uk.ibm.com 
 Simon Heinzle wrote:
 > Is there a way of getting the names(identifiers) of the parameters in an
 > advice generic?
 
 You can do the following:
 
 pointcut traced() : execution(* *(..));  // whatever you want here
 
 before() : traced {
 CodeSignature sig = (CodeSignature) thisJoinPoint.getSignature();
 StringBuffer traceRecord = new StringBuffer();
 traceRecord.append("Entering method ");
 traceRecord.append(sig.getDeclaringTypeName());
 traceRecord.append(".");
 traceRecord.append(sig.getName());
 traceRecord.append("(");
 Object[] args = thisJoinPoint.getArgs();
 String[] pNames = sig.getParameterNames();
 for (int p=0; p < pName.length; p++) {
 traceRecord.append(pNames[p]);
 traceRecord.append("=");
 traceRecord.append(args[p] == null ? "null" : args[p].toString());
 traceRecord.append(" ");
 }
 traceRecord.append(")");
 log(traceRecord.toString());
 }
 |  |  |  | 
| 
| Re: Accessing parameter names in advice [message #587265 is a reply to message #49540] | Mon, 07 March 2005 10:39  |  | 
| Eclipse User  |  |  |  |  | Simon, 
 I haven't tried this, but it looks promising.
 
 
 before( ) : execution( * *.calculateValue() ) {
 Object args[] = thisJoinPoint.getArgs();
 for( int i = 0; i < args++; i++ ) {
 // do stuff
 }
 }
 
 -adrian.
 
 
 Simon Heinzle wrote:
 
 > SORRY about the post before, something went wrong....
 >
 > I'm currently writing an Enter/Leave tracing aspect for Debugging. The
 > output of it should be somewhat like "Entering method m_name(p_name =
 > p_value,...)".
 >
 > Is there a way of getting the names(identifiers) of the parameters in an
 > advice generic?
 > With thisJoinPoint only the parameter values and their types can be
 > queried. A solution like
 >
 >
 > before (String target, int count) :        execution(*
 > *.calculateValue(String, int))
 >        &&  args(target, count)    {
 >       // Output: "Entering method calculateValue(target="+target ...
 >    }
 >
 >
 > is too bulky.
 >
 >
 >
 >
 |  |  |  | 
| 
| Re: Accessing parameter names in advice [message #587320 is a reply to message #49540] | Tue, 08 March 2005 08:32  |  | 
| Eclipse User  |  |  |  |  | Simon Heinzle wrote: > Is there a way of getting the names(identifiers) of the parameters in an
 > advice generic?
 
 You can do the following:
 
 pointcut traced() : execution(* *(..));  // whatever you want here
 
 before() : traced {
 CodeSignature sig = (CodeSignature) thisJoinPoint.getSignature();
 StringBuffer traceRecord = new StringBuffer();
 traceRecord.append("Entering method ");
 traceRecord.append(sig.getDeclaringTypeName());
 traceRecord.append(".");
 traceRecord.append(sig.getName());
 traceRecord.append("(");
 Object[] args = thisJoinPoint.getArgs();
 String[] pNames = sig.getParameterNames();
 for (int p=0; p < pName.length; p++) {
 traceRecord.append(pNames[p]);
 traceRecord.append("=");
 traceRecord.append(args[p] == null ? "null" : args[p].toString());
 traceRecord.append(" ");
 }
 traceRecord.append(")");
 log(traceRecord.toString());
 }
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.04330 seconds