diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt index 05a5d154673..5b86eeb43a8 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt @@ -121,7 +121,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator(FirTree parents += callBuilder } - builder(arraySetCall) { + builder(augmentedArraySetCall) { default("calleeReference", "FirStubReference") useTypes(stubReferenceType) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt index 8a3896c4373..322751d53c5 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt @@ -10,157 +10,157 @@ import org.jetbrains.kotlin.fir.tree.generator.model.Element.Kind.* @Suppress("unused", "MemberVisibilityCanBePrivate") object FirTreeBuilder : AbstractFirTreeBuilder() { - val annotationContainer = element("AnnotationContainer", Other) - val typeRef = sealedElement("TypeRef", TypeRef, annotationContainer) - val reference = element("Reference", Reference) - val label = element("Label", Other) + val annotationContainer by element(Other) + val typeRef by sealedElement(TypeRef, annotationContainer) + val reference by element(Reference) + val label by element(Other) - val resolvable = sealedElement("Resolvable", Expression) + val resolvable by sealedElement(Expression) - val targetElement = element("TargetElement", Other) + val targetElement by element(Other) - val declarationStatus = element("DeclarationStatus", Declaration) - val resolvedDeclarationStatus = element("ResolvedDeclarationStatus", Declaration, declarationStatus) + val declarationStatus by element(Declaration) + val resolvedDeclarationStatus by element(Declaration, declarationStatus) - val controlFlowGraphOwner = element("ControlFlowGraphOwner", Declaration) + val controlFlowGraphOwner by element(Declaration) - val statement = element("Statement", Expression, annotationContainer) - val expression = element("Expression", Expression, statement) - val declaration = sealedElement("Declaration", Declaration) - val annotatedDeclaration = sealedElement("AnnotatedDeclaration", Declaration, declaration, annotationContainer) - val anonymousInitializer = element("AnonymousInitializer", Declaration, declaration, controlFlowGraphOwner) - val typedDeclaration = sealedElement("TypedDeclaration", Declaration, annotatedDeclaration) - val typeParameterRefsOwner = sealedElement("TypeParameterRefsOwner", Declaration) - val typeParametersOwner = sealedElement("TypeParametersOwner", Declaration, typeParameterRefsOwner) - val memberDeclaration = sealedElement("MemberDeclaration", Declaration, typeParameterRefsOwner) - val callableDeclaration = sealedElement("CallableDeclaration", Declaration, typedDeclaration, memberDeclaration) - val typeParameterRef = element("TypeParameterRef", Declaration) - val typeParameter = element("TypeParameter", Declaration, typeParameterRef, annotatedDeclaration) + val statement by element(Expression, annotationContainer) + val expression by element(Expression, statement) + val declaration by sealedElement(Declaration) + val annotatedDeclaration by sealedElement(Declaration, declaration, annotationContainer) + val anonymousInitializer by element(Declaration, declaration, controlFlowGraphOwner) + val typedDeclaration by sealedElement(Declaration, annotatedDeclaration) + val typeParameterRefsOwner by sealedElement(Declaration) + val typeParametersOwner by sealedElement(Declaration, typeParameterRefsOwner) + val memberDeclaration by sealedElement(Declaration, typeParameterRefsOwner) + val callableDeclaration by sealedElement(Declaration, typedDeclaration, memberDeclaration) + val typeParameterRef by element(Declaration) + val typeParameter by element(Declaration, typeParameterRef, annotatedDeclaration) - val variable = sealedElement("Variable", Declaration, callableDeclaration, statement) - val valueParameter = element("ValueParameter", Declaration, variable, controlFlowGraphOwner) - val property = element("Property", Declaration, variable, typeParametersOwner, controlFlowGraphOwner) - val field = element("Field", Declaration, variable) - val enumEntry = element("EnumEntry", Declaration, variable) + val variable by sealedElement(Declaration, callableDeclaration, statement) + val valueParameter by element(Declaration, variable, controlFlowGraphOwner) + val property by element(Declaration, variable, typeParametersOwner, controlFlowGraphOwner) + val field by element(Declaration, variable) + val enumEntry by element(Declaration, variable) - val classLikeDeclaration = sealedElement("ClassLikeDeclaration", Declaration, annotatedDeclaration, statement) - val klass = sealedElement("Class", Declaration, classLikeDeclaration, statement, typeParameterRefsOwner) - val regularClass = element("RegularClass", Declaration, klass, memberDeclaration, controlFlowGraphOwner) - val typeAlias = element("TypeAlias", Declaration, classLikeDeclaration, memberDeclaration, typeParametersOwner) + val classLikeDeclaration by sealedElement(Declaration, annotatedDeclaration, statement) + val klass by sealedElement("Class", Declaration, classLikeDeclaration, statement, typeParameterRefsOwner) + val regularClass by element(Declaration, klass, memberDeclaration, controlFlowGraphOwner) + val typeAlias by element(Declaration, classLikeDeclaration, memberDeclaration, typeParametersOwner) - val function = sealedElement("Function", Declaration, callableDeclaration, targetElement, controlFlowGraphOwner, statement) + val function by sealedElement(Declaration, callableDeclaration, targetElement, controlFlowGraphOwner, statement) - val contractDescriptionOwner = sealedElement("ContractDescriptionOwner", Declaration) - val simpleFunction = element("SimpleFunction", Declaration, function, contractDescriptionOwner, typeParametersOwner) - val propertyAccessor = element("PropertyAccessor", Declaration, function, contractDescriptionOwner, typeParametersOwner) - val backingField = element("BackingField", Declaration, variable, typeParametersOwner, statement) - val constructor = element("Constructor", Declaration, function, typeParameterRefsOwner) - val file = element("File", Declaration, annotatedDeclaration) - val packageDirective = element("PackageDirective", Other) + val contractDescriptionOwner by sealedElement(Declaration) + val simpleFunction by element(Declaration, function, contractDescriptionOwner, typeParametersOwner) + val propertyAccessor by element(Declaration, function, contractDescriptionOwner, typeParametersOwner) + val backingField by element(Declaration, variable, typeParametersOwner, statement) + val constructor by element(Declaration, function, typeParameterRefsOwner) + val file by element(Declaration, annotatedDeclaration) + val packageDirective by element(Other) - val anonymousFunction = element("AnonymousFunction", Declaration, function, typeParametersOwner) - val anonymousFunctionExpression = element("AnonymousFunctionExpression", Expression, expression) + val anonymousFunction by element(Declaration, function, typeParametersOwner) + val anonymousFunctionExpression by element(Expression, expression) - val anonymousObject = element("AnonymousObject", Declaration, klass, controlFlowGraphOwner) - val anonymousObjectExpression = element("AnonymousObjectExpression", Expression, expression) + val anonymousObject by element(Declaration, klass, controlFlowGraphOwner) + val anonymousObjectExpression by element(Expression, expression) - val diagnosticHolder = element("DiagnosticHolder", Diagnostics) + val diagnosticHolder by element(Diagnostics) - val import = element("Import", Declaration) - val resolvedImport = element("ResolvedImport", Declaration, import) - val errorImport = element("ErrorImport", Declaration, import, diagnosticHolder) + val import by element(Declaration) + val resolvedImport by element(Declaration, import) + val errorImport by element(Declaration, import, diagnosticHolder) - val loop = sealedElement("Loop", Expression, statement, targetElement) - val errorLoop = element("ErrorLoop", Expression, loop, diagnosticHolder) - val doWhileLoop = element("DoWhileLoop", Expression, loop) - val whileLoop = element("WhileLoop", Expression, loop) + val loop by sealedElement(Expression, statement, targetElement) + val errorLoop by element(Expression, loop, diagnosticHolder) + val doWhileLoop by element(Expression, loop) + val whileLoop by element(Expression, loop) - val block = element("Block", Expression, expression) - val binaryLogicExpression = element("BinaryLogicExpression", Expression, expression) - val jump = sealedElement("Jump", Expression, expression) - val loopJump = element("LoopJump", Expression, jump) - val breakExpression = element("BreakExpression", Expression, loopJump) - val continueExpression = element("ContinueExpression", Expression, loopJump) - val catchClause = element("Catch", Expression) - val tryExpression = element("TryExpression", Expression, expression, resolvable) - val constExpression = element("ConstExpression", Expression, expression) - val typeProjection = element("TypeProjection", TypeRef) - val starProjection = element("StarProjection", TypeRef, typeProjection) - val typeProjectionWithVariance = element("TypeProjectionWithVariance", TypeRef, typeProjection) - val argumentList = element("ArgumentList", Expression) - val call = sealedElement("Call", Expression, statement) // TODO: may smth like `CallWithArguments` or `ElementWithArguments`? - val annotation = element("Annotation", Expression, expression, call, resolvable) - val comparisonExpression = element("ComparisonExpression", Expression, expression) - val typeOperatorCall = element("TypeOperatorCall", Expression, expression, call) - val assignmentOperatorStatement = element("AssignmentOperatorStatement", Expression, statement) - val equalityOperatorCall = element("EqualityOperatorCall", Expression, expression, call) - val whenExpression = element("WhenExpression", Expression, expression, resolvable) - val whenBranch = element("WhenBranch", Expression) - val qualifiedAccess = element("QualifiedAccess", Expression, resolvable, statement) - val checkNotNullCall = element("CheckNotNullCall", Expression, expression, call, resolvable) - val elvisExpression = element("ElvisExpression", Expression, expression, resolvable) + val block by element(Expression, expression) + val binaryLogicExpression by element(Expression, expression) + val jump by sealedElement(Expression, expression) + val loopJump by element(Expression, jump) + val breakExpression by element(Expression, loopJump) + val continueExpression by element(Expression, loopJump) + val catchClause by element("Catch", Expression) + val tryExpression by element(Expression, expression, resolvable) + val constExpression by element(Expression, expression) + val typeProjection by element(TypeRef) + val starProjection by element(TypeRef, typeProjection) + val typeProjectionWithVariance by element(TypeRef, typeProjection) + val argumentList by element(Expression) + val call by sealedElement(Expression, statement) // TODO: may smth like `CallWithArguments` or `ElementWithArguments`? + val annotation by element(Expression, expression, call, resolvable) + val comparisonExpression by element(Expression, expression) + val typeOperatorCall by element(Expression, expression, call) + val assignmentOperatorStatement by element(Expression, statement) + val equalityOperatorCall by element(Expression, expression, call) + val whenExpression by element(Expression, expression, resolvable) + val whenBranch by element(Expression) + val qualifiedAccess by element(Expression, resolvable, statement) + val checkNotNullCall by element(Expression, expression, call, resolvable) + val elvisExpression by element(Expression, expression, resolvable) - val arrayOfCall = element("ArrayOfCall", Expression, expression, call) - val arraySetCall = element("AugmentedArraySetCall", Expression, statement) - val classReferenceExpression = element("ClassReferenceExpression", Expression, expression) - val errorExpression = element("ErrorExpression", Expression, expression, diagnosticHolder) - val errorFunction = element("ErrorFunction", Declaration, function, diagnosticHolder) - val errorProperty = element("ErrorProperty", Declaration, variable, diagnosticHolder) - val qualifiedAccessExpression = element("QualifiedAccessExpression", Expression, expression, qualifiedAccess) - val propertyAccessExpression = element("PropertyAccessExpression", Expression, qualifiedAccessExpression) - val functionCall = element("FunctionCall", Expression, qualifiedAccessExpression, call) - val implicitInvokeCall = element("ImplicitInvokeCall", Expression, functionCall) - val delegatedConstructorCall = element("DelegatedConstructorCall", Expression, resolvable, call) - val componentCall = element("ComponentCall", Expression, functionCall) - val callableReferenceAccess = element("CallableReferenceAccess", Expression, qualifiedAccessExpression) - val thisReceiverExpression = element("ThisReceiverExpression", Expression, qualifiedAccessExpression) - val expressionWithSmartcast = element("ExpressionWithSmartcast", Expression, qualifiedAccessExpression) - val expressionWithSmartcastToNull = element("ExpressionWithSmartcastToNull", Expression, expressionWithSmartcast) - val safeCallExpression = element("SafeCallExpression", Expression, expression) - val checkedSafeCallSubject = element("CheckedSafeCallSubject", Expression, expression) - val getClassCall = element("GetClassCall", Expression, expression, call) - val wrappedExpression = element("WrappedExpression", Expression, expression) - val wrappedArgumentExpression = element("WrappedArgumentExpression", Expression, wrappedExpression) - val lambdaArgumentExpression = element("LambdaArgumentExpression", Expression, wrappedArgumentExpression) - val spreadArgumentExpression = element("SpreadArgumentExpression", Expression, wrappedArgumentExpression) - val namedArgumentExpression = element("NamedArgumentExpression", Expression, wrappedArgumentExpression) - val varargArgumentsExpression = element("VarargArgumentsExpression", Expression, expression) + val arrayOfCall by element(Expression, expression, call) + val augmentedArraySetCall by element(Expression, statement) + val classReferenceExpression by element(Expression, expression) + val errorExpression by element(Expression, expression, diagnosticHolder) + val errorFunction by element(Declaration, function, diagnosticHolder) + val errorProperty by element(Declaration, variable, diagnosticHolder) + val qualifiedAccessExpression by element(Expression, expression, qualifiedAccess) + val propertyAccessExpression by element(Expression, qualifiedAccessExpression) + val functionCall by element(Expression, qualifiedAccessExpression, call) + val implicitInvokeCall by element(Expression, functionCall) + val delegatedConstructorCall by element(Expression, resolvable, call) + val componentCall by element(Expression, functionCall) + val callableReferenceAccess by element(Expression, qualifiedAccessExpression) + val thisReceiverExpression by element(Expression, qualifiedAccessExpression) + val expressionWithSmartcast by element(Expression, qualifiedAccessExpression) + val expressionWithSmartcastToNull by element(Expression, expressionWithSmartcast) + val safeCallExpression by element(Expression, expression) + val checkedSafeCallSubject by element(Expression, expression) + val getClassCall by element(Expression, expression, call) + val wrappedExpression by element(Expression, expression) + val wrappedArgumentExpression by element(Expression, wrappedExpression) + val lambdaArgumentExpression by element(Expression, wrappedArgumentExpression) + val spreadArgumentExpression by element(Expression, wrappedArgumentExpression) + val namedArgumentExpression by element(Expression, wrappedArgumentExpression) + val varargArgumentsExpression by element(Expression, expression) - val resolvedQualifier = element("ResolvedQualifier", Expression, expression) - val errorResolvedQualifier = element("ErrorResolvedQualifier", Expression, resolvedQualifier, diagnosticHolder) - val resolvedReifiedParameterReference = element("ResolvedReifiedParameterReference", Expression, expression) - val returnExpression = element("ReturnExpression", Expression, jump) - val stringConcatenationCall = element("StringConcatenationCall", Expression, call, expression) - val throwExpression = element("ThrowExpression", Expression, expression) - val variableAssignment = element("VariableAssignment", Expression, qualifiedAccess) - val whenSubjectExpression = element("WhenSubjectExpression", Expression, expression) + val resolvedQualifier by element(Expression, expression) + val errorResolvedQualifier by element(Expression, resolvedQualifier, diagnosticHolder) + val resolvedReifiedParameterReference by element(Expression, expression) + val returnExpression by element(Expression, jump) + val stringConcatenationCall by element(Expression, call, expression) + val throwExpression by element(Expression, expression) + val variableAssignment by element(Expression, qualifiedAccess) + val whenSubjectExpression by element(Expression, expression) - val wrappedDelegateExpression = element("WrappedDelegateExpression", Expression, wrappedExpression) + val wrappedDelegateExpression by element(Expression, wrappedExpression) - val namedReference = element("NamedReference", Reference, reference) - val errorNamedReference = element("ErrorNamedReference", Reference, namedReference, diagnosticHolder) - val superReference = element("SuperReference", Reference, reference) - val thisReference = element("ThisReference", Reference, reference) - val controlFlowGraphReference = element("ControlFlowGraphReference", Reference, reference) + val namedReference by element(Reference, reference) + val errorNamedReference by element(Reference, namedReference, diagnosticHolder) + val superReference by element(Reference, reference) + val thisReference by element(Reference, reference) + val controlFlowGraphReference by element(Reference, reference) - val resolvedNamedReference = element("ResolvedNamedReference", Reference, namedReference) - val delegateFieldReference = element("DelegateFieldReference", Reference, resolvedNamedReference) - val backingFieldReference = element("BackingFieldReference", Reference, resolvedNamedReference) + val resolvedNamedReference by element(Reference, namedReference) + val delegateFieldReference by element(Reference, resolvedNamedReference) + val backingFieldReference by element(Reference, resolvedNamedReference) - val resolvedCallableReference = element("ResolvedCallableReference", Reference, resolvedNamedReference) + val resolvedCallableReference by element(Reference, resolvedNamedReference) - val resolvedTypeRef = element("ResolvedTypeRef", TypeRef, typeRef) - val errorTypeRef = element("ErrorTypeRef", TypeRef, resolvedTypeRef, diagnosticHolder) - val typeRefWithNullability = element("TypeRefWithNullability", TypeRef, typeRef) - val userTypeRef = element("UserTypeRef", TypeRef, typeRefWithNullability) - val dynamicTypeRef = element("DynamicTypeRef", TypeRef, typeRefWithNullability) - val functionTypeRef = element("FunctionTypeRef", TypeRef, typeRefWithNullability) - val implicitTypeRef = element("ImplicitTypeRef", TypeRef, typeRef) + val resolvedTypeRef by element(TypeRef, typeRef) + val errorTypeRef by element(TypeRef, resolvedTypeRef, diagnosticHolder) + val typeRefWithNullability by element(TypeRef, typeRef) + val userTypeRef by element(TypeRef, typeRefWithNullability) + val dynamicTypeRef by element(TypeRef, typeRefWithNullability) + val functionTypeRef by element(TypeRef, typeRefWithNullability) + val implicitTypeRef by element(TypeRef, typeRef) - val effectDeclaration = element("EffectDeclaration", Contracts) + val effectDeclaration by element(Contracts) - val contractDescription = element("ContractDescription", Contracts) - val legacyRawContractDescription = element("LegacyRawContractDescription", Contracts, contractDescription) - val rawContractDescription = element("RawContractDescription", Contracts, contractDescription) - val resolvedContractDescription = element("ResolvedContractDescription", Contracts, contractDescription) + val contractDescription by element(Contracts) + val legacyRawContractDescription by element(Contracts, contractDescription) + val rawContractDescription by element(Contracts, contractDescription) + val resolvedContractDescription by element(Contracts, contractDescription) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 936bb6d176e..4306759ea69 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -450,7 +450,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +field("resolveStatus", annotationResolveStatusType, withReplace = true) } - arraySetCall.configure { + augmentedArraySetCall.configure { +field("assignCall", functionCall) +field("setGetBlock", block) +field("operation", operationType) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractBuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractBuilderConfigurator.kt index d2e1d397697..b85ee602264 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractBuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractBuilderConfigurator.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.tree.generator.context import org.jetbrains.kotlin.fir.tree.generator.model.* import org.jetbrains.kotlin.fir.tree.generator.noReceiverExpressionType -import org.jetbrains.kotlin.fir.tree.generator.printer.call +import org.jetbrains.kotlin.fir.tree.generator.util.DummyDelegate import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty @@ -138,12 +138,6 @@ abstract class AbstractBuilderConfigurator(val firTr } return DummyDelegate(builder) } - - private inner class DummyDelegate(val builder: IntermediateBuilder) : ReadOnlyProperty { - override fun getValue(thisRef: Nothing?, property: KProperty<*>): IntermediateBuilder { - return builder - } - } } inner class LeafBuilderConfigurationContext(override val builder: LeafBuilder) : BuilderConfigurationContext() { @@ -199,4 +193,4 @@ abstract class AbstractBuilderConfigurator(val firTr val implementation = element.extractImplementation(type) implementation.builder = null } -} \ No newline at end of file +} diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractFirTreeBuilder.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractFirTreeBuilder.kt index 85dc1bde1c5..a58ecddf941 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractFirTreeBuilder.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/context/AbstractFirTreeBuilder.kt @@ -9,7 +9,10 @@ import org.jetbrains.kotlin.fir.tree.generator.model.Element import org.jetbrains.kotlin.fir.tree.generator.model.IntermediateBuilder import org.jetbrains.kotlin.fir.tree.generator.model.Type import org.jetbrains.kotlin.fir.tree.generator.printer.BASE_PACKAGE +import org.jetbrains.kotlin.fir.tree.generator.util.DummyDelegate +import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KClass +import kotlin.reflect.KProperty abstract class AbstractFirTreeBuilder { companion object { @@ -26,8 +29,24 @@ abstract class AbstractFirTreeBuilder { val elements = mutableListOf(baseFirElement) val intermediateBuilders = mutableListOf() - protected fun element(name: String, kind: Element.Kind, vararg dependencies: Element, init: Element.() -> Unit = {}): Element = - Element(name, kind).apply(init).also { + protected fun element(kind: Element.Kind, vararg dependencies: Element): ElementDelegateProvider { + return ElementDelegateProvider(kind, dependencies, isSealed = false, predefinedName = null) + } + + protected fun sealedElement(kind: Element.Kind, vararg dependencies: Element): ElementDelegateProvider { + return ElementDelegateProvider(kind, dependencies, isSealed = true, predefinedName = null) + } + + protected fun element(name: String, kind: Element.Kind, vararg dependencies: Element): ElementDelegateProvider { + return ElementDelegateProvider(kind, dependencies, isSealed = false, predefinedName = name) + } + + protected fun sealedElement(name: String, kind: Element.Kind, vararg dependencies: Element): ElementDelegateProvider { + return ElementDelegateProvider(kind, dependencies, isSealed = true, predefinedName = name) + } + + private fun createElement(name: String, kind: Element.Kind, vararg dependencies: Element): Element = + Element(name, kind).also { if (dependencies.isEmpty()) { it.parents.add(baseFirElement) } @@ -35,13 +54,12 @@ abstract class AbstractFirTreeBuilder { elements += it } - protected fun sealedElement( + private fun createSealedElement( name: String, kind: Element.Kind, vararg dependencies: Element, - init: Element.() -> Unit = {} ): Element { - return element(name, kind, *dependencies, init = init).apply { + return createElement(name, kind, *dependencies).apply { isSealed = true } } @@ -53,6 +71,26 @@ abstract class AbstractFirTreeBuilder { configurations[element]?.invoke() } } + + inner class ElementDelegateProvider( + private val kind: Element.Kind, + private val dependencies: Array, + private val isSealed: Boolean, + private val predefinedName: String? + ) { + operator fun provideDelegate( + thisRef: AbstractFirTreeBuilder, + prop: KProperty<*> + ): ReadOnlyProperty { + val name = predefinedName ?: prop.name.replaceFirstChar { it.uppercaseChar() } + val element = if (isSealed) { + createSealedElement(name, kind, *dependencies) + } else { + createElement(name, kind, *dependencies) + } + return DummyDelegate(element) + } + } } fun generatedType(type: String): Type = generatedType("", type) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/util/DummyDelegate.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/util/DummyDelegate.kt new file mode 100644 index 00000000000..55770075404 --- /dev/null +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/util/DummyDelegate.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.tree.generator.util + +import kotlin.properties.ReadOnlyProperty +import kotlin.reflect.KProperty + +class DummyDelegate(val value: T) : ReadOnlyProperty { + override fun getValue(thisRef: Any?, property: KProperty<*>): T { + return value + } +}