Pointcut for main method

Discussion in 'Java' started by Guybrush Threepwood, Nov 8, 2006.

  1. 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?
    Guybrush Threepwood, Nov 8, 2006
    #1
    1. Advertising

  2. Guybrush Threepwood

    Piotr Kobzda Guest

    Guybrush Threepwood wrote:

    > 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?


    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
    Piotr Kobzda, Nov 8, 2006
    #2
    1. Advertising

  3. Guybrush Threepwood

    Chris Uppal Guest

    Piotr Kobzda wrote:

    > 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


    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
    Chris Uppal, Nov 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John M
    Replies:
    1
    Views:
    1,102
    Kumar Reddi
    May 29, 2005
  2. Hal Styli
    Replies:
    14
    Views:
    1,608
    Old Wolf
    Jan 20, 2004
  3. Frederick Ding

    int main() or int main(void)?

    Frederick Ding, Dec 3, 2005, in forum: C Programming
    Replies:
    10
    Views:
    639
  4. Ravi
    Replies:
    17
    Views:
    905
    Kenneth Brody
    Apr 1, 2006
  5. main() called inside main()

    , May 4, 2006, in forum: C Programming
    Replies:
    14
    Views:
    1,406
    Richard Heathfield
    May 7, 2006
Loading...

Share This Page