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

Ah, a messier problem because it's not advisable (and usually treads dangerously on licenses) to weave against third party libraries, especially the Java standard ones. What you are seeing is that the standard libraries are not being dragged into your weaving process (for good reasons) and even if you did manage to include them (using -inpath) that could be a problem because of the aforementioned licensing troubles.

Are you trying to capture when an object is "toString()"ed only when you are using System.out.println()? Because you could use call() on that to capture when objects are being converted toString() ... 


On Thursday, November 11, 2004, at 02:41PM, Benjamin Mesing <benjamin.mesing@xxxxxxxxxxxxxxx> wrote:

>Hello,
>
>> Depending on what you are trying to do you may prefer to use 'execution' 
>> instead of 'call'.  For your example the pointcut would be:
>> 
>> execution (String HelloWorld.toString())
>> 
>> and would result in "jpt hit" being printed out twice.
>
>Thanks for the tip, unfortunately this does not work for me as I want to 
>capture the toString function calls for the built in Number classes 
>(i.e. Integer, Float,..) to pipe them through a NumberFormatter. But it 
>seems that these classes are somewhat special because they are not 
>captured this way.
>
>Here is the example rewritten using execution join points. The output is
>---
>Goodbye world
>Goodbye world
>25
>---
>
>public class HelloWorld
>{
>	public static void main(String[] args)
>	{
>		HelloWorld hw = new HelloWorld();
>		System.out.println(hw.toString() + "\n" + hw);
>		Integer i = new Integer(25);
>		System.out.println(""+i);
>	}
>	
>	public String toString()
>	{	
>		return "Hello World ";
>	}
>}
>
>
>public aspect TestAspect
>{
>	String around() : execution(String HelloWorld.toString())
>	{
>		return "Goodbye world";
>	}
>	
>	String around() : execution(String Integer.toString() )
>	{
>		System.out.println("Returning 1");
>		return "1";
>	}
>}
>
>Greetings Ben
>_______________________________________________
>aspectj-users mailing list
>aspectj-users@xxxxxxxxxxx
>http://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top