BoundaryInterfaceReflectionUtil

public class BoundaryInterfaceReflectionUtil


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

Summary

Public methods

static @Nullable T
<T> castToSuppLibClass(
    @NonNull Class<@NonNull T> clazz,
    @Nullable InvocationHandler invocationHandler
)

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

static @NonNull boolean
containsFeature(
    @NonNull Collection<@NonNull String> features,
    @NonNull String soughtFeature
)

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

static @NonNull boolean
containsFeature(@NonNull String[] features, @NonNull String soughtFeature)
static @RequiresApi(value = Build.VERSION_CODES.KITKAT) @Nullable 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.

static @RequiresApi(value = Build.VERSION_CODES.KITKAT) @Nullable InvocationHandler[]

Plural version of createInvocationHandlerFor.

static @NonNull Method
dupeMethod(@NonNull Method method, @NonNull ClassLoader delegateLoader)

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.

static @Nullable Object

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.

static @NonNull boolean

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

Public methods

castToSuppLibClass

@Nullable
@NonNull
public static T <T> castToSuppLibClass(
    @NonNull Class<@NonNull T> clazz,
    @Nullable InvocationHandler invocationHandler
)

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
@NonNull Class<@NonNull T> clazz

a Class object representing the desired boundary interface.

@Nullable InvocationHandler invocationHandler

an InvocationHandler compatible with this boundary interface.

containsFeature

@NonNull
public static boolean containsFeature(
    @NonNull Collection<@NonNull String> features,
    @NonNull String soughtFeature
)

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

containsFeature

@NonNull
public static boolean containsFeature(@NonNull String[] features, @NonNull String soughtFeature)

createInvocationHandlerFor

@RequiresApi(value = Build.VERSION_CODES.KITKAT)
@Nullable
@NonNull
public static @RequiresApi(value = Build.VERSION_CODES.KITKAT) InvocationHandler createInvocationHandlerFor(@Nullable Object delegate)

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
@Nullable Object delegate

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

Returns
@RequiresApi(value = Build.VERSION_CODES.KITKAT) InvocationHandler

an InvocationHandlerWithDelegateGetter wrapping delegate

createInvocationHandlersForArray

@RequiresApi(value = Build.VERSION_CODES.KITKAT)
@Nullable
@NonNull
public static @RequiresApi(value = Build.VERSION_CODES.KITKAT) InvocationHandler[] createInvocationHandlersForArray(
    @Nullable Array<@NonNull Object> delegates
)

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
@Nullable Array<@NonNull Object> delegates

an array of objects to which to delegate.

Returns
@RequiresApi(value = Build.VERSION_CODES.KITKAT) InvocationHandler[]

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