Skip to content

Stability: ALPHA Maven Central Version Maven snapshots GitHub Repo GitHub License

Inspekt

100% multiplatform, 100% compile time reflection for Kotlin. Includes:

  • Inspecting classes, functions, and properties
  • Top-level declaration support
  • Annotation instances
  • Function invocation, including suspend functions
  • is checking and casting
  • JVM-like proxies
  • Reflecting over dependencies (whether they use Inspekt or not)
  • Seamless reflection over Java classes
  • GraalVM compatible out of the box (I think, it's not tested yet)

Getting started

To use Inspekt, just apply the Gradle plugin:

plugins {
    id("dev.rnett.inspekt") version "<version>" // see the Maven Central badge above
}

and call inspekt from your code:

val fooClass = inspekt(Foo::class)

foo.function("bar").invoke {
    dispatchReceiver = Foo()
}

Other Compiler Plugins

Compatibility with other compiler plugins depends on the plugin and is not at all guaranteed or even expected to work. Use at your own risk. It will most likely work for declarations generated by other plugins if you use the compiler plugin ordering parameter to ensure Inspekt (which has id dev.rnett.inspekt.compiler-plugin) runs after the other plugin(s).

It is 0% compatible with @Composable functions.

Stability

This library has been initially released as alpha because it depends on a number of compiler internals. However, I plan no significant changes and will strive to avoid any backwards incompatible changes.

Examples

Some basic examples are located in the examples directory of the GitHub repo.