How many methods does a pointcut add? [message #1690213] |
Wed, 25 March 2015 13:15  |
Eclipse User |
|
|
|
Hey all,
I hope someone might be help me (and thanks in advance to anyone who tries).
I am using AJDT (download.eclipse.org/tools/ajdt/43/update) with eclipse. When testing to see how it operates, I see that it simply adds about 2 methods (beyond the pointcut itself) for each pointcut.
Example code:
package com.mytest.aspects;
public class HelloWorld {
public static void main(String[] args) {
foo();
}
private static void foo() {
System.out.println("Hello world");
}
}
Example aspect:
package com.mytest.aspects;
public aspect HelloAspect {
pointcut foo() : call (void com.mytest.aspects.HelloWorld.foo(..));
void around() : foo() {
System.out.println("weaving foo...");
proceed();
}
}
When i decompile (using JD-Gui), I see that the aspect class has been added 3 methods (AspectOf, hasAspect and a static constructor), and that the pointcut is not implemented by injecting a code, rather by overwriting the call to a new pointcut:
package com.mytest.aspects;
import java.io.PrintStream;
import org.aspectj.runtime.internal.AroundClosure;
public class HelloWorld
{
private static final int foo_aroundBody0()
{
foo();
}
public static void main(String[] args)
{
foo_aroundBody1$advice(HelloAspect.aspectOf(), null) == 2);
}
private static final int foo_aroundBody1$advice(HelloAspect ajc$aspectInstance, AroundClosure ajc$aroundClosure)
{
System.out.println("weaving foo...");
AroundClosure localAroundClosure = ajc$aroundClosure;
foo2_aroundBody0();
}
private static void foo()
{
System.out.println("Hello World");
}
}
Am I perhaps missing something? Is this the proper way AspectJ works?
Moreover, for a call pointcut, it seems 2 methods are added for each call to a method, even if both done in the same class.
I am trying to avoid adding so many methods to my code, since my aspiration is to use this for an Android application and earlier versions of android cannot have more 65,536 methods (and using various jars, it is easy to reach that number, especially if the aspects add so many methods).
Any know if this is right or is there something else I should be doing?
|
|
|
|
Re: How many methods does a pointcut add? [message #1690354 is a reply to message #1690331] |
Thu, 26 March 2015 15:11  |
Eclipse User |
|
|
|
Thanks for your answer.
I'm afraid I'm using AspectJ in order to log some aspects (no pun intended) of my application, including in third party libraries.
Does anyone know perhaps of some other way to achieve something much more similar to injection, or preferably that adds less methods (as the call pointcut)? Is there some other tool or compiler out there which can inject / crosscut java code?
Thanks.
|
|
|
Powered by
FUDForum. Page generated in 0.03950 seconds