compiler/fir/tree/tree-generator/Readme.md
FirTree.kt.val foo by element(elementKind: Kind, name: String?).
FirFoo. If you specify name = "Bar" it will be called FirBar instead.kind describes target package of an element. Available kinds:
Expression (package fir.expression)Declaration (package fir.declaration)Reference (package fir.references)TypeRef (package fir.types)Other (package fir)field(..., nullable: Boolean = false, withReplace: Boolean).
nullable is true, then the type of the field will be nullable.withReplace is true, then in the element the replace... method will be generated for that field.withTransform is true, then in the element the transform... method will be generated for that field.... you can pass an optional name (with String type), and TypeRef or Element objectname is passed, then it will be inferred based on the type.TypeRef or Element have type arguments, then you can use TypeRef.withArgs(vararg types: TypeRef).fieldList([name: String], element: TypeRef) (if no name is specified, it will be inferred based on the type of
element).+ operator:
+fieldList("catches", catchClause).symbol(symbolTypeName: String) to create a field named symbol with a lying in
the org.jetbrains.kotlin.fir.symbols package.FieldSets.kt.parent(foo)
FirElement.transform... methods, and you want to add methods for transforming all other children, you should call
needTransformOtherChildren().+param(typeParameterName: String, [upperBound: TypeRef]).parent(foo.withArgs(...)).ImplementationConfigurator.ktimpl(element: Element, [name: String]) {...} describes the configuration of the element with name name (if there is no name,
then it would be ElementTypeImpl).
Lambda with implementation configuration is optional.
Note that this function returns an object of type Implementation.noImpl(element: Element) used when you don't want to generate any implementation for element/FinalClass (default), OpenClass, AbstractClass, Interface using the syntax
kind = Interfaceparents += parent.parent can be only implementation with kind = Interface.default(fieldName: String) { ... }
value = _defaultValue_.withGetter = true/false (false by default).delegate = delegateFieldName (used for generating such fields: val typeRef: FirTypeRef get() = expression.typeRef).delegateName = fieldNameInDelegateType (val expressionTypeRef: FirTypeRef get() = expression.typeRef).needAcceptAndTransform = true/false (true by default) -- specify it if you don't want to accept field in
acceptChildren.customSetter = setterExpresison.default(fieldName, value)defaultNull(fieldName, [withGetter: Boolean])lateinit, you describe them in the lateinit(vararg fields: String) call.additionalImports(vararg types: Importable)Types.ktfun <reified T : Any> type() uses FQN of the corresponding T class.fun type(packageName: String, typeName: String, exactPackage: Boolean = false, kind: TypeKind = TypeKind.Interface).
exactPackage = false, its return type with default package prefix: org.jetbrains.kotlin.packageName.typeName.packageName.typeName .generatedType([packageName: String], typeName: String) — same as type(packageName, typeName) but with
the org.jetbrains.kotlin.fir prefix .Element or Implementation should be always an interface you should:
kind = ImplementationKind.Interface when configuring a Element in FirTree.ktkind = Interface when configuring an Implementation in ImplementationConfigurator.kt