RFR 6388543: improve accuracy of source positions for AnnotationValue param of Messager.printMessage

Jonathan Gibbons jonathan.gibbons at oracle.com
Wed Jan 4 02:00:51 UTC 2017



On 01/03/2017 01:21 PM, Liam Miller-Cushon wrote:
> Hello,
>
> The JavacMessager API allows a message to be generated for a source 
> position defined by a combination of Element + AnnotationMirror + 
> AnnotationValue. The AnnotationValue is currently ignored, and the 
> position is defined using only the Element and AnnotationMirror.
>
> This fix causes the AnnotationValue to be considered when calculating 
> the diagnostic position. The value must be a direct value of the given 
> annotation, or an element in an array initializer. Values of nested 
> annotation mirrors are not supported.
>
> For example, given `@A(x = {1}, y = @B(2))` positions will be 
> calculated for the AnnotationMirror + AnnotationValue pairs @A + {1}, 
> @A + 1, and @B + 2, but not for @A + 2.
>
> Bug: https://bugs.openjdk.java.net/browse/JDK-6388543
> Webrev: http://cr.openjdk.java.net/~cushon/6388543/webrev.00/ 
> <http://cr.openjdk.java.net/%7Ecushon/6388543/webrev.00/>


I guess I am slightly surprised by the proposed solution, as regards the 
choice of what it means to find a match. I have always assumed that any 
implementation would iterate over the element values of the annotation, 
looking for a value that is .equals to the given value, for some 
appropriate definition of AnnotationValue.equals.  It does not seem 
obvious to me that you should be searching within the individual element 
values for the match. I am also surprised that you might match for @B + 
2; I would expect the annotation mirror to only match at the top 
level.   For example, assuming a "first one wins" policy, I would have 
expected @B + 2 to match the second annotation in the pair of 
annotations `@A(x = {1}, y = @B(2)) @B(2)`

So, before getting into the details of the proposed code, I think it 
would be worthwhile to determine what the semantics of this somewhat 
loosely-specified "hint" should actually be.

-- Jon






More information about the compiler-dev mailing list