--- a/src/java.base/share/classes/java/lang/invoke/MethodType.java Sat Dec 08 18:52:57 2018 -0500
+++ b/src/java.base/share/classes/java/lang/invoke/MethodType.java Sun Dec 09 12:36:24 2018 -0500
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, 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
@@ -25,21 +25,30 @@
package java.lang.invoke;
-import jdk.internal.vm.annotation.Stable;
-import sun.invoke.util.Wrapper;
-import java.lang.ref.WeakReference;
+import java.lang.constant.ClassDesc;
+import java.lang.constant.Constable;
+import java.lang.constant.MethodTypeDesc;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.NoSuchElementException;
import java.util.Objects;
+import java.util.Optional;
import java.util.StringJoiner;
-import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.stream.Stream;
+
+import jdk.internal.vm.annotation.Stable;
import sun.invoke.util.BytecodeDescriptor;
-import static java.lang.invoke.MethodHandleStatics.*;
import sun.invoke.util.VerifyType;
+import sun.invoke.util.Wrapper;
+
+import static java.lang.invoke.MethodHandleStatics.UNSAFE;
+import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException;
/**
* A method type represents the arguments and return type accepted and
@@ -91,7 +100,10 @@
* @since 1.7
*/
public final
-class MethodType implements java.io.Serializable {
+class MethodType
+ implements Constable,
+ TypeDescriptor.OfMethod<Class<?>, MethodType>,
+ java.io.Serializable {
private static final long serialVersionUID = 292L; // {rtype, {ptype...}}
// The rtype and ptypes fields define the structural identity of the method type:
@@ -1175,10 +1187,43 @@
return desc;
}
+ /**
+ * Return a field type descriptor string for this type
+ *
+ * @return the descriptor string
+ * @jvms 4.3.2 Field Descriptors
+ * @since 12
+ */
+ @Override
+ public String descriptorString() {
+ return toMethodDescriptorString();
+ }
+
/*non-public*/ static String toFieldDescriptorString(Class<?> cls) {
return BytecodeDescriptor.unparse(cls);
}
+ /**
+ * Return a nominal descriptor for this instance, if one can be
+ * constructed, or an empty {@link Optional} if one cannot be.
+ *
+ * @return An {@link Optional} containing the resulting nominal descriptor,
+ * or an empty {@link Optional} if one cannot be constructed.
+ * @since 12
+ */
+ @Override
+ public Optional<MethodTypeDesc> describeConstable() {
+ try {
+ return Optional.of(MethodTypeDesc.of(returnType().describeConstable().orElseThrow(),
+ Stream.of(parameterArray())
+ .map(p -> p.describeConstable().orElseThrow())
+ .toArray(ClassDesc[]::new)));
+ }
+ catch (NoSuchElementException e) {
+ return Optional.empty();
+ }
+ }
+
/// Serialization.
/**