JDK 9 RFR of JDK-8162817: Annotation toString output not reusable for source input
Peter Levart
peter.levart at gmail.com
Tue Aug 2 08:59:01 UTC 2016
Hi Joe,
I wonder why you compare the type obtained from an value.getClass() with
class literals for primitive types (lines 174, 176, 178):
165 Class<?> type = value.getClass();
166 if (!type.isArray()) {
167 // primitive value, string, class, enum const, or
annotation
168 if (type == Class.class)
169 return toSourceString((Class<?>) value);
170 else if (type == String.class)
171 return toSourceString((String) value);
172 if (type == Character.class)
173 return toSourceString((char) value);
174 else if (type == double.class)
175 return toSourceString((double) value);
176 else if (type == float.class)
177 return toSourceString((float) value);
178 else if (type == long.class)
179 return toSourceString((long) value);
180 else
181 return value.toString();
182 } else {
They will never match!
Also, sometimes you use "else if (...)" and sometimes just "if (...)".
They are both logically correct as you always "return" in the body of
the previous if statement, but it is not very consistent...
Otherwise looks good.
Regards, Peter
On 08/01/2016 11:39 PM, joe darcy wrote:
> This change should cover 99 44/100 % of the annotation values that
> appear in practice; limited efforts were taken quoting characters in
> strings, etc.
>
> The basic approach is to introduce a family of overloaded
> toSourceString methods to wrap/filter different kinds of values
> coupled with methods to convert the various primitive arrays to
> Stream<String> for final processing by a shared method to surround an
> array by "{" and "}" and add comma separators as needed.
>
> Thanks,
>
> -Joe
More information about the core-libs-dev
mailing list