Package com. rnett. plugin. naming
The com.rnett.plugin.naming
package provides ways to get FqName
s 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
.
Structured
The structured name resolution can be seen in the stdlib names . Objects extending RootPackage
, PackageRef
, and ClassRef
can be nested, each auto-detecting the name from the object named and adding its parent's name as a prefix to its own. This requires the compiler plugin since there is no inner object
or object delegation. However, if both name
and parent
are specified the compiler plugin is unnecessary. Property, function, and constructor references can be created inside of class or package references (with constructor references in packages requiring the class name). Note that just like in IR, extension receivers are not part of an element's FqName
, only dispatch receivers.
Direct
Methods to directly get references are also provided for classes, functions, properties, and constructors. Literal versions are also provided, that take a class, function, property, or class literal, respectively. Using the literal versions requires the compiler plugin, since the FqName
s of the literals will be resolved at compile time. The getFqName(literal)
and literal.fqName()
functions work similarly, and also require the compiler plugin. Note that all of these literal functions only work with literal arguments for the declaration being resolved (thus the name), not variables or parameters.
Types
typeOf()
-like type resolution methods are also provided. They enable getting a TypeRef
from a type literal with typeRef<T>()
, which can be resolved to an IrType
later with an IrPluginContext
or HasContext
. They can also be compared to IrType
s without resolving using eq
. Methods using eq
such as IrType.isType<T>()
and IrType.isClassifierOf<T>()
are also provided. The classifier
of a TypeRef
is a ClassRef
, which provides another method for resolving classes.
Types
Implementation of IConstructorFilter
A constructor reference that gets the constructor of the parent class matching the filter.
Implementation of IFunctionFilter
A function reference that gets the function matching the name and filter.
A delegate to get a FunctionRef with the property's name
A filter for resolving IR constructors.
A filter for resolving IR functions
A filter for resolving IR properties
A namespace that defiens a FqName. Either a class or package for now.
Implementation of IPropertyFilter
A property reference that gets the property matching the name and filter.
A delegate to get a PropertyRef with the property's name
A package with no parent. Does not have to be a single package (i.e. name can have .
s).
Functions
Get a constructor from the given class literal matching filter. Must be called with a literal.
Get a constructor from the class with fqClassName, matching filter.
Get a constructor for the class with className in this PackageRef, matching filter.
Get a constructor for the class with className in this RootPackage, matching filter.
Get a function from a function literal. Can only be called on literals, not variables.
Get the primary constructor from the given class literal matching filter. Must be called with a literal.
Get the primary constructor from the class with fqClassName, matching filter.
Get the primary constructor for the class with className in this PackageRef, matching filter.
Get the primary constructor for the class with className in this RootPackage, matching filter.
Get a property from a property literal. Can only be called on literals, not variables.
Only select functions with a matching (lazily resolved) extension receiver
Add a lambda filter