AsmClassVisitorFactory

@Incubating interface AsmClassVisitorFactory<ParametersT : InstrumentationParameters> : Serializable
com.android.build.api.instrumentation.AsmClassVisitorFactory

A factory to create class visitor objects to instrument classes.

The implementation of this interface must be an abstract class where the parameters and instrumentationContext are left unimplemented. The class must have an empty constructor which will be used to construct the factory object.

This API is experimental and subject to breaking change and we strongly suggest you don't publish plugins that depend on it yet.

Summary

Public methods

abstract ClassVisitor
createClassVisitor(classContext: ClassContext, nextClassVisitor: ClassVisitor)

Creates a class visitor object that will visit a class with the given classContext.

abstract Boolean

Whether or not the factory wants to instrument the class with the given classData.

Properties

abstract InstrumentationContext

Contains parameters to help instantiate the visitor objects.

abstract Property<ParametersT>

The parameters that will be instantiated, configured using the given config when registering the visitor, and injected on instantiation.

Public methods

createClassVisitor

abstract fun createClassVisitor(
    classContext: ClassContext,
    nextClassVisitor: ClassVisitor
): ClassVisitor

Creates a class visitor object that will visit a class with the given classContext. The returned class visitor must delegate its calls to nextClassVisitor.

The given classContext contains static information about the classes before starting the instrumentation process. Any changes in interfaces or superclasses for the class with the given classContext or for any other class in its classpath by a previous visitor will not be reflected in the classContext object.

classContext can also be used to get the data for classes that are in the runtime classpath of the class being visited.

This method must handle asynchronous calls.

Parameters
classContext: ClassContext contains information about the class that will be instrumented by the returned class visitor.
nextClassVisitor: ClassVisitor the ClassVisitor to which the created ClassVisitor must delegate method calls.

isInstrumentable

abstract fun isInstrumentable(classData: ClassData): Boolean

Whether or not the factory wants to instrument the class with the given classData.

If returned true, createClassVisitor will be called and the returned class visitor will visit the class.

This method must handle asynchronous calls.

Properties

instrumentationContext

abstract val instrumentationContext: InstrumentationContext

Contains parameters to help instantiate the visitor objects.

This field must be left unimplemented.

parameters

abstract val parameters: Property<ParametersT>

The parameters that will be instantiated, configured using the given config when registering the visitor, and injected on instantiation.

This field must be left unimplemented.