使用注释代码中的方法在Javapoet中轻松创建(复制)方法

使用注释代码中的方法在Javapoet中轻松创建(复制)方法,java,android,annotation-processing,javapoet,Java,Android,Annotation Processing,Javapoet,我编写了一个注释处理器来创建一个子类。例如,如果您有以下代码: @MyAnnotation(Bar.class) class Foo : MyGenerated_Foo { } 然后,注释处理器生成: class MyGenerated_Foo extends Bar { ... generate some helpful methods and fields here ... } 在使用了一段时间后,我意识到如果Bar有一个自定义构造函数,这就不起作用了。我想创建一个传递构造函数,但我

我编写了一个注释处理器来创建一个子类。例如,如果您有以下代码:

@MyAnnotation(Bar.class)
class Foo : MyGenerated_Foo {
}
然后,注释处理器生成:

class MyGenerated_Foo extends Bar {
  ... generate some helpful methods and fields here ...
}
在使用了一段时间后,我意识到如果Bar有一个自定义构造函数,这就不起作用了。我想创建一个传递构造函数,但我不确定最好的方法是什么

以下是我想要实现的目标:

class Bar {
  Bar(String arg) {}
}

@MyAnnotation(Bar.class)
class Foo : MyGenerated_Foo {
  Foo(String arg) {
    MyGenerated_Foo(arg);
  }
}
上述情况应产生以下结果:

class MyGenerated_Foo extends Bar {
  MyGenerated_Bar(String arg) {
    Bar(arg);
  }

  ... generate some helpful methods and fields here ...
}