APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.dynalink.linker.support

public final Class Guards

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, java.util.logging.Level, .Logger, jdk.dynalink.DynamicLinker, jdk.dynalink.linker.LinkerServices

Utility methods for creating typical guards for MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle) and for adjusting their method types.
Since
9

Field Summary

Modifier and TypeField and Description
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static MethodHandle

Returns:

the adapted method handle
asType
(final MethodHandle
the test method handle
test
,
final MethodType
the type to adapt the method handle to
type
)

Takes a method handle intended to be used as a guard, and adapts it to the requested type, but returning a boolean.

public static MethodHandle

Returns:

the adapted method handle
asType
(final LinkerServices
the linker services to use for type conversions
linkerServices
,
final MethodHandle
the test method handle
test
,
final MethodType
the type to adapt the method handle to
type
)

Takes a method handle intended to be used as a guard, and adapts it to the requested type, but returning a boolean.

private static MethodHandle
asType(final MethodHandle test, final int pos, final MethodType type)

private static MethodHandle
constantBoolean(final Boolean value, final MethodType type)

private static MethodHandle
private static MethodHandle
private static MethodHandle
getClassBoundArgumentTest(final MethodHandle test, final Class<?> clazz, final int pos, final MethodType type)

public static MethodHandle

Returns:

the desired guard method.
getClassGuard
(final Class<?>
the class to test for.
clazz
)

Creates a guard method that tests its only argument for being of an exact particular class.

public static MethodHandle

Returns:

the desired guard method.
getIdentityGuard
(final Object
the object used as referential identity test
obj
)

Creates a guard method that tests its only argument for being referentially identical to another object

public static MethodHandle

Returns:

the desired guard method.
getInstanceOfGuard
(final Class<?>
the class to test for.
clazz
)

Creates a guard method that tests its only argument for being an instance of a particular class.

private static MethodType
getTestType(final MethodHandle test, final MethodType type)

public static MethodHandle

Returns:

a method handle that returns true if the argument in the specified position is a Java array; the rest of the arguments are ignored.
isArray
(final int
the position in the argument lit
pos
,
final MethodType
the method type of the handle
type
)

Creates a method handle that returns true if the argument in the specified position is a Java array.

private static boolean
isArray(final Object o)

private static boolean
isIdentical(final Object o1, final Object o2)

public static MethodHandle

Returns:

a method handle testing whether its first argument is of the specified class or subclass.
isInstance
(final Class<?>
the class of the first argument to test for
clazz
,
final MethodType
the method type
type
)

Creates a method handle with arguments of a specified type, but with boolean return value.

public static MethodHandle

Returns:

a method handle testing whether its first argument is of the specified class or subclass.
isInstance
(final Class<?>
the class of the first argument to test for
clazz
,
final int
the position on the argument list to test
pos
,
final MethodType
the method type
type
)

Creates a method handle with arguments of a specified type, but with boolean return value.

public static MethodHandle

Returns:

a guard that tests whether the first argument is not null.
isNotNull
()

Returns a guard that tests whether the first argument is not null.

private static boolean
isNotNull(final Object obj)

public static MethodHandle

Returns:

a guard that tests whether the first argument is null.
isNull
()

Returns a guard that tests whether the first argument is null.

private static boolean
isNull(final Object obj)

public static MethodHandle

Returns:

a method handle testing whether its first argument is of the specified class.
isOfClass
(final Class<?>
the class of the first argument to test for
clazz
,
final MethodType
the method type
type
)

Creates a guard method handle with arguments of a specified type, but with boolean return value.

private static boolean
isOfClass(final Class<?> c, final Object o)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

IS_ARRAYback to summary
private static final MethodHandle IS_ARRAY
IS_IDENTICALback to summary
private static final MethodHandle IS_IDENTICAL
IS_INSTANCEback to summary
private static final MethodHandle IS_INSTANCE
IS_NOT_NULLback to summary
private static final MethodHandle IS_NOT_NULL
IS_NULLback to summary
private static final MethodHandle IS_NULL
IS_OF_CLASSback to summary
private static final MethodHandle IS_OF_CLASS
LOGback to summary
private static final Logger LOG

Constructor Detail

Guardsback to summary
private Guards()

Method Detail

asTypeback to summary
public static MethodHandle asType(final MethodHandle test, final MethodType type)

Takes a method handle intended to be used as a guard, and adapts it to the requested type, but returning a boolean. Applies MethodHandle#asType(MethodType) to convert types and uses MethodHandles#dropArguments(MethodHandle, int, Class...) to match the requested type arity.

Parameters
test:MethodHandle

the test method handle

type:MethodType

the type to adapt the method handle to

Returns:MethodHandle

the adapted method handle

asTypeback to summary
public static MethodHandle asType(final LinkerServices linkerServices, final MethodHandle test, final MethodType type)

Takes a method handle intended to be used as a guard, and adapts it to the requested type, but returning a boolean. Applies LinkerServices#asType(MethodHandle, MethodType) to convert types and uses MethodHandles#dropArguments(MethodHandle, int, Class...) to match the requested type arity.

Parameters
linkerServices:LinkerServices

the linker services to use for type conversions

test:MethodHandle

the test method handle

type:MethodType

the type to adapt the method handle to

Returns:MethodHandle

the adapted method handle

asTypeback to summary
private static MethodHandle asType(final MethodHandle test, final int pos, final MethodType type)
constantBooleanback to summary
private static MethodHandle constantBoolean(final Boolean value, final MethodType type)
constantFalseback to summary
private static MethodHandle constantFalse(final MethodType type)
constantTrueback to summary
private static MethodHandle constantTrue(final MethodType type)
getClassBoundArgumentTestback to summary
private static MethodHandle getClassBoundArgumentTest(final MethodHandle test, final Class<?> clazz, final int pos, final MethodType type)
getClassGuardback to summary
public static MethodHandle getClassGuard(final Class<?> clazz)

Creates a guard method that tests its only argument for being of an exact particular class.

Parameters
clazz:Class<?>

the class to test for.

Returns:MethodHandle

the desired guard method.

getIdentityGuardback to summary
public static MethodHandle getIdentityGuard(final Object obj)

Creates a guard method that tests its only argument for being referentially identical to another object

Parameters
obj:Object

the object used as referential identity test

Returns:MethodHandle

the desired guard method.

getInstanceOfGuardback to summary
public static MethodHandle getInstanceOfGuard(final Class<?> clazz)

Creates a guard method that tests its only argument for being an instance of a particular class.

Parameters
clazz:Class<?>

the class to test for.

Returns:MethodHandle

the desired guard method.

getTestTypeback to summary
private static MethodType getTestType(final MethodHandle test, final MethodType type)
isArrayback to summary
public static MethodHandle isArray(final int pos, final MethodType type)

Creates a method handle that returns true if the argument in the specified position is a Java array.

Parameters
pos:int

the position in the argument lit

type:MethodType

the method type of the handle

Returns:MethodHandle

a method handle that returns true if the argument in the specified position is a Java array; the rest of the arguments are ignored.

Annotations
@SuppressWarnings:boxing
isArrayback to summary
private static boolean isArray(final Object o)
Annotations
@SuppressWarnings:unused
isIdenticalback to summary
private static boolean isIdentical(final Object o1, final Object o2)
Annotations
@SuppressWarnings:unused
isInstanceback to summary
public static MethodHandle isInstance(final Class<?> clazz, final MethodType type)

Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it returns true if the first argument is instance of the specified class or its subclass). The rest of the arguments will be ignored.

Parameters
clazz:Class<?>

the class of the first argument to test for

type:MethodType

the method type

Returns:MethodHandle

a method handle testing whether its first argument is of the specified class or subclass.

isInstanceback to summary
public static MethodHandle isInstance(final Class<?> clazz, final int pos, final MethodType type)

Creates a method handle with arguments of a specified type, but with boolean return value. When invoked, it returns true if the n'th argument is instance of the specified class or its subclass). The rest of the arguments will be ignored.

Parameters
clazz:Class<?>

the class of the first argument to test for

pos:int

the position on the argument list to test

type:MethodType

the method type

Returns:MethodHandle

a method handle testing whether its first argument is of the specified class or subclass.

Annotations
@SuppressWarnings:boxing
isNotNullback to summary
public static MethodHandle isNotNull()

Returns a guard that tests whether the first argument is not null.

Returns:MethodHandle

a guard that tests whether the first argument is not null.

isNotNullback to summary
private static boolean isNotNull(final Object obj)
Annotations
@SuppressWarnings:unused
isNullback to summary
public static MethodHandle isNull()

Returns a guard that tests whether the first argument is null.

Returns:MethodHandle

a guard that tests whether the first argument is null.

isNullback to summary
private static boolean isNull(final Object obj)
Annotations
@SuppressWarnings:unused
isOfClassback to summary
public static MethodHandle isOfClass(final Class<?> clazz, final MethodType type)

Creates a guard method handle with arguments of a specified type, but with boolean return value. When invoked, it returns true if the first argument is of the specified class (exactly of it, not a subclass). The rest of the arguments will be ignored.

Parameters
clazz:Class<?>

the class of the first argument to test for

type:MethodType

the method type

Returns:MethodHandle

a method handle testing whether its first argument is of the specified class.

Annotations
@SuppressWarnings:boxing
isOfClassback to summary
private static boolean isOfClass(final Class<?> c, final Object o)
Annotations
@SuppressWarnings:unused