< prev index next >

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

Print this page

        

*** 26,36 **** --- 26,39 ---- 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,89 **** --- 66,96 ---- * @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,116 **** --- 102,126 ---- @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) throw new IndexOutOfBoundsException(); else if (start > end)
*** 119,128 **** --- 129,139 ---- 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];
*** 168,173 **** --- 179,189 ---- @Override public String toString() { return String.format("MethodTypeDesc[%s]", displayDescriptor()); } + + @Override + public Optional<? extends ConstantDesc> describeConstable() { + return Optional.empty(); + } }
< prev index next >