8217000: Refactor Class::methodToString

Reviewed-by: smarks
This commit is contained in:
Joe Darcy 2019-01-15 19:10:40 -08:00
parent 3a1f460d19
commit 38cf9d76c8
2 changed files with 25 additions and 22 deletions

View File

@ -272,8 +272,9 @@ public final class Class<T> implements java.io.Serializable,
TypeVariable<?>[] typeparms = component.getTypeParameters(); TypeVariable<?>[] typeparms = component.getTypeParameters();
if (typeparms.length > 0) { if (typeparms.length > 0) {
sb.append(Stream.of(typeparms).map(Class::typeVarBounds). sb.append(Arrays.stream(typeparms)
collect(Collectors.joining(",", "<", ">"))); .map(Class::typeVarBounds)
.collect(Collectors.joining(",", "<", ">")));
} }
for (int i = 0; i < arrayDepth; i++) for (int i = 0; i < arrayDepth; i++)
@ -289,8 +290,9 @@ public final class Class<T> implements java.io.Serializable,
return typeVar.getName(); return typeVar.getName();
} else { } else {
return typeVar.getName() + " extends " + return typeVar.getName() + " extends " +
Stream.of(bounds).map(Type::getTypeName). Arrays.stream(bounds)
collect(Collectors.joining(" & ")); .map(Type::getTypeName)
.collect(Collectors.joining(" & "));
} }
} }
@ -3419,8 +3421,9 @@ public final class Class<T> implements java.io.Serializable,
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(getName() + "." + name + "("); sb.append(getName() + "." + name + "(");
if (argTypes != null) { if (argTypes != null) {
sb.append(Stream.of(argTypes).map(c -> {return (c == null) ? "null" : c.getName();}). sb.append(Arrays.stream(argTypes)
collect(Collectors.joining(","))); .map(c -> (c == null) ? "null" : c.getName())
.collect(Collectors.joining(",")));
} }
sb.append(")"); sb.append(")");
return sb.toString(); return sb.toString();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -111,16 +111,13 @@ public abstract class Executable extends AccessibleObject
printModifiersIfNonzero(sb, modifierMask, isDefault); printModifiersIfNonzero(sb, modifierMask, isDefault);
specificToStringHeader(sb); specificToStringHeader(sb);
sb.append('('); sb.append(Arrays.stream(parameterTypes)
.map(Type::getTypeName)
sb.append(Stream.of(parameterTypes).map(Type::getTypeName). .collect(Collectors.joining(",", "(", ")")));
collect(Collectors.joining(",")));
sb.append(')');
if (exceptionTypes.length > 0) { if (exceptionTypes.length > 0) {
sb.append(Stream.of(exceptionTypes).map(Type::getTypeName). sb.append(Arrays.stream(exceptionTypes)
collect(Collectors.joining(",", " throws ", ""))); .map(Type::getTypeName)
.collect(Collectors.joining(",", " throws ", "")));
} }
return sb.toString(); return sb.toString();
} catch (Exception e) { } catch (Exception e) {
@ -140,8 +137,9 @@ public abstract class Executable extends AccessibleObject
return typeVar.getName(); return typeVar.getName();
} else { } else {
return typeVar.getName() + " extends " + return typeVar.getName() + " extends " +
Stream.of(bounds).map(Type::getTypeName). Arrays.stream(bounds)
collect(Collectors.joining(" & ")); .map(Type::getTypeName)
.collect(Collectors.joining(" & "));
} }
} }
@ -153,8 +151,9 @@ public abstract class Executable extends AccessibleObject
TypeVariable<?>[] typeparms = getTypeParameters(); TypeVariable<?>[] typeparms = getTypeParameters();
if (typeparms.length > 0) { if (typeparms.length > 0) {
sb.append(Stream.of(typeparms).map(Executable::typeVarBounds). sb.append(Arrays.stream(typeparms)
collect(Collectors.joining(",", "<", "> "))); .map(Executable::typeVarBounds)
.collect(Collectors.joining(",", "<", "> ")));
} }
specificToGenericStringHeader(sb); specificToGenericStringHeader(sb);
@ -173,8 +172,9 @@ public abstract class Executable extends AccessibleObject
Type[] exceptionTypes = getGenericExceptionTypes(); Type[] exceptionTypes = getGenericExceptionTypes();
if (exceptionTypes.length > 0) { if (exceptionTypes.length > 0) {
sb.append(Stream.of(exceptionTypes).map(Type::getTypeName). sb.append(Arrays.stream(exceptionTypes)
collect(Collectors.joining(",", " throws ", ""))); .map(Type::getTypeName)
.collect(Collectors.joining(",", " throws ", "")));
} }
return sb.toString(); return sb.toString();
} catch (Exception e) { } catch (Exception e) {