我正在尝试通过Java 8中的编译时注释处理生成源代码的配置文件。
据我所知,在getSupportedAnnotationTypes
类列出的每个注释中,处理器将被调用一次。
@Override
public Set<String> getSupportedAnnotationTypes() {
Set<String> set = new LinkedHashSet<>();
set.add(MCPlugin.class.getCanonicalName());
set.add(MCAPIVersion.class.getCanonicalName());
set.add(MCAuthor.class.getCanonicalName());
set.add(MCAPIVersion.class.getCanonicalName());
set.add(MCDepend.class.getCanonicalName());
set.add(MCLoad.class.getCanonicalName());
set.add(MCLoadBefore.class.getCanonicalName());
set.add(MCSoftDepend.class.getCanonicalName());
set.add(MCCommand.class.getCanonicalName());
return set;
}
实际上,我不想使用一个注解处理器处理所有这些注解(这样做是正确的吗?),因为它会导致与MCCommand
注解的问题。因此,我的计划是创建另一个注解处理器,仅处理MCCommand
注解。
我的问题是,两个处理器的输出应该进入同一个输出文件。(这可能吗?)
我已经尝试过以这种方式重新打开资源文件(这也是我最初打开它的方式):
FileObject file = filer.createResource(StandardLocation.SOURCE_OUTPUT, "", "config.yml");
这会导致错误或覆盖现有文件。
TlDr:我如何让我的注解处理器编辑另一个注解处理器生成的文件?
Filer#getResource
这个方法有效吗? - undefined