8222151: refactoring: enhancements to java.lang.Class::methodToString and java.lang.Class::getTypeName

Reviewed-by: darcy
This commit is contained in:
Sergei Tsypanov 2019-04-11 22:56:11 -04:00 committed by Vicente Romero
parent d03cf75344
commit 9d979eaf56

View File

@ -277,8 +277,7 @@ public final class Class<T> implements java.io.Serializable,
.collect(Collectors.joining(",", "<", ">")));
}
for (int i = 0; i < arrayDepth; i++)
sb.append("[]");
if (arrayDepth > 0) sb.append("[]".repeat(arrayDepth));
return sb.toString();
}
@ -1589,12 +1588,7 @@ public final class Class<T> implements java.io.Serializable,
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();
return cl.getName() + "[]".repeat(dimensions);
} catch (Throwable e) { /*FALLTHRU*/ }
}
return getName();
@ -3418,15 +3412,12 @@ public final class Class<T> implements java.io.Serializable,
* 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();
return getName() + '.' + name +
((argTypes == null || argTypes.length == 0) ?
"()" :
Arrays.stream(argTypes)
.map(c -> c == null ? "null" : c.getName())
.collect(Collectors.joining(",", "(", ")")));
}
/** use serialVersionUID from JDK 1.1 for interoperability */