-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
b09
Consider an annotation processor that generates source files and errors in the AP round. E.g.:
---ProcessorImpl.java
import java.io.IOException;
import java.io.Writer;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.tools.Diagnostic.Kind;
@SupportedAnnotationTypes("*")
public class ProcessorImpl extends AbstractProcessor {
int round = 0;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (round++ == 0) {
try (Writer w = processingEnv.getFiler().createSourceFile("Extra").openWriter()) {
w.write("public class Extra {}");
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
processingEnv.getMessager().printMessage(Kind.ERROR, "processor error");
}
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}
---
And consider a source file being compiled with this processor, like:
---Test.java
public class Test extends Extra implements ExtraExtra {}
---
---
$ javac -processor ProcessorImpl /tmp/Test.java
Test.java:1: error: cannot find symbol
public class Test extends Extra implements ExtraExtra {}
^
symbol: class Extra
Test.java:1: error: cannot find symbol
public class Test extends Extra implements ExtraExtra {}
^
symbol: class ExtraExtra
error: processor error
3 errors
---
This is inconvenient for two reasons:
-the "cannot find Extra" error is resolved by the file the AP generated
-the error reported by the AP is probably quite important, but is listed after the other errors, some of which are fixed by the AP
---ProcessorImpl.java
import java.io.IOException;
import java.io.Writer;
import java.util.*;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.tools.Diagnostic.Kind;
@SupportedAnnotationTypes("*")
public class ProcessorImpl extends AbstractProcessor {
int round = 0;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (round++ == 0) {
try (Writer w = processingEnv.getFiler().createSourceFile("Extra").openWriter()) {
w.write("public class Extra {}");
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
processingEnv.getMessager().printMessage(Kind.ERROR, "processor error");
}
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
}
---
And consider a source file being compiled with this processor, like:
---Test.java
public class Test extends Extra implements ExtraExtra {}
---
---
$ javac -processor ProcessorImpl /tmp/Test.java
Test.java:1: error: cannot find symbol
public class Test extends Extra implements ExtraExtra {}
^
symbol: class Extra
Test.java:1: error: cannot find symbol
public class Test extends Extra implements ExtraExtra {}
^
symbol: class ExtraExtra
error: processor error
3 errors
---
This is inconvenient for two reasons:
-the "cannot find Extra" error is resolved by the file the AP generated
-the error reported by the AP is probably quite important, but is listed after the other errors, some of which are fixed by the AP