我正在使用注释处理来生成一些代码,我需要在特定包中创建 kotlin 文件这是我的代码
@AutoService(Processor.class)
@IncrementalAnnotationProcessor(IncrementalAnnotationProcessorType.DYNAMIC)
@SuppressWarnings("NullAway")
public final class MyProcessor extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
....
}
private void writeKotlinFile(String pack, String fileName, String fileContent, Element it) {
.....
}
}
Run Code Online (Sandbox Code Playgroud)
我认为你必须OutputStream在你的函数中这样使用writeKolinFilee:
private void writeKotlinFile(String pack, String fileName, String fileContent, Element it) {
try {
FileObject filerSourceFile = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
pack, fileName + ".kt", it);
OutputStream outputStream = filerSourceFile.openOutputStream();
outputStream.write(fileContent.getBytes());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46 次 |
| 最近记录: |