I am trying to use processingEnv.getFiler() to create a source file. But I don't see any source file getting created. Below is the code that I am using:
public void javaPoetEg() {
Filer filer = super.processingEnv.getFiler();
MethodSpec main = MethodSpec.methodBuilder("testFiler")
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
.addParameter(String[].class, "args")
.addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!")
.build();
TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addMethod(main)
.build();
JavaFile javaFile = JavaFile.builder("com.ankit.annotation", helloWorld)
.build();
try{
javaFile.writeTo(filer);
} catch (IOException e) {
e.printStackTrace();
}
}
And then calling the function javaPoetEg in the overridden function process() of Annotation processor. What am I doing wrong here?