< prev index next >

src/java.base/share/classes/java/lang/constant/MethodTypeDescImpl.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,11 +26,14 @@
 
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 
+import jdk.internal.lang.annotation.Foldable;
+import static java.lang.constant.ConstantDescs.BSM_INVOKE;
 import static java.util.Objects.requireNonNull;
 
 /**
  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a
  * {@link MethodType}.  A {@linkplain MethodTypeDescImpl} corresponds to a

@@ -63,27 +66,31 @@
      * @return a {@linkplain MethodTypeDescImpl} describing the desired method type
      * @throws IllegalArgumentException if the descriptor string is not a valid
      * method descriptor
      * @jvms 4.3.3 Method Descriptors
      */
+    @Foldable
     static MethodTypeDescImpl ofDescriptor(String descriptor) {
         requireNonNull(descriptor);
         List<String> types = ConstantUtils.parseMethodDescriptor(descriptor);
         ClassDesc[] paramTypes = types.stream().skip(1).map(ClassDesc::ofDescriptor).toArray(ClassDesc[]::new);
         return new MethodTypeDescImpl(ClassDesc.ofDescriptor(types.get(0)), paramTypes);
     }
 
+    @Foldable
     @Override
     public ClassDesc returnType() {
         return returnType;
     }
 
+    @Foldable
     @Override
     public int parameterCount() {
         return argTypes.length;
     }
 
+    @Foldable
     @Override
     public ClassDesc parameterType(int index) {
         return argTypes[index];
     }
 

@@ -95,32 +102,38 @@
     @Override
     public ClassDesc[] parameterArray() {
         return argTypes.clone();
     }
 
+    @Foldable
     @Override
     public MethodTypeDesc changeReturnType(ClassDesc returnType) {
         return MethodTypeDesc.of(returnType, argTypes);
     }
 
+    @Foldable
     @Override
     public MethodTypeDesc changeParameterType(int index, ClassDesc paramType) {
         ClassDesc[] newArgs = argTypes.clone();
         newArgs[index] = paramType;
         return MethodTypeDesc.of(returnType, newArgs);
     }
 
+    @Foldable
     @Override
     public MethodTypeDesc dropParameterTypes(int start, int end) {
-        if (start < 0 || start >= argTypes.length || end < 0 || end > argTypes.length || start > end)
+        if (start < 0 || start >= argTypes.length || end < 0 || end > argTypes.length)
             throw new IndexOutOfBoundsException();
+        else if (start > end)
+            throw new IllegalArgumentException(String.format("Range (%d, %d) not valid for size %d", start, end, argTypes.length));
         ClassDesc[] newArgs = new ClassDesc[argTypes.length - (end - start)];
         System.arraycopy(argTypes, 0, newArgs, 0, start);
         System.arraycopy(argTypes, end, newArgs, start, argTypes.length - end);
         return MethodTypeDesc.of(returnType, newArgs);
     }
 
+    @Foldable
     @Override
     public MethodTypeDesc insertParameterTypes(int pos, ClassDesc... paramTypes) {
         if (pos < 0 || pos > argTypes.length)
             throw new IndexOutOfBoundsException(pos);
         ClassDesc[] newArgs = new ClassDesc[argTypes.length + paramTypes.length];

@@ -166,6 +179,11 @@
 
     @Override
     public String toString() {
         return String.format("MethodTypeDesc[%s]", displayDescriptor());
     }
+
+    @Override
+    public Optional<? extends ConstantDesc> describeConstable() {
+        return Optional.empty();
+    }
 }
< prev index next >