BoundaryInterfaceReflectionUtil

class BoundaryInterfaceReflectionUtil


A set of utility methods used for calling across the support library boundary.

Summary

Public constructors

Public functions

java-static T?
<T> castToSuppLibClass(
    clazz: Class<T!>,
    invocationHandler: InvocationHandler?
)

Returns an implementation of the boundary interface named clazz, by delegating method calls to the InvocationHandler invocationHandler.

java-static Boolean
containsFeature(features: Array<String!>!, soughtFeature: String!)
java-static Boolean
containsFeature(
    features: (Mutable)Collection<String!>!,
    soughtFeature: String!
)

Check whether a set of features {@param features} contains a certain feature {@param * soughtFeature}.

java-static InvocationHandler?
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
createInvocationHandlerFor(delegate: Any?)

Create an InvocationHandler that delegates method calls to delegate, making sure that the Method and parameters being passed exist in the same as delegate.

java-static Array<InvocationHandler!>?
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
createInvocationHandlersForArray(delegates: Array<Any!>?)

Plural version of createInvocationHandlerFor.

java-static Method!
dupeMethod(method: Method!, delegateLoader: ClassLoader!)

Utility method for fetching a method from {@param delegateLoader}, with the same signature (package + class + method name + parameters) as a given method defined in another classloader.

java-static Any?
@RequiresApi(value = Build.VERSION_CODES.KITKAT)
getDelegateFromInvocationHandler(invocationHandler: InvocationHandler?)

Assuming that the given InvocationHandler was created in the current classloader and is an InvocationHandlerWithDelegateGetter, return the object the InvocationHandler delegates its method calls to.

java-static Boolean
instanceOfInOwnClassLoader(obj: Any!, className: String!)

Check if an object is an instance of className, resolving className in the object's own ClassLoader.

Public constructors

BoundaryInterfaceReflectionUtil

BoundaryInterfaceReflectionUtil()

Public functions

castToSuppLibClass

java-static fun <T> castToSuppLibClass(
    clazz: Class<T!>,
    invocationHandler: InvocationHandler?
): T?

Returns an implementation of the boundary interface named clazz, by delegating method calls to the InvocationHandler invocationHandler.

A nullInvocationHandler is treated as representing a null object.

Parameters
clazz: Class<T!>

a Class object representing the desired boundary interface.

invocationHandler: InvocationHandler?

an InvocationHandler compatible with this boundary interface.

containsFeature

java-static fun containsFeature(features: Array<String!>!, soughtFeature: String!): Boolean

containsFeature

java-static fun containsFeature(
    features: (Mutable)Collection<String!>!,
    soughtFeature: String!
): Boolean

Check whether a set of features {@param features} contains a certain feature {@param * soughtFeature}.

createInvocationHandlerFor

@RequiresApi(value = Build.VERSION_CODES.KITKAT)
java-static fun createInvocationHandlerFor(delegate: Any?): InvocationHandler?

Create an InvocationHandler that delegates method calls to delegate, making sure that the Method and parameters being passed exist in the same as delegate.

A null delegate is represented with a nullInvocationHandler.

Parameters
delegate: Any?

the object which the resulting InvocationHandler should delegate method calls to.

Returns
InvocationHandler?

an InvocationHandlerWithDelegateGetter wrapping delegate

createInvocationHandlersForArray

@RequiresApi(value = Build.VERSION_CODES.KITKAT)
java-static fun createInvocationHandlersForArray(delegates: Array<Any!>?): Array<InvocationHandler!>?

Plural version of createInvocationHandlerFor. The resulting array will be the same length as delegates, where the nth InvocationHandler wraps the nth delegate object.

A null array of delegates is represented with a null array of s. Any individual null delegate is represented with a nullInvocationHandler.

Parameters
delegates: Array<Any!>?

an array of objects to which to delegate.

Returns
Array<InvocationHandler!>?

an array of InvocationHandlerWithDelegateGetter instances, each delegating to the corresponding member of delegates.

dupeMethod

java-static fun dupeMethod(method: Method!, delegateLoader: ClassLoader!): Method!

Utility method for fetching a method from {@param delegateLoader}, with the same signature (package + class + method name + parameters) as a given method defined in another classloader.

getDelegateFromInvocationHandler

@RequiresApi(value = Build.VERSION_CODES.KITKAT)
java-static fun getDelegateFromInvocationHandler(invocationHandler: InvocationHandler?): Any?

Assuming that the given InvocationHandler was created in the current classloader and is an InvocationHandlerWithDelegateGetter, return the object the InvocationHandler delegates its method calls to.

A nullInvocationHandler is treated as wrapping a null delegate.

Parameters
invocationHandler: InvocationHandler?

a Nullable InvocationHandlerWithDelegateGetter.

Returns
Any?

the corresponding delegate.

instanceOfInOwnClassLoader

java-static fun instanceOfInOwnClassLoader(obj: Any!, className: String!): Boolean

Check if an object is an instance of className, resolving className in the object's own ClassLoader. This is useful when obj may have been created in a ClassLoader other than the current one (in which case obj instanceof Foo would fail but instanceOfInOwnClassLoader(obj, "Foo") may succeed).