< prev index next >

src/java.base/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 143,166 **** StringBuilder result = new StringBuilder(128); result.append('@'); result.append(type.getName()); result.append('('); boolean firstMember = true; ! Set<Map.Entry<String, Object>> entries = memberValues.entrySet(); ! boolean loneValue = entries.size() == 1; ! for (Map.Entry<String, Object> e : entries) { if (firstMember) firstMember = false; else result.append(", "); ! String key = e.getKey(); ! if (!loneValue || !"value".equals(key)) { ! result.append(key); ! result.append('='); ! } ! loneValue = false; result.append(memberValueToString(e.getValue())); } result.append(')'); return result.toString(); } --- 143,160 ---- StringBuilder result = new StringBuilder(128); result.append('@'); result.append(type.getName()); result.append('('); boolean firstMember = true; ! for (Map.Entry<String, Object> e : memberValues.entrySet()) { if (firstMember) firstMember = false; else result.append(", "); ! result.append(e.getKey()); ! result.append('='); result.append(memberValueToString(e.getValue())); } result.append(')'); return result.toString(); }
*** 182,193 **** return toSourceString((double) value); else if (type == Float.class) return toSourceString((float) value); else if (type == Long.class) return toSourceString((long) value); - else if (type == Byte.class) - return toSourceString((byte) value); else return value.toString(); } else { Stream<String> stringStream; if (type == byte[].class) --- 176,185 ----
*** 227,244 **** * Translates a Class value to a form suitable for use in the * string representation of an annotation. */ private static String toSourceString(Class<?> clazz) { Class<?> finalComponent = clazz; ! StringBuilder arrayBrackets = new StringBuilder(); while(finalComponent.isArray()) { finalComponent = finalComponent.getComponentType(); ! arrayBrackets.append("[]"); } ! return finalComponent.getName() + arrayBrackets.toString() + ".class"; } private static String toSourceString(float f) { if (Float.isFinite(f)) return Float.toString(f) + "f" ; --- 219,236 ---- * Translates a Class value to a form suitable for use in the * string representation of an annotation. */ private static String toSourceString(Class<?> clazz) { Class<?> finalComponent = clazz; ! StringBuilder arrayBackets = new StringBuilder(); while(finalComponent.isArray()) { finalComponent = finalComponent.getComponentType(); ! arrayBackets.append("[]"); } ! return finalComponent.getName() + arrayBackets.toString() + ".class" ; } private static String toSourceString(float f) { if (Float.isFinite(f)) return Float.toString(f) + "f" ;
*** 262,329 **** } private static String toSourceString(char c) { StringBuilder sb = new StringBuilder(4); sb.append('\''); ! sb.append(quote(c)); ! return sb.append('\'') .toString(); ! } ! ! /** ! * Escapes a character if it has an escape sequence or is ! * non-printable ASCII. Leaves non-ASCII characters alone. ! */ ! private static String quote(char ch) { ! switch (ch) { ! case '\b': return "\\b"; ! case '\f': return "\\f"; ! case '\n': return "\\n"; ! case '\r': return "\\r"; ! case '\t': return "\\t"; ! case '\'': return "\\'"; ! case '\"': return "\\\""; ! case '\\': return "\\\\"; ! default: ! return (isPrintableAscii(ch)) ! ? String.valueOf(ch) ! : String.format("\\u%04x", (int) ch); ! } ! } ! ! /** ! * Is a character printable ASCII? ! */ ! private static boolean isPrintableAscii(char ch) { ! return ch >= ' ' && ch <= '~'; ! } ! ! private static String toSourceString(byte b) { ! return String.format("(byte)0x%02x", b); } private static String toSourceString(long ell) { ! return String.valueOf(ell) + "L"; } /** * Return a string suitable for use in the string representation * of an annotation. */ private static String toSourceString(String s) { StringBuilder sb = new StringBuilder(); sb.append('"'); ! for (int i = 0; i < s.length(); i++) { ! sb.append(quote(s.charAt(i))); ! } sb.append('"'); return sb.toString(); } private static Stream<String> convert(byte[] values) { List<String> list = new ArrayList<>(values.length); for (byte b : values) ! list.add(toSourceString(b)); return list.stream(); } private static Stream<String> convert(char[] values) { List<String> list = new ArrayList<>(values.length); --- 254,295 ---- } private static String toSourceString(char c) { StringBuilder sb = new StringBuilder(4); sb.append('\''); ! if (c == '\'') ! sb.append("\\'"); ! else ! sb.append(c); ! return sb.append('\'') ! .toString(); } private static String toSourceString(long ell) { ! String str = String.valueOf(ell); ! return (ell < Integer.MIN_VALUE || ell > Integer.MAX_VALUE) ! ? (str + 'L') : str; } /** * Return a string suitable for use in the string representation * of an annotation. */ private static String toSourceString(String s) { StringBuilder sb = new StringBuilder(); sb.append('"'); ! // Escape embedded quote characters, if present, but don't do ! // anything more heroic. ! sb.append(s.replace("\"", "\\\"")); sb.append('"'); return sb.toString(); } private static Stream<String> convert(byte[] values) { List<String> list = new ArrayList<>(values.length); for (byte b : values) ! list.add(Byte.toString(b)); return list.stream(); } private static Stream<String> convert(char[] values) { List<String> list = new ArrayList<>(values.length);
< prev index next >