A DESCRIPTION OF THE PROBLEM :
There is no position information included when using a RecordComponentElement with Messager#printMessage, regardless of if an annotation mirror is included or not.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. `javac proc/*.java`
2. `javac -processorpath . -processor proc.ReproducingAP Test.java`
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java:1: warning: Reporting Test with an annotation
@proc.TestWarning(includeAnnotation = true)
^
Test.java:3: warning: Reporting first with an annotation
@proc.TestWarning(includeAnnotation = true) int first,
^
Test.java:4: warning: Reporting second
@proc.TestWarning(includeAnnotation = false) int second
^
Test.java:8: warning: Reporting Test2
record Test2() {}
^
4 warnings
ACTUAL -
Test.java:1: warning: Reporting Test with an annotation
@proc.TestWarning(includeAnnotation = true)
^
warning: Reporting first with an annotation
warning: Reporting second
Test.java:8: warning: Reporting Test2
record Test2() {}
^
4 warnings
---------- BEGIN SOURCE ----------
proc/ReproducingAP.java:
```
package proc;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
@SupportedSourceVersion(SourceVersion.RELEASE_17)
public class ReproducingAP extends AbstractProcessor {
@Override
public Set<String> getSupportedAnnotationTypes() {
return Set.of(TestWarning.class.getName());
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
roundEnv.getElementsAnnotatedWith(TestWarning.class).forEach(e -> {
var annotation = e.getAnnotation(TestWarning.class);
if (annotation.includeAnnotation()) {
processingEnv.getMessager().printMessage(
javax.tools.Diagnostic.Kind.WARNING,
"Reporting " + e.getSimpleName() + " with an annotation",
e,
e.getAnnotationMirrors().get(0));
} else {
processingEnv.getMessager().printMessage(
javax.tools.Diagnostic.Kind.WARNING,
"Reporting " + e.getSimpleName(),
e);
}
});
return false;
}
}
```
proc/TestWarning.java:
```
package proc;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
/**
* Direct {@link ReproducingAP} to emit a warning.
*/
@Target({ElementType.TYPE, ElementType.RECORD_COMPONENT})
public @interface TestWarning {
/**
* {@return {@code true} to include the relevant mirror in the warning message}
*/
boolean includeAnnotation() default false;
}
```
Test.java:
```
@proc.TestWarning(includeAnnotation = true)
public record Test(
@proc.TestWarning(includeAnnotation = true) int first,
@proc.TestWarning int second) {
}
@proc.TestWarning
record Test2() {}
```
---------- END SOURCE ----------
FREQUENCY : always
There is no position information included when using a RecordComponentElement with Messager#printMessage, regardless of if an annotation mirror is included or not.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. `javac proc/*.java`
2. `javac -processorpath . -processor proc.ReproducingAP Test.java`
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java:1: warning: Reporting Test with an annotation
@proc.TestWarning(includeAnnotation = true)
^
Test.java:3: warning: Reporting first with an annotation
@proc.TestWarning(includeAnnotation = true) int first,
^
Test.java:4: warning: Reporting second
@proc.TestWarning(includeAnnotation = false) int second
^
Test.java:8: warning: Reporting Test2
record Test2() {}
^
4 warnings
ACTUAL -
Test.java:1: warning: Reporting Test with an annotation
@proc.TestWarning(includeAnnotation = true)
^
warning: Reporting first with an annotation
warning: Reporting second
Test.java:8: warning: Reporting Test2
record Test2() {}
^
4 warnings
---------- BEGIN SOURCE ----------
proc/ReproducingAP.java:
```
package proc;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
@SupportedSourceVersion(SourceVersion.RELEASE_17)
public class ReproducingAP extends AbstractProcessor {
@Override
public Set<String> getSupportedAnnotationTypes() {
return Set.of(TestWarning.class.getName());
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
roundEnv.getElementsAnnotatedWith(TestWarning.class).forEach(e -> {
var annotation = e.getAnnotation(TestWarning.class);
if (annotation.includeAnnotation()) {
processingEnv.getMessager().printMessage(
javax.tools.Diagnostic.Kind.WARNING,
"Reporting " + e.getSimpleName() + " with an annotation",
e,
e.getAnnotationMirrors().get(0));
} else {
processingEnv.getMessager().printMessage(
javax.tools.Diagnostic.Kind.WARNING,
"Reporting " + e.getSimpleName(),
e);
}
});
return false;
}
}
```
proc/TestWarning.java:
```
package proc;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
/**
* Direct {@link ReproducingAP} to emit a warning.
*/
@Target({ElementType.TYPE, ElementType.RECORD_COMPONENT})
public @interface TestWarning {
/**
* {@return {@code true} to include the relevant mirror in the warning message}
*/
boolean includeAnnotation() default false;
}
```
Test.java:
```
@proc.TestWarning(includeAnnotation = true)
public record Test(
@proc.TestWarning(includeAnnotation = true) int first,
@proc.TestWarning int second) {
}
@proc.TestWarning
record Test2() {}
```
---------- END SOURCE ----------
FREQUENCY : always