[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[Fwd: Re: [aspectj-users] capturing implicit toString() function call (fwd)]
|
Forwarded because of a bounce of the original message.
---------- Forwarded message ----------
Date: Thu, 11 Nov 2004 08:02:37 -0500 (EST)
From: Prof. Laurie HENDREN <hendren@xxxxxxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] capturing implicit toString() function call
Hi Ben,
I tried to reply to the list, but it was bounced. My original reply
was not quite right.
The problem is that the weaver looks at the generated bytecode and
compilers can actually generate lots of different things to handle
strcat and toString().
If you look at the key bits of the bytecode produced by javac for your
println you see that your explicit toString shows up as a toString, but
the second one is implicit in the second append to StringBuffer, and then
the last toString in the generated code corresponds to conversion of
a StringBuffer to a String.
Cheers, Laurie
public static void main(java.lang.String[]);
Code:
0: new #2; //class HelloWorld
3: dup
4: invokespecial #3; //Method "<init>":()V
7: astore_1
8: getstatic #4; //Field
java/lang/System.out:Ljava/io/PrintStream;
11: new #5; //class StringBuffer
14: dup
15: invokespecial #6; //Method java/lang/StringBuffer."<init>":()V
18: aload_1
19: invokevirtual #7; //Method toString:()Ljava/lang/String;
22: invokevirtual #8; //Method
java/lang/StringBuffer.append:(Ljava/lang/S
tring;)Ljava/lang/StringBuffer;
25: aload_1
26: invokevirtual #9; //Method
java/lang/StringBuffer.append:(Ljava/lang/O
bject;)Ljava/lang/StringBuffer;
29: invokevirtual #10; //Method
java/lang/StringBuffer.toString:()Ljava/la
ng/String;
32: invokevirtual #11; //Method
java/io/PrintStream.println:(Ljava/lang/St
ring;)V
35: return
+-------------------------------------------------------------+
| Laurie Hendren, Professor, School of Computer Science |
| McGill University |
| 318 McConnell Engineering Building tel: (514) 398-7391 |
| 3480 University Street fax: (514) 398-3883 |
| Montreal, Quebec H3A 2A7 hendren@xxxxxxxxxxxx |
| CANADA http://www.sable.mcgill.ca/~hendren |
+-------------------------------------------------------------+
On Thu, 11 Nov 2004, Benjamin Mesing wrote:
Hello,
I have stumbled over a problem. When specifying a pointcut, implicit
calls of toString functions will not be captured. Consider the following
example, wher "jpt hit" will be printed only once.
Is there anything I can do about it?
public class HelloWorld {
public static void main(String[] args) {
HelloWorld hw = new HelloWorld();
// here occurs an explicit and an implicit call of
// toString()
System.out.println(hw.toString() + hw);
}
public String toString()
{
return "Hello World ";
}
}
public aspect TestAspect
{
before() : call (String HelloWorld.toString())
{
System.out.println("jpt hit");
}
}
Greetings Ben
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users