Compiler Plugin Utils

Utilities for writing Kotlin compiler plugins.

GitHub + Overview

Packages

com.rnett.plugin.ir
Link copied to clipboard

The com.rnett.plugin.ir package contains a number of utilities for working with IR. This includes basic utilities such as CompilerConfiguration.messageCollector, IrClass.addAnonymousInitializer, IrType.raiseTo, and IrClass.typeWith(List<IrTypeArgument>), all of which are available as extension functions.

com.rnett.plugin.naming
Link copied to clipboard

The com.rnett.plugin.naming package provides ways to get FqNames and IR symbols for declarations. It primarily provides a structured method based on nested objects, but also provides direct access. Each of these reference types exposes the FqName of the element, and can be resolved with an IrPluginContext. Function, property, and constructor references all accept filters (essentially (IrSimpleFunction) -> Boolean lambdas or the equivalent, but with some helper methods for common conditions) to disambiguate overloads. Some utility functions are provided in HasContext for working with references in IR, such as irCall(FunctionRef) or ClassRef.resolveTypeWith.

com.rnett.plugin.stdlib
Link copied to clipboard

The com.rnett.plugin.stdlib package provides builders for common standard library functions, using the Naming and IR Utilities features (and providing good examples of how to use them). Collections, toString and hashCode, typeOf, scope functions, numbers, and common exceptions are included. All builder methods are tested. Note that unlike for Naming, extension functions are members of their extension receiver, i.e. Map.getValue. In some cases, builders will resolve their functions based on the types of arguments, such as for number operators or nullable toString and hashCode. The receiver arguments are type checked (in IR) in most cases, the other arguments aren't.