Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AJDT » Accessing parameter names in advice
Accessing parameter names in advice [message #49540] Mon, 07 March 2005 06:01 Go to next message
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 #49570 is a reply to message #49540] Mon, 07 March 2005 10:39 Go to previous messageGo to next message
Eclipse User
Originally posted by: adrian.redpointsoft.com

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 #49658 is a reply to message #49540] Tue, 08 March 2005 08:32 Go to previous message
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 Go to previous message
Adrian Powell is currently offline Adrian Powell
Messages: 16
Registered: July 2009
Junior Member
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 Go to previous message
Adrian Colyer is currently offline Adrian Colyer
Messages: 61
Registered: July 2009
Member
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());
}
Previous Topic:AspectJ with Device Developer
Next Topic:newbie question
Goto Forum:
  


Current Time: Sun Apr 20 12:18:37 EDT 2014

Powered by FUDForum. Page generated in 0.01722 seconds