< prev index next >

src/java.base/share/classes/java/lang/constant/MethodHandleDesc.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -26,10 +26,12 @@
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 
+import jdk.internal.lang.annotation.Foldable;
+
 import static java.lang.constant.ConstantDescs.CD_void;
 import static java.lang.constant.DirectMethodHandleDesc.Kind.CONSTRUCTOR;
 
 /**
  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a

@@ -41,11 +43,11 @@
  * {@linkplain MethodHandleDesc} directly.
  *
  * @since 12
  */
 public interface MethodHandleDesc
-        extends ConstantDesc {
+        extends ConstantDesc, Constable {
 
     /**
      * Creates a {@linkplain MethodHandleDesc} corresponding to an invocation of a
      * declared method, invocation of a constructor, or access to a field.
      *

@@ -68,17 +70,16 @@
      *                         if the request is for a method invocation, or
      *                         describing the invocation type, if the request is
      *                         for a field or constructor
      * @return the {@linkplain MethodHandleDesc}
      * @throws NullPointerException if any of the non-ignored arguments are null
-     * @throws IllegalArgumentException if the descriptor string is not a valid
-     * method or field descriptor
      * @jvms 4.4.8 The CONSTANT_MethodHandle_info Structure
      * @jvms 4.2.2 Unqualified Names
      * @jvms 4.3.2 Field Descriptors
      * @jvms 4.3.3 Method Descriptors
      */
+    @Foldable
     static DirectMethodHandleDesc of(DirectMethodHandleDesc.Kind kind,
                                      ClassDesc owner,
                                      String name,
                                      String lookupDescriptor) {
         switch (kind) {

@@ -115,10 +116,11 @@
      * @throws NullPointerException if any non-ignored arguments are null
      * @throws IllegalArgumentException if the {@code name} has the incorrect
      * format, or the kind is invalid
      * @jvms 4.2.2 Unqualified Names
      */
+    @Foldable
     static DirectMethodHandleDesc ofMethod(DirectMethodHandleDesc.Kind kind,
                                            ClassDesc owner,
                                            String name,
                                            MethodTypeDesc lookupMethodType) {
         switch (kind) {

@@ -153,10 +155,11 @@
      * @throws NullPointerException if any of the arguments are null
      * @throws IllegalArgumentException if the {@code kind} is not one of the
      * valid values or if the field name is not valid
      * @jvms 4.2.2 Unqualified Names
      */
+    @Foldable
     static DirectMethodHandleDesc ofField(DirectMethodHandleDesc.Kind kind,
                                           ClassDesc owner,
                                           String fieldName,
                                           ClassDesc fieldType) {
         MethodTypeDesc mtr;

@@ -177,12 +180,13 @@
      * @param owner a {@link ClassDesc} describing the class containing the
      *              constructor
      * @param paramTypes {@link ClassDesc}s describing the parameter types of
      *                   the constructor
      * @return the {@linkplain MethodHandleDesc}
-     * @throws NullPointerException if any argument or its contents is {@code null}
+     * @throws NullPointerException if any of the arguments are null
      */
+    @Foldable
     static DirectMethodHandleDesc ofConstructor(ClassDesc owner,
                                                 ClassDesc... paramTypes) {
         return MethodHandleDesc.ofMethod(CONSTRUCTOR, owner, ConstantDescs.DEFAULT_NAME,
                                          MethodTypeDesc.of(CD_void, paramTypes));
     }

@@ -191,12 +195,12 @@
      * Returns a {@linkplain MethodHandleDesc} that describes this method handle
      * adapted to a different type, as if by {@link MethodHandle#asType(MethodType)}.
      *
      * @param type a {@link MethodHandleDesc} describing the new method type
      * @return a {@linkplain MethodHandleDesc} for the adapted method handle
-     * @throws NullPointerException if the argument is {@code null}
      */
+    @Foldable
     default MethodHandleDesc asType(MethodTypeDesc type) {
         return (invocationType().equals(type)) ? this : new AsTypeMethodHandleDesc(this, type);
     }
 
     /**

@@ -205,10 +209,11 @@
      * describes the full set of stack values that are consumed by the invocation
      * (including the receiver, if any).
      *
      * @return a {@linkplain MethodHandleDesc} describing the method handle type
      */
+    @Foldable
     MethodTypeDesc invocationType();
 
     /**
      * Compares the specified object with this descriptor for equality.  Returns
      * {@code true} if and only if the specified object is also a
< prev index next >