8306698: Add overloads to MethodTypeDesc::of

Reviewed-by: mchung
This commit is contained in:
Chen Liang 2023-05-23 21:26:25 +00:00 committed by Mandy Chung
parent 6b27dad76e
commit 8ffa264cf0
3 changed files with 53 additions and 38 deletions

View file

@ -36,6 +36,7 @@ import static java.util.Objects.requireNonNull;
class ConstantUtils {
/** an empty constant descriptor */
public static final ConstantDesc[] EMPTY_CONSTANTDESC = new ConstantDesc[0];
static final ClassDesc[] EMPTY_CLASSDESC = new ClassDesc[0];
static final Constable[] EMPTY_CONSTABLE = new Constable[0];
static final int MAX_ARRAY_TYPE_DESC_DIMENSIONS = 255;

View file

@ -55,6 +55,34 @@ public sealed interface MethodTypeDesc
return MethodTypeDescImpl.ofDescriptor(descriptor);
}
/**
* {@return a {@linkplain MethodTypeDesc} with the given return type and no
* parameter types}
*
* @param returnDesc a {@linkplain ClassDesc} describing the return type
* @throws NullPointerException if {@code returnDesc} is {@code null}
* @since 21
*/
static MethodTypeDesc of(ClassDesc returnDesc) {
return new MethodTypeDescImpl(returnDesc, ConstantUtils.EMPTY_CLASSDESC);
}
/**
* {@return a {@linkplain MethodTypeDesc} given the return type and a list of
* parameter types}
*
* @param returnDesc a {@linkplain ClassDesc} describing the return type
* @param paramDescs a {@linkplain List} of {@linkplain ClassDesc}s
* describing the parameter types
* @throws NullPointerException if any argument or its contents are {@code null}
* @throws IllegalArgumentException if any element of {@code paramDescs} is a
* {@link ClassDesc} for {@code void}
* @since 21
*/
static MethodTypeDesc of(ClassDesc returnDesc, List<ClassDesc> paramDescs) {
return of(returnDesc, paramDescs.toArray(ConstantUtils.EMPTY_CLASSDESC));
}
/**
* Returns a {@linkplain MethodTypeDesc} given the return type and parameter
* types.