A DESCRIPTION OF THE REQUEST :
It would be nice if there were a way for annotation processors to report a message at a specific position *within* an annotation value. For example if the value is a string, the processor may wish to print a message at a specific character position within that string where bad input was found. This would require adding another overload of Messager.printMessage with an index parameter. Something like this:
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, int index);
The index could be interpreted as a character position for string values or an array index for array values. The compiler would be responsible for mapping the character position back to the source code position, which would need to account for special cases like escape sequences and strings formed by concatenation.
For example given this line of code:
@Something(name="an error reported HERE")
The annotation processor could call:
msg.printMessage(Diagnostic.Kind.ERROR, theAnnotatedElement, theAnnotationMirror, theAnnotationValue, 18);
The compiler would then report a diagnostic at the exact position of the letter 'H' in this example.
JUSTIFICATION :
Annotation processors may expect input to meet some constraints. For example, a string may need to follow some syntax rules. Allowing the processor to report diagnostics at a precise location provides a better user experience and allows developers to understand and fix errors quicker.
It would be nice if there were a way for annotation processors to report a message at a specific position *within* an annotation value. For example if the value is a string, the processor may wish to print a message at a specific character position within that string where bad input was found. This would require adding another overload of Messager.printMessage with an index parameter. Something like this:
void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v, int index);
The index could be interpreted as a character position for string values or an array index for array values. The compiler would be responsible for mapping the character position back to the source code position, which would need to account for special cases like escape sequences and strings formed by concatenation.
For example given this line of code:
@Something(name="an error reported HERE")
The annotation processor could call:
msg.printMessage(Diagnostic.Kind.ERROR, theAnnotatedElement, theAnnotationMirror, theAnnotationValue, 18);
The compiler would then report a diagnostic at the exact position of the letter 'H' in this example.
JUSTIFICATION :
Annotation processors may expect input to meet some constraints. For example, a string may need to follow some syntax rules. Allowing the processor to report diagnostics at a precise location provides a better user experience and allows developers to understand and fix errors quicker.
- relates to
-
JDK-8066843 Messager.printMessage cannot print multiple errors for same source position
-
- Closed
-