我有两个类的方法,我想将两个类的方法组合到一个类.
@Service("ITestService")
public interface ITest1
{
@Export
void method1();
}
@Service("ITestService")
public interface ITest2
{
@Export
void method2();
}
Run Code Online (Sandbox Code Playgroud)
结果应该是:
public interface ITestService extends Remote
{
void method1();
void method2();
}
Run Code Online (Sandbox Code Playgroud)
我的AnnotationProcessor的第一次运行生成正确的输出(因为RoundEnvironment包含两个类).
但是如果我编辑其中一个类(例如添加一个新方法),RoundEnviroment只包含已编辑的类,因此结果如下(向接口ITest1添加newMethod())
public interface ITestService extends Remote
{
void method1();
void newMethod();
}
Run Code Online (Sandbox Code Playgroud)
现在缺少method2.我不知道如何解决我的问题.有没有办法(Enviroment),访问项目中的所有类?或者还有另一种解决方法吗?
生成类的代码很长,所以这里简要介绍我如何生成类.我遍历Elements env.getElementsAnnotatedWith(Service.class)并提取方法并将它们写入新文件:
FileObject file = null;
file = filer.createSourceFile("com/test/" + serviceName);
file.openWriter().append(serviceContent).close();
Run Code Online (Sandbox Code Playgroud)