# AsmClassVisitorFactory

[View Source](https://cs.android.com/search?q=file:com/android/build/api/instrumentation/AsmClassVisitorFactory.kt+class:com.android.build.api.instrumentation.AsmClassVisitorFactory) Added in 4.2.0


```
interface AsmClassVisitorFactory<ParametersT : InstrumentationParameters> : Serializable
```

<br />

*** ** * ** ***

A factory to create class visitor objects to instrument classes.

The implementation of this interface must be an abstract class where the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#parameters()` and `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#instrumentationContext()` are left unimplemented. The class must have an empty constructor which will be used to construct the factory object.

## Summary

| ### Public functions |
|---|---|
| `https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)( classContext: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/ClassContext, nextClassVisitor: https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html )` Creates a class visitor object that will visit a class with the given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)`. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#isInstrumentable(com.android.build.api.instrumentation.ClassData)(classData: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/ClassData)` Whether the factory wants to instrument the class with the given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#isInstrumentable(com.android.build.api.instrumentation.ClassData)`. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/InstrumentationContext` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#instrumentationContext()` Contains parameters to help instantiate the visitor objects. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html<ParametersT>` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#parameters()` The parameters that will be instantiated, configured using the given config when registering the visitor, and injected on instantiation. |

## Public functions

### createClassVisitor

Added in 4.2.0

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

Creates a class visitor object that will visit a class with the given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)`. The returned class visitor must delegate its calls to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)`. If at this point the factory is not interested in instrumenting the class with given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)`, then return `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)`.

The given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)` contains static information about the classes before starting the instrumentation process. Any changes in interfaces or superclasses for the class with the given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)` or for any other class in its classpath by a previous visitor will not be reflected in the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)` object.

`https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)` 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: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/ClassContext` | contains information about the class that will be instrumented by the returned class visitor. |
| `nextClassVisitor: https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html` | the `https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html` to which the created `https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html` must delegate method calls. |

### isInstrumentable

Added in 4.2.0

```
fun isInstrumentable(classData: ClassData): Boolean
```

Whether the factory wants to instrument the class with the given `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#isInstrumentable(com.android.build.api.instrumentation.ClassData)`.

If returned true, `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)` will be called and the returned class visitor will visit the class.

This method must handle asynchronous calls.

## Public properties

### instrumentationContext

Added in 4.2.0

```
val instrumentationContext: InstrumentationContext
```

Contains parameters to help instantiate the visitor objects.

This field must be left unimplemented.

### parameters

Added in 4.2.0

```
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.