Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » AspectJ » Accessing parameter names in advice
Accessing parameter names in advice [message #49540] Mon, 07 March 2005 11:01 Go to next message
Eclipse UserFriend
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 15:39 Go to previous messageGo to next message
Eclipse UserFriend
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 13:32 Go to previous message
Eclipse UserFriend
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 15:39 Go to previous message
Adrian Powell is currently offline Adrian PowellFriend
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 13:32 Go to previous message
Adrian Colyer is currently offline Adrian ColyerFriend
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: Tue Apr 23 08:55:43 GMT 2024

Powered by FUDForum. Page generated in 0.02714 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top