i'm using annotation processing to generate some code and i need to create kotlin file in specific package this is my code
@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) {
.....
}
}
I think you have to use OutputStream
like this in your writeKolinFilee
function:
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With