Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] capturing implicit toString() function calls

Hello,

aspect TestAspect
{
       before() : call (String HelloWorld.toString())
       || (call(void PrintStream.println(..)) && args(HelloWorld))
       || (call(StringBuffer StringBuffer.append(..)) && args(HelloWorld))
       {
                   System.out.println("jpt hit");
       }
}
Thanks, that did the trick!

The final version looks like this (based on my second example)

public aspect TestAspect
{
    StringBuffer around(Integer i, StringBuffer sb) :
   	(call(StringBuffer StringBuffer.append(..)) && args(i))
	&& target(sb) && (!within(TestAspect))
    {
   	return sb.append(i  + " became 1");
    }
}

public class HelloWorld
{
	public static void main(String[] args)
	{
		Integer i = new Integer(25);
		System.out.println(""+i);
	}
}

Where the output is as expected: "25 became 1".
I have also tried
	 String around() :
	 	withincode(StringBuffer StringBuffer.append(..)) &&
		call(String Integer.toString())
	{
	 	return "1";
	}
In the aspect but this did not work.

Thanks all for your help. Your posts helped me a lot in understanding what is going on.

Greetings Ben


Back to the top