Pointcut for main method

  • Thread starter Guybrush Threepwood
  • Start date
G

Guybrush Threepwood

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

Piotr Kobzda

Guybrush said:
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
 
C

Chris Uppal

Piotr said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top