< prev index next >

src/java.base/share/classes/java/lang/Class.java

Print this page
rev 54515 : 8222151: refactoring: enhancements to java.lang.Class::methodToString and java.lang.Class::getTypeName

*** 275,286 **** sb.append(Arrays.stream(typeparms) .map(Class::typeVarBounds) .collect(Collectors.joining(",", "<", ">"))); } ! for (int i = 0; i < arrayDepth; i++) ! sb.append("[]"); return sb.toString(); } } --- 275,285 ---- sb.append(Arrays.stream(typeparms) .map(Class::typeVarBounds) .collect(Collectors.joining(",", "<", ">"))); } ! if (arrayDepth > 0) sb.append("[]".repeat(arrayDepth)); return sb.toString(); } }
*** 1587,1602 **** int dimensions = 0; do { dimensions++; cl = cl.getComponentType(); } while (cl.isArray()); ! StringBuilder sb = new StringBuilder(); ! sb.append(cl.getName()); ! for (int i = 0; i < dimensions; i++) { ! sb.append("[]"); ! } ! return sb.toString(); } catch (Throwable e) { /*FALLTHRU*/ } } return getName(); } --- 1586,1596 ---- int dimensions = 0; do { dimensions++; cl = cl.getComponentType(); } while (cl.isArray()); ! return cl.getName() + "[]".repeat(dimensions); } catch (Throwable e) { /*FALLTHRU*/ } } return getName(); }
*** 3416,3434 **** /** * Helper method to get the method name from arguments. */ private String methodToString(String name, Class<?>[] argTypes) { ! StringBuilder sb = new StringBuilder(); ! sb.append(getName() + "." + name + "("); ! if (argTypes != null) { ! sb.append(Arrays.stream(argTypes) ! .map(c -> (c == null) ? "null" : c.getName()) ! .collect(Collectors.joining(","))); ! } ! sb.append(")"); ! return sb.toString(); } /** use serialVersionUID from JDK 1.1 for interoperability */ private static final long serialVersionUID = 3206093459760846163L; --- 3410,3427 ---- /** * Helper method to get the method name from arguments. */ private String methodToString(String name, Class<?>[] argTypes) { ! String prefix = getName() + '.' + name; ! if (argTypes == null || argTypes.length == 0) { ! return prefix + "()"; ! } ! return prefix ! + Arrays.stream(argTypes) ! .map(c -> c == null ? "null" : c.getName()) ! .collect(Collectors.joining(",", "(", ")")); } /** use serialVersionUID from JDK 1.1 for interoperability */ private static final long serialVersionUID = 3206093459760846163L;
< prev index next >