MethodHandleDesc interface in Java

java.lang.constant.MethodHandleDesc

A nominal descriptor for a MethodHandle constant.

Declaration

public interface MethodHandleDesc extends ConstantDesc {

    static DirectMethodHandleDesc of(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String name,
            String lookupDescriptor) {
        switch (kind) {
        case GETTER:
        case SETTER:
        case STATIC_GETTER:
        case STATIC_SETTER:
            return ofField(kind, owner, name, ClassDesc.ofDescriptor(lookupDescriptor));
        default:
            return new DirectMethodHandleDescImpl(kind, owner, name, MethodTypeDesc.ofDescriptor(lookupDescriptor));
        }
    }

    static DirectMethodHandleDesc ofMethod(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String name,
            MethodTypeDesc lookupMethodType) {
        switch (kind) {
        case GETTER:
        case SETTER:
        case STATIC_GETTER:
        case STATIC_SETTER:
            throw new IllegalArgumentException(kind.toString());
        case VIRTUAL:
        case SPECIAL:
        case INTERFACE_VIRTUAL:
        case INTERFACE_SPECIAL:
        case INTERFACE_STATIC:
        case STATIC:
        case CONSTRUCTOR:
            return new DirectMethodHandleDescImpl(kind, owner, name, lookupMethodType);
        default:
            throw new IllegalArgumentException(kind.toString());
        }
    }

    static DirectMethodHandleDesc ofField(DirectMethodHandleDesc.Kind kind, ClassDesc owner, String fieldName,
            ClassDesc fieldType) {
        MethodTypeDesc mtr;
        switch (kind) {
        case GETTER:
            mtr = MethodTypeDesc.of(fieldType, owner);
            break;
        case SETTER:
            mtr = MethodTypeDesc.of(CD_void, owner, fieldType);
            break;
        case STATIC_GETTER:
            mtr = MethodTypeDesc.of(fieldType);
            break;
        case STATIC_SETTER:
            mtr = MethodTypeDesc.of(CD_void, fieldType);
            break;
        default:
            throw new IllegalArgumentException(kind.toString());
        }
        return new DirectMethodHandleDescImpl(kind, owner, fieldName, mtr);
    }

    static DirectMethodHandleDesc ofConstructor(ClassDesc owner, ClassDesc... paramTypes) {
        return MethodHandleDesc.ofMethod(CONSTRUCTOR, owner, ConstantDescs.DEFAULT_NAME,
                MethodTypeDesc.of(CD_void, paramTypes));
    }

    default MethodHandleDesc asType(MethodTypeDesc type) {
        return (invocationType().equals(type)) ? this : new AsTypeMethodHandleDesc(this, type);
    }

    MethodTypeDesc invocationType();

    boolean equals(Object o);
}


Methods

1. of(Kind kind, ClassDesc owner, String name, String lookupDescriptor)

DirectMethodHandleDesc java.lang.constant.MethodHandleDesc.of(Kind kind, ClassDesc owner, String name, String lookupDescriptor)

This method takes four arguments. This method creates a MethodHandleDesc corresponding to an invocation of a declared method, invocation of a constructor, or access to a field.

Parameters: Four parameters are required for this method.

kind: The kind of method handle to be described.

owner: a ClassDesc describing the class containing the method, constructor, or field.

name: the unqualified name of the method or field.

lookupDescriptor: a method descriptor string the lookup type, if the request is for a method invocation, or describing the invocation type if the request is for a field or constructor.

Returns: the MethodHandleDesc.

Throws:

1. NullPointerException - if any of the non-ignored arguments are null.

2. IllegalArgumentException - if the descriptor string is not a valid method or field descriptor.


2. DirectMethodHandleDesc java.lang.constant.MethodHandleDesc.ofMethod(Kind kind, ClassDesc owner, String name, MethodTypeDesc lookupMethodType)

This method takes four arguments. This method creates a MethodHandleDesc corresponding to an invocation of a declared method or constructor.

Parameters: Four parameters are required for this method.

kind: The kind of method handle to be described; must be one of SPECIAL, VIRTUAL, STATIC, INTERFACE_SPECIAL, INTERFACE_VIRTUAL, INTERFACE_STATIC, CONSTRUCTOR.

owner: a ClassDesc describing the class containing the method or constructor.

name: the unqualified name of the method (ignored if the kind is CONSTRUCTOR).

lookupMethodType: a MethodTypeDesc describing the lookup type.

Returns: the MethodHandleDesc.

Throws:

1. NullPointerException - if any non-ignored arguments are null.

2. IllegalArgumentException - if the name has the incorrect format or the kind is invalid.


3. ofField(Kind kind, ClassDesc owner, String fieldName, ClassDesc fieldType)

DirectMethodHandleDesc java.lang.constant.MethodHandleDesc.ofField(Kind kind, ClassDesc owner, String fieldName, ClassDesc fieldType)

This method takes four arguments. This method creates a MethodHandleDesc corresponding to a method handle that accesses a field.

Parameters: Four parameters are required for this method.

kind: the kind of method handle to be described; must be one of GETTER, SETTER, STATIC_GETTER, or STATIC_SETTER.

owner: a ClassDesc describing the class containing the field.

fieldName: the unqualified name of the field.

fieldType: a ClassDesc describing the type of the field.

Returns: the MethodHandleDesc.

Throws:

1. NullPointerException - if any of the arguments are null.

2. IllegalArgumentException - if the kind is not one of the valid values or if the field name is not valid.


4. ofConstructor(ClassDesc owner, ClassDesc... paramTypes)

DirectMethodHandleDesc java.lang.constant.MethodHandleDesc.ofConstructor(ClassDesc owner, ClassDesc... paramTypes)

This method takes two arguments. This method returns a MethodHandleDesc corresponding to the invocation of a constructor

Parameters: Two parameters are required for this method.

owner: a ClassDesc describing the class containing the constructor.

paramTypes: ClassDescs describing the parameter types of the constructor.

Returns: the MethodHandleDesc.

Throws:

1. NullPointerException - if any argument or its contents is null.


5. asType(MethodTypeDesc type)

MethodHandleDesc java.lang.constant.MethodHandleDesc.asType(MethodTypeDesc type)

This method takes one argument. This method returns a MethodHandleDesc that describes this method handle adapted to a different type.

Parameters: One parameter is required for this method.

type: a MethodHandleDesc describing the new method type.

Returns: a MethodHandleDesc for the adapted method handle.

Throws:

1. NullPointerException - if the argument is null.


6. invocationType()

MethodTypeDesc java.lang.constant.MethodHandleDesc.invocationType()

This method returns a MethodTypeDesc describing the invocation type of the method handle described by this nominal descriptor. The invocation type describes the full set of stack values that are consumed by the invocation.

Parameters: NA

Returns: MethodHandleDesc describing the method handle type.


7. equals(Object o)

boolean java.lang.constant.MethodHandleDesc.equals(Object o)

This method takes one argument. This method compares the specified object with this descriptor for equality. Returns true if and only if the specified object is also a MethodHandleDesc, and both encode the same nominal description of a method handle.

Parameters: One parameter is required for this method.

o: the other object.

Returns: whether this descriptor is equal to the other object.


Some other classes/interfaces of java.lang.constant

MethodTypeDescA nominal descriptor for a MethodType constant.

MethodHandleDescA nominal descriptor for a MethodHandle constant.

DynamicConstantDescA nominal descriptor for a dynamic constant.

DynamicCallSiteDescA nominal descriptor for an invoke dynamic call site.

DirectMethodHandleDescA nominal descriptor for a direct MethodHandle. A DirectMethodHandleDesc corresponds to a Constant_MethodHandle_info entry in the constant pool of a class file.

ConstantDescsPredefined values of nominal descriptors for common constants, including descriptors for primitive class types and other common platform types, and descriptors for method handles for standard bootstrap methods.

ConstantDescA nominal descriptor for a loadable constant value. Such a descriptor can be resolved via ConstantDesc.resolveConstantDesc(MethodHandles.Lookup) to yield the constant value itself.

ConstableRepresents a type that is constable. A constable type is one whose values are constants that can be represented in the constant pool of a Java class file.

ClassDescA nominal descriptor for a Class constant.

No comments:

Post a Comment