|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.dyn.MethodType
public final class MethodType
Disabled: no SafeJ information.
Run-time token used to match call sites with method handles.
The structure is a return type accompanied by any number of parameter types.
The types (primitive, void, and reference) are represented by Class objects.
All instances of MethodType
are immutable.
Two instances are completely interchangeable if they compare equal.
Equality depends exactly on the return and parameter types.
This type can be created only by factory methods, which manage interning.
Method Summary | |
---|---|
MethodType |
changeParameterType(int num,
Class<?> nptype)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
changeReturnType(Class<?> nrtype)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
dropParameterType(int num)
Deprecated. Use dropParameterTypes(int, int) instead. |
MethodType |
dropParameterTypes(int start,
int end)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
boolean |
equals(Object x)
Compares the specified object with this type for equality. |
MethodType |
erase()
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
fromBytecodeString(String descriptor,
ClassLoader loader)
Temporary alias for fromMethodDescriptorString; delete after M3. |
static MethodType |
fromMethodDescriptorString(String descriptor,
ClassLoader loader)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
generic()
Convenience method for genericMethodType(int) . |
static MethodType |
genericMethodType(int objectArgCount)
All parameters and the return type will be Object. |
static MethodType |
genericMethodType(int objectArgCount,
boolean varargs)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
int |
hashCode()
Returns the hash code value for this method type. |
boolean |
hasPrimitives()
Convenience method. |
boolean |
hasWrappers()
Convenience method. |
MethodType |
insertParameterType(int num,
Class<?> nptype)
Deprecated. Use insertParameterTypes(int, java.lang.Class>...) instead. |
MethodType |
insertParameterTypes(int num,
Class<?>... ptypesToInsert)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
insertParameterTypes(int num,
List<Class<?>> ptypesToInsert)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
make(Class<?> rtype)
Deprecated. |
static MethodType |
make(Class<?> rtype,
Class<?> ptype0)
Deprecated. |
static MethodType |
make(Class<?> rtype,
Class<?>[] ptypes)
Deprecated. |
static MethodType |
make(Class<?> rtype,
Class<?> ptype0,
Class<?>... ptypes)
Deprecated. |
static MethodType |
make(Class<?> rtype,
List<? extends Class<?>> ptypes)
Deprecated. |
static MethodType |
make(Class<?> rtype,
MethodType ptypes)
Deprecated. |
static MethodType |
makeGeneric(int objectArgCount)
Deprecated. |
static MethodType |
makeGeneric(int objectArgCount,
boolean varargs)
Deprecated. |
static MethodType |
methodType(Class<?> rtype)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
Class<?> ptype0)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
Class<?>[] ptypes)
Find or create an instance of the given method type. |
static MethodType |
methodType(Class<?> rtype,
Class<?> ptype0,
Class<?>... ptypes)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
List<? extends Class<?>> ptypes)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
static MethodType |
methodType(Class<?> rtype,
MethodType ptypes)
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
Class<?>[] |
parameterArray()
Convenience method to present the arguments as an array. |
int |
parameterCount()
|
List<Class<?>> |
parameterList()
Convenience method to present the arguments as a list. |
int |
parameterSlotCount()
The number of JVM stack slots required to invoke a method of this type. |
int |
parameterSlotDepth(int num)
Number of JVM stack slots which carry all parameters including and after the given position, which must be in the range of 0 to parameterCount inclusive. |
Class<?> |
parameterType(int num)
|
int |
returnSlotCount()
The number of JVM stack slots required to receive a return value from a method of this type. |
Class<?> |
returnType()
|
String |
toBytecodeString()
Temporary alias for toMethodDescriptorString; delete after M3. |
String |
toMethodDescriptorString()
Create a bytecode signature representation of the type. |
String |
toString()
The string representation of a method type is a parenthesis enclosed, comma separated list of type names, followed immediately by the return type. |
MethodType |
unwrap()
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
MethodType |
wrap()
Convenience method for methodType(java.lang.Class, java.lang.Class[]) . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static MethodType methodType(Class<?> rtype, Class<?>[] ptypes)
rtype
- the return typeptypes
- the parameter types
NullPointerException
- if rtype or any ptype is null
IllegalArgumentException
- if any of the ptypes is void@Deprecated public static MethodType make(Class<?> rtype, Class<?>[] ptypes)
public static MethodType methodType(Class<?> rtype, List<? extends Class<?>> ptypes)
methodType(java.lang.Class, java.lang.Class[])
.
@Deprecated public static MethodType make(Class<?> rtype, List<? extends Class<?>> ptypes)
public static MethodType methodType(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes)
methodType(java.lang.Class, java.lang.Class[])
.
The leading parameter type is prepended to the remaining array.
@Deprecated public static MethodType make(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes)
public static MethodType methodType(Class<?> rtype)
methodType(java.lang.Class, java.lang.Class[])
.
The resulting method has no parameter types.
@Deprecated public static MethodType make(Class<?> rtype)
public static MethodType methodType(Class<?> rtype, Class<?> ptype0)
methodType(java.lang.Class, java.lang.Class[])
.
The resulting method has the single given parameter type.
@Deprecated public static MethodType make(Class<?> rtype, Class<?> ptype0)
public static MethodType methodType(Class<?> rtype, MethodType ptypes)
methodType(java.lang.Class, java.lang.Class[])
.
The resulting method has the same parameter types as ptypes
,
and the specified return type.
@Deprecated public static MethodType make(Class<?> rtype, MethodType ptypes)
public static MethodType genericMethodType(int objectArgCount, boolean varargs)
methodType(java.lang.Class, java.lang.Class[])
.
All parameters and the return type will be Object
,
except the final varargs parameter if any, which will be Object[]
.
objectArgCount
- number of parameters (excluding the varargs parameter if any)varargs
- whether there will be a varargs parameter, of type Object[]
genericMethodType(int)
@Deprecated public static MethodType makeGeneric(int objectArgCount, boolean varargs)
public static MethodType genericMethodType(int objectArgCount)
objectArgCount
- number of parameters
genericMethodType(int, boolean)
@Deprecated public static MethodType makeGeneric(int objectArgCount)
public MethodType changeParameterType(int num, Class<?> nptype)
methodType(java.lang.Class, java.lang.Class[])
.
num
- the index (zero-based) of the parameter type to changenptype
- a new parameter type to replace the old one with
@Deprecated public MethodType insertParameterType(int num, Class<?> nptype)
insertParameterTypes(int, java.lang.Class>...)
instead.
insertParameterTypes(int, java.lang.Class>...)
.
public MethodType insertParameterTypes(int num, Class<?>... ptypesToInsert)
methodType(java.lang.Class, java.lang.Class[])
.
num
- the position (zero-based) of the inserted parameter type(s)ptypesToInsert
- zero or more a new parameter types to insert into the parameter list
public MethodType insertParameterTypes(int num, List<Class<?>> ptypesToInsert)
methodType(java.lang.Class, java.lang.Class[])
.
num
- the position (zero-based) of the inserted parameter type(s)ptypesToInsert
- zero or more a new parameter types to insert into the parameter list
public MethodType dropParameterTypes(int start, int end)
methodType(java.lang.Class, java.lang.Class[])
.
start
- the index (zero-based) of the first parameter type to removeend
- the index (greater than start
) of the first parameter type after not to remove
@Deprecated public MethodType dropParameterType(int num)
dropParameterTypes(int, int)
instead.
dropParameterTypes(int, int)
.
public MethodType changeReturnType(Class<?> nrtype)
methodType(java.lang.Class, java.lang.Class[])
.
nrtype
- a return parameter type to replace the old one with
public boolean hasPrimitives()
void
counts as a primitive.
public boolean hasWrappers()
Integer
.
The reference type java.lang.Void
counts as a wrapper.
public MethodType erase()
methodType(java.lang.Class, java.lang.Class[])
.
Erase all reference types to Object
.
All primitive types (including void
) will remain unchanged.
public MethodType generic()
genericMethodType(int)
.
Convert all types, both reference and primitive, to Object
.
The expression type.wrap().erase()
produces the same value
as type.generic()
.
public MethodType wrap()
methodType(java.lang.Class, java.lang.Class[])
.
Convert all primitive types to their corresponding wrapper types.
All reference types (including wrapper types) will remain unchanged.
A void
return type is changed to the type java.lang.Void
.
The expression type.wrap().erase()
produces the same value
as type.generic()
.
public MethodType unwrap()
methodType(java.lang.Class, java.lang.Class[])
.
Convert all wrapper types to their corresponding primitive types.
All primitive types (including void
) will remain unchanged.
A return type of java.lang.Void
is changed to void
.
public Class<?> parameterType(int num)
num
- the index (zero-based) of the desired parameter type
public int parameterCount()
public Class<?> returnType()
public List<Class<?>> parameterList()
public Class<?>[] parameterArray()
public boolean equals(Object x)
equals
in class Object
x
- object to compare
true
if this object is the same as the obj
argument; false
otherwise.Object.equals(Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
,
equals(Object)
,
List.hashCode()
public String toString()
If a type name is array, it the base type followed by [], rather than the Class.getName of the array type.
toString
in class Object
public int parameterSlotCount()
parameterCount()
plus the
number of long and double parameters (if any).
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
public int parameterSlotDepth(int num)
parameterCount
inclusive. Successive parameters are
more shallowly stacked, and parameters are indexed in the bytecodes
according to their trailing edge. Thus, to obtain the depth
in the outgoing call stack of parameter N
, obtain
the parameterSlotDepth
of its trailing edge
at position N+1
.
Parameters of type long
and double
occupy
two stack slots (for historical reasons) and all others occupy one.
Therefore, the number returned is the number of arguments
including and after the given parameter,
plus the number of long or double arguments
at or after after the argument for the given parameter.
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
num
- an index (zero-based, inclusive) within the parameter types
public int returnSlotCount()
return type
is void, it will be zero,
else if the return type is long or double, it will be two, else one.
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
public static MethodType fromMethodDescriptorString(String descriptor, ClassLoader loader) throws IllegalArgumentException, TypeNotPresentException
methodType(java.lang.Class, java.lang.Class[])
.
Find or create an instance (interned) of the given method type.
Any class or interface name embedded in the signature string
will be resolved by calling ClassLoader.loadClass(java.lang.String)
on the given loader (or if it is null, on the system class loader).
Note that it is possible to build method types which cannot be constructed by this method, because their component types are not all reachable from a common class loader.
This method is included for the benfit of applications that must generate bytecodes that process method handles and invokedynamic.
descriptor
- a bytecode-level signature string "(T...)T"loader
- the class loader in which to look up the types
IllegalArgumentException
- if the string is not well-formed
TypeNotPresentException
- if a named type cannot be foundpublic String toMethodDescriptorString()
This method is included for the benfit of applications that must
generate bytecodes that process method handles and invokedynamic.
fromMethodDescriptorString(java.lang.String, java.lang.ClassLoader)
,
because the latter requires a suitable class loader argument.
public String toBytecodeString()
public static MethodType fromBytecodeString(String descriptor, ClassLoader loader) throws IllegalArgumentException, TypeNotPresentException
IllegalArgumentException
TypeNotPresentException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |