Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Pointcut for main method

Thread view: 
Guybrush Threepwood - 08 Nov 2006 17:11 GMT
I'm making some exercises to learn AspectJ and I'm not able to define a
pointcut that captures the main method.

public aspect Test {
   
pointcut callStatic() : call(public static void *(..));
   
before() : callStatic() {
   System.out.println("ok");
}
}

Why does the pointcut capture all public static methods with void return
type except for the main method?
Piotr Kobzda - 08 Nov 2006 21:47 GMT
> I'm making some exercises to learn AspectJ and I'm not able to define a
> pointcut that captures the main method.
[quoted text clipped - 10 lines]
> Why does the pointcut capture all public static methods with void return
> type except for the main method?

The call join point picked out by your pointcut happens outside the
target method.  In order to implement that for main() method, AspectJ
should be able to modify the code of the JVM which invoked your main().
 Use the execution join point instead.

See also:
http://www.eclipse.org/aspectj/doc/released/faq.php#q:comparecallandexecution

piotr
Chris Uppal - 09 Nov 2006 14:52 GMT
> The call join point picked out by your pointcut happens outside the
> target method.  In order to implement that for main() method, AspectJ
[quoted text clipped - 3 lines]
> See also:
> http://www.eclipse.org/aspectj/doc/released/faq.php#q:comparecallandexecution

Interesting. I hadn't realised that AspectJ distinguished between the inside
and outside of a method call (as it were).  It's a good idea.  (Still doesn't
make me less sceptical about the AspectJ vision of AOP, though).

In this case the main() entry point is invoked directly from JNI [*] -- which
does make it difficult for bytecode manipulation to replace ;-)

([*] That's to say, it's not -- strictly speaking -- built into the JVM).

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.