OpenJDK / amber / amber
changeset 58608:d1cbaf90642d records
applying reflection review comments
author | vromero |
---|---|
date | Fri, 01 Nov 2019 20:15:41 -0400 |
parents | d56cbf3378df |
children | 81d8f438d66d |
files | src/java.base/share/classes/java/lang/annotation/ElementType.java src/java.base/share/classes/java/lang/reflect/RecordComponent.java src/java.base/share/classes/java/lang/runtime/ObjectMethods.java |
diffstat | 3 files changed, 38 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/annotation/ElementType.java Fri Nov 01 17:17:37 2019 -0400 +++ b/src/java.base/share/classes/java/lang/annotation/ElementType.java Fri Nov 01 20:15:41 2019 -0400 @@ -127,6 +127,9 @@ * * Record component * + * @jls 8.10.3 Record Members + * @jls 9.7.4 Where Annotations May Appear + * * @since 14 */ @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
--- a/src/java.base/share/classes/java/lang/reflect/RecordComponent.java Fri Nov 01 17:17:37 2019 -0400 +++ b/src/java.base/share/classes/java/lang/reflect/RecordComponent.java Fri Nov 01 20:15:41 2019 -0400 @@ -237,21 +237,37 @@ /** * Returns a string describing this record component, including - * its generic type. The format is: the access modifiers for the - * record component, always {@code private} and {@code final}, in that - * order, followed by the generic record component type, followed by a - * space, followed by the fully-qualified name of the class declaring - * the record component, followed by a period, followed by the name of - * the record component. + * its generic type. The format is: the generic record component type, + * followed by a space, followed by the fully-qualified name of the + * record class declaring the record component, followed by a period, + * followed by the name of the record component. * * @return a string describing this record component, including its * generic type */ public String toGenericString() { - int mod = Modifier.PRIVATE | Modifier.FINAL; Type type = getGenericType(); - return (((mod == 0) ? "" : (Modifier.toString(mod) + " ")) - + type.getTypeName() + " " + return (type.getTypeName() + " " + + getDeclaringClass().getTypeName() + "." + + getName()); + } + + /** + * Returns a string describing this record component. The format is + * the record component type, followed by a space, followed by + * the fully-qualified name of the class declaring the record + * component, followed by a period, followed by the name of the + * record component. + * For example: + * <pre> + * String Person.name + * int Person.age + * </pre> + * + * @return a string describing this record component + */ + public String toString() { + return (getType().getTypeName() + " " + getDeclaringClass().getTypeName() + "." + getName()); }
--- a/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java Fri Nov 01 17:17:37 2019 -0400 +++ b/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java Fri Nov 01 20:15:41 2019 -0400 @@ -304,7 +304,8 @@ * on a description of the component names and accessor methods, for either * {@code invokedynamic} call sites or dynamic constant pool entries * - * @param lookup the lookup + * @param lookup Represents a lookup context with the accessibility + * privileges of the caller. * @param methodName the name of the method to generate, which must be one of * {@code "equals"}, {@code "hashCode"}, or {@code "toString"} * @param type a {@link MethodType} corresponding the descriptor type @@ -313,7 +314,7 @@ * an {@code invokedynamic} call site, or the * constant {@code MethodHandle.class}, if linking a * dynamic constant - * @param theClass the class hosting the components + * @param recordClass the record class hosting the record components * @param names the list of component names, joined into a string * separated by ";", or the empty string if there are no * components. Maybe be null, if the {@code methodName} @@ -326,7 +327,7 @@ * @throws Throwable if any exception is thrown during call site construction */ public static Object bootstrap(MethodHandles.Lookup lookup, String methodName, TypeDescriptor type, - Class<?> theClass, + Class<?> recordClass, String names, MethodHandle... getters) throws Throwable { MethodType methodType; @@ -341,22 +342,22 @@ MethodHandle handle; switch (methodName) { case "equals": - if (methodType != null && !methodType.equals(MethodType.methodType(boolean.class, theClass, Object.class))) + if (methodType != null && !methodType.equals(MethodType.methodType(boolean.class, recordClass, Object.class))) throw new IllegalArgumentException("Bad method type: " + methodType); - handle = makeEquals(theClass, getterList); + handle = makeEquals(recordClass, getterList); return methodType != null ? new ConstantCallSite(handle) : handle; case "hashCode": - if (methodType != null && !methodType.equals(MethodType.methodType(int.class, theClass))) + if (methodType != null && !methodType.equals(MethodType.methodType(int.class, recordClass))) throw new IllegalArgumentException("Bad method type: " + methodType); - handle = makeHashCode(theClass, getterList); + handle = makeHashCode(recordClass, getterList); return methodType != null ? new ConstantCallSite(handle) : handle; case "toString": - if (methodType != null && !methodType.equals(MethodType.methodType(String.class, theClass))) + if (methodType != null && !methodType.equals(MethodType.methodType(String.class, recordClass))) throw new IllegalArgumentException("Bad method type: " + methodType); List<String> nameList = "".equals(names) ? List.of() : List.of(names.split(";")); if (nameList.size() != getterList.size()) throw new IllegalArgumentException("Name list and accessor list do not match"); - handle = makeToString(theClass, getterList, nameList); + handle = makeToString(recordClass, getterList, nameList); return methodType != null ? new ConstantCallSite(handle) : handle; default: throw new IllegalArgumentException(methodName);