Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 would like to know how can I get the project path from within my processor. I believe this can be done because the project source path is provided to the processor - but I cannot find a way to reach it.

I tried looking at the System.properties and at the processingEnv.getOptions() but there is no useful information there..

eventually I would like to use this annotation processor on Netbeans too so if there is a public API that can provide this information it will be the best - but any help will be appreciated..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
548 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 "";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...