Java 8编译器插件:如何在构造函数中添加super()调用?

I'm writing a Java compiler plugin to add a simple class named MyClass in some classes of my project (something like lombok does). I've managed to do it by writing the code bellow (you can find the overall code is here):

JCTree.JCMethodDecl constructor = maker.MethodDef(maker.Modifiers(Flags.PUBLIC),
        symbolsTable.init,
        null,
        List.nil(), // params
        List.nil(),
        List.nil(),
        maker.Block(0, List.of(callSuper)),
        null
);

JCTree.JCClassDecl myClass = maker
        .at(((JCTree) node).pos)
        .ClassDef(maker.Modifiers(Flags.PUBLIC | Flags.STATIC | Flags.FINAL),
                symbolsTable.fromString("MyClass"),
                List.nil(),
                maker.Ident(symbolsTable.fromString("AnotherClass")),
                List.nil(),
                List.of(constructor)
        );

((JCTree.JCClassDecl) node).defs = ((JCTree.JCClassDecl) node).defs.append(myClass);

I don't know how to write the callSuper statement to get this output :

public static final MyClass extends AnotherClass {
   public MyClass () {
      super(); // I want this line
   }
}

任何帮助表示赞赏。

评论