AspectJ Question [message #47994] |
Tue, 15 February 2005 08:22 |
Eclipse User |
|
|
|
Originally posted by: kh_see.yahoo.com
hi,
Was evaluating AspectJ when i encounter this problem. Hopefully someone
can enlighten me.
AspectJ compiler ver 1.2.1
JDK compiler ver 1.5.0_01-b08
Linux kernel 2.6.10-1.760_FC3
------ JTest.java --------
public class JTest {
public void prtSomeThing(){
System.out.println("Hello World");
}
public static void main(String[] args){
JTest jt = new JTest();
jt.prtSomeThing(); }
}
------- JTestAspectJ.aj -------
public aspect JTestAspectJ {
pointcut logAllSystemPrint() : call(* System.out.println(..));
before() : logAllSystemPrint(){
System.out.println("Before Method");
}
}
--------------------------------
After compiling the two codes above, i got this warning message:
[tomcat@cm212 Test]$ ajc JTest.java JTestAspectJ.aj
/home/tomcat/aspectj/Test/JTestAspectJ.aj:17 [warning] no match for this
type name: System.out [Xlint:invalidAbsoluteTypeName]
pointcut logAllSystemPrint() : call(* System.out.println(..));
^^^^^^^^^^^^^^^^
[tomcat@cm212 Test]$ java JTest
Hello World
Why is there no match for 'System.out.println(..)' ?
I've tried these and they all don't work.
call(* System.out.*(..))
call(* System.out.println(String))
|
|
|
Re: AspectJ Question [message #48026 is a reply to message #47994] |
Tue, 15 February 2005 08:54 |
Eclipse User |
|
|
|
Originally posted by: adrian_colyer.uk.ibm.com
Freddy wrote:
> [tomcat@cm212 Test]$ ajc JTest.java JTestAspectJ.aj
> /home/tomcat/aspectj/Test/JTestAspectJ.aj:17 [warning] no match for this
> type name: System.out [Xlint:invalidAbsoluteTypeName]
> pointcut logAllSystemPrint() : call(* System.out.println(..));
> ^^^^^^^^^^^^^^^^
> [tomcat@cm212 Test]$ java JTest
> Hello World
> Why is there no match for 'System.out.println(..)' ?
> I've tried these and they all don't work.
> call(* System.out.*(..))
> call(* System.out.println(String))
Because System.out.println is such a common idiom in Java, we tend to
forget what it really means.
System.out is an access to a static field on the System class called "out"
println is then a method invocation on the out object.
So there is no type "System.out" (the call pcd needs a type pattern in
that position, and is interpreting "System.out" as "a type named out in
the System package").
call( * println(..)) would work, as would
call( * PrintStream.println(..))
a common aspectj idiom used to catch System.out/err printing is:
get(* System.out) || get(* System.err)
which actually matches the field access but gives you what you want 99% of
the time.
|
|
|
Re: AspectJ Question [message #48243 is a reply to message #48026] |
Wed, 16 February 2005 08:26 |
Eclipse User |
|
|
|
Originally posted by: kh_see.yahoo.com
Adrian Colyer wrote:
> Because System.out.println is such a common idiom in Java, we tend to
> forget what it really means.
> System.out is an access to a static field on the System class called "out"
> println is then a method invocation on the out object.
> So there is no type "System.out" (the call pcd needs a type pattern in
> that position, and is interpreting "System.out" as "a type named out in
> the System package").
> call( * println(..)) would work, as would
> call( * PrintStream.println(..))
> a common aspectj idiom used to catch System.out/err printing is:
> get(* System.out) || get(* System.err)
> which actually matches the field access but gives you what you want 99% of
> the time.
OK, now i understand, thanks for the info.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03360 seconds