Eclipse - Annotation processor, get project path

后端 未结 2 1659
南方客
南方客 2020-12-21 11:05

I am building an annotation processor plugin for eclipse, what i would like to do is to examine several files inside the project folder during the processing.

I wou

2条回答
  •  醉酒成梦
    2020-12-21 11:43

    I am getting the source path from ProsessingEnv by generating a source file:

    String fetchSourcePath() {
        try {
            JavaFileObject generationForPath = processingEnv.getFiler().createSourceFile("PathFor" + getClass().getSimpleName());
            Writer writer = generationForPath.openWriter();
            String sourcePath = generationForPath.toUri().getPath();
            writer.close();
            generationForPath.delete();
    
            return sourcePath;
        } catch (IOException e) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Unable to determine source file path!");
        }
    
        return "";
    }
    

提交回复
热议问题