开发者

converting class with aspect into single source

Is there some tool for appying aspect to some class and generating final source into existing java source? I want my initial class

public class HelloWorld {

  public static void main(String[] args) {
    System.out.println("Hello world!");
  }

}

would be final source

public class HelloWorld {

  public static void main(String[] args) {
    System.out.println("Hello world!");
    System.out.println("Hello from AspectJ");
  }

}

after a开发者_StackOverflowpplying this tool with next aspect

public aspect HelloFromAspectJ {
  pointcut mainMethod() : execution(public static void main(String[]));
  after() returning : mainMethod() {
    System.out.println("Hello from AspectJ");
  }
}


No, this is not possible. AspectJ is not a tool for source code generation. There are other tools around that might be better suited to your purpose, but unfortunately, I don't know enough about any of them to recommend one.


AspectJ acts on compiled code, not on source. If you don't really care about comments, variable names, formatting, etc. what you can do is apply aspectj on your compiled code and then decompile your code to generate the source code with aspects weaved in. It's not perfect but might be enough for your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜