[FIR/IR generator] Reduce duplication when printing curly-braced blocks
This commit is contained in:
committed by
Space Team
parent
18ed85c26e
commit
fab63e38aa
+3
-6
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.tree.generator.model.*
|
|||||||
import org.jetbrains.kotlin.generators.tree.ImportCollector
|
import org.jetbrains.kotlin.generators.tree.ImportCollector
|
||||||
import org.jetbrains.kotlin.generators.tree.StandardTypes
|
import org.jetbrains.kotlin.generators.tree.StandardTypes
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.GeneratedFile
|
import org.jetbrains.kotlin.generators.tree.printer.GeneratedFile
|
||||||
|
import org.jetbrains.kotlin.generators.tree.printer.printBlock
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.printGeneratedType
|
import org.jetbrains.kotlin.generators.tree.printer.printGeneratedType
|
||||||
import org.jetbrains.kotlin.generators.tree.render
|
import org.jetbrains.kotlin.generators.tree.render
|
||||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||||
@@ -50,8 +51,7 @@ private fun SmartPrinter.printBuilder(builder: Builder) {
|
|||||||
print(builder.parents.joinToString(separator = ", ", prefix = " : ") { it.render() })
|
print(builder.parents.joinToString(separator = ", ", prefix = " : ") { it.render() })
|
||||||
}
|
}
|
||||||
var hasRequiredFields = false
|
var hasRequiredFields = false
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
var needNewLine = false
|
var needNewLine = false
|
||||||
for (field in builder.allFields) {
|
for (field in builder.allFields) {
|
||||||
val (newLine, requiredFields) = printFieldInBuilder(field, builder, fieldIsUseless = false)
|
val (newLine, requiredFields) = printFieldInBuilder(field, builder, fieldIsUseless = false)
|
||||||
@@ -74,8 +74,7 @@ private fun SmartPrinter.printBuilder(builder: Builder) {
|
|||||||
}
|
}
|
||||||
print("fun build(): $buildType")
|
print("fun build(): $buildType")
|
||||||
if (builder is LeafBuilder) {
|
if (builder is LeafBuilder) {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
println("return ${builder.implementation.render()}(")
|
println("return ${builder.implementation.render()}(")
|
||||||
withIndent {
|
withIndent {
|
||||||
for (field in builder.allFields) {
|
for (field in builder.allFields) {
|
||||||
@@ -91,7 +90,6 @@ private fun SmartPrinter.printBuilder(builder: Builder) {
|
|||||||
}
|
}
|
||||||
println(")")
|
println(")")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
if (hasBackingFields) {
|
if (hasBackingFields) {
|
||||||
println()
|
println()
|
||||||
}
|
}
|
||||||
@@ -116,7 +114,6 @@ private fun SmartPrinter.printBuilder(builder: Builder) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
if (builder is LeafBuilder) {
|
if (builder is LeafBuilder) {
|
||||||
println()
|
println()
|
||||||
printDslBuildFunction(builder, hasRequiredFields)
|
printDslBuildFunction(builder, hasRequiredFields)
|
||||||
|
|||||||
+9
-18
@@ -109,8 +109,7 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
print("${pureAbstractElementType.render()}(), ")
|
print("${pureAbstractElementType.render()}(), ")
|
||||||
}
|
}
|
||||||
print(allParents.joinToString { "${it.render()}${it.kind.braces()}" })
|
print(allParents.joinToString { "${it.render()}${it.kind.braces()}" })
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
if (isInterface || isAbstract) {
|
if (isInterface || isAbstract) {
|
||||||
allFields.forEach {
|
allFields.forEach {
|
||||||
fieldPrinter.printField(it, override = true, modality = Modality.ABSTRACT.takeIf { isAbstract })
|
fieldPrinter.printField(it, override = true, modality = Modality.ABSTRACT.takeIf { isAbstract })
|
||||||
@@ -217,15 +216,14 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
|
|
||||||
if (hasTransformChildrenMethod) {
|
if (hasTransformChildrenMethod) {
|
||||||
printTransformChildrenMethod(
|
printTransformChildrenMethod(
|
||||||
this,
|
implementation,
|
||||||
firTransformerType,
|
firTransformerType,
|
||||||
this,
|
implementation,
|
||||||
modality = Modality.ABSTRACT.takeIf { isAbstract },
|
modality = Modality.ABSTRACT.takeIf { isAbstract },
|
||||||
override = true,
|
override = true,
|
||||||
)
|
)
|
||||||
if (!isInterface && !isAbstract) {
|
if (!isInterface && !isAbstract) {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
for (field in transformableChildren) {
|
for (field in transformableChildren) {
|
||||||
when {
|
when {
|
||||||
field.name == "explicitReceiver" -> {
|
field.name == "explicitReceiver" -> {
|
||||||
@@ -275,24 +273,21 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
}
|
}
|
||||||
println("return this")
|
println("return this")
|
||||||
}
|
}
|
||||||
print("}")
|
|
||||||
}
|
}
|
||||||
println()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (field in allFields) {
|
for (field in allFields) {
|
||||||
if (!field.needsSeparateTransform) continue
|
if (!field.needsSeparateTransform) continue
|
||||||
println()
|
println()
|
||||||
transformFunctionDeclaration(field, this, override = true, kind!!)
|
transformFunctionDeclaration(field, implementation, override = true, kind!!)
|
||||||
if (isInterface || isAbstract) {
|
if (isInterface || isAbstract) {
|
||||||
println()
|
println()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
if (field.isMutable && field.isFirType) {
|
if (field.isMutable && field.isFirType) {
|
||||||
// TODO: replace with smth normal
|
// TODO: replace with smth normal
|
||||||
if (this.typeName == "FirWhenExpressionImpl" && field.name == "subject") {
|
if (typeName == "FirWhenExpressionImpl" && field.name == "subject") {
|
||||||
println(
|
println(
|
||||||
"""
|
"""
|
||||||
|if (subjectVariable != null) {
|
|if (subjectVariable != null) {
|
||||||
@@ -309,17 +304,15 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
}
|
}
|
||||||
println("return this")
|
println("return this")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.needTransformOtherChildren) {
|
if (element.needTransformOtherChildren) {
|
||||||
println()
|
println()
|
||||||
transformOtherChildrenFunctionDeclaration(this, override = true, kind!!)
|
transformOtherChildrenFunctionDeclaration(implementation, override = true, kind!!)
|
||||||
if (isInterface || isAbstract) {
|
if (isInterface || isAbstract) {
|
||||||
println()
|
println()
|
||||||
} else {
|
} else {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
for (field in allFields) {
|
for (field in allFields) {
|
||||||
if (!field.isMutable || !field.isFirType || field.name == "subjectVariable") continue
|
if (!field.isMutable || !field.isFirType || field.name == "subjectVariable") continue
|
||||||
if (!field.needsSeparateTransform) {
|
if (!field.needsSeparateTransform) {
|
||||||
@@ -331,7 +324,6 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
}
|
}
|
||||||
println("return this")
|
println("return this")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +388,6 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-14
@@ -12,13 +12,8 @@ import org.jetbrains.kotlin.fir.tree.generator.firVisitorType
|
|||||||
import org.jetbrains.kotlin.fir.tree.generator.model.Element
|
import org.jetbrains.kotlin.fir.tree.generator.model.Element
|
||||||
import org.jetbrains.kotlin.fir.tree.generator.model.Field
|
import org.jetbrains.kotlin.fir.tree.generator.model.Field
|
||||||
import org.jetbrains.kotlin.generators.tree.*
|
import org.jetbrains.kotlin.generators.tree.*
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.FunctionParameter
|
import org.jetbrains.kotlin.generators.tree.printer.*
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.GeneratedFile
|
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.printFunctionDeclaration
|
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.printGeneratedType
|
|
||||||
import org.jetbrains.kotlin.types.Variance
|
|
||||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||||
import org.jetbrains.kotlin.utils.withIndent
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
private class TransformerPrinter(
|
private class TransformerPrinter(
|
||||||
@@ -61,7 +56,7 @@ private class TransformerPrinter(
|
|||||||
)
|
)
|
||||||
println()
|
println()
|
||||||
} else {
|
} else {
|
||||||
printFunctionDeclaration(
|
printFunctionWithBlockBody(
|
||||||
name = "transform" + element.name,
|
name = "transform" + element.name,
|
||||||
parameters = listOf(
|
parameters = listOf(
|
||||||
FunctionParameter(elementParameterName, element),
|
FunctionParameter(elementParameterName, element),
|
||||||
@@ -70,12 +65,9 @@ private class TransformerPrinter(
|
|||||||
returnType = visitMethodReturnType(element),
|
returnType = visitMethodReturnType(element),
|
||||||
typeParameters = element.params,
|
typeParameters = element.params,
|
||||||
modality = Modality.OPEN,
|
modality = Modality.OPEN,
|
||||||
)
|
) {
|
||||||
println(" {")
|
|
||||||
withIndent {
|
|
||||||
println("return transformElement(", elementParameterName, ", data)")
|
println("return transformElement(", elementParameterName, ", data)")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
println()
|
println()
|
||||||
printVisitMethodDeclaration(
|
printVisitMethodDeclaration(
|
||||||
@@ -83,8 +75,7 @@ private class TransformerPrinter(
|
|||||||
modality = Modality.FINAL,
|
modality = Modality.FINAL,
|
||||||
override = true,
|
override = true,
|
||||||
)
|
)
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
println(
|
println(
|
||||||
"return transform",
|
"return transform",
|
||||||
element.name,
|
element.name,
|
||||||
@@ -94,7 +85,6 @@ private class TransformerPrinter(
|
|||||||
"data)"
|
"data)"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ValueClassRepresentation
|
|||||||
import org.jetbrains.kotlin.generators.tree.*
|
import org.jetbrains.kotlin.generators.tree.*
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.FunctionParameter
|
import org.jetbrains.kotlin.generators.tree.printer.FunctionParameter
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.printFunctionDeclaration
|
import org.jetbrains.kotlin.generators.tree.printer.printFunctionDeclaration
|
||||||
|
import org.jetbrains.kotlin.generators.tree.printer.printFunctionWithBlockBody
|
||||||
import org.jetbrains.kotlin.ir.generator.config.AbstractTreeBuilder
|
import org.jetbrains.kotlin.ir.generator.config.AbstractTreeBuilder
|
||||||
import org.jetbrains.kotlin.ir.generator.config.ElementConfig
|
import org.jetbrains.kotlin.ir.generator.config.ElementConfig
|
||||||
import org.jetbrains.kotlin.ir.generator.config.ElementConfig.Category.*
|
import org.jetbrains.kotlin.ir.generator.config.ElementConfig.Category.*
|
||||||
@@ -776,12 +777,9 @@ object IrTree : AbstractTreeBuilder() {
|
|||||||
vararg statements: String,
|
vararg statements: String,
|
||||||
) {
|
) {
|
||||||
println()
|
println()
|
||||||
printFunctionDeclaration(name, listOf(indexParam) + listOfNotNull(additionalParameter), returnType)
|
printFunctionWithBlockBody(name, listOf(indexParam) + listOfNotNull(additionalParameter), returnType) {
|
||||||
println(" {")
|
|
||||||
withIndent {
|
|
||||||
statements.forEach { println(it) }
|
statements.forEach { println(it) }
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printFunction(
|
printFunction(
|
||||||
|
|||||||
+6
-8
@@ -60,8 +60,7 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!element.isRootElement) {
|
if (!element.isRootElement) {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
for (child in element.walkableChildren) {
|
for (child in element.walkableChildren) {
|
||||||
print(child.name)
|
print(child.name)
|
||||||
if (child.nullable) {
|
if (child.nullable) {
|
||||||
@@ -79,9 +78,9 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("}")
|
} else {
|
||||||
|
println()
|
||||||
}
|
}
|
||||||
println()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.hasTransformChildrenMethod) {
|
if (element.hasTransformChildrenMethod) {
|
||||||
@@ -92,8 +91,7 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
|||||||
override = !element.isRootElement,
|
override = !element.isRootElement,
|
||||||
)
|
)
|
||||||
if (!element.isRootElement) {
|
if (!element.isRootElement) {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
for (child in element.transformableChildren) {
|
for (child in element.transformableChildren) {
|
||||||
print(child.name)
|
print(child.name)
|
||||||
when (child) {
|
when (child) {
|
||||||
@@ -125,9 +123,9 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print("}")
|
} else {
|
||||||
|
println()
|
||||||
}
|
}
|
||||||
println()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-28
@@ -7,10 +7,7 @@ package org.jetbrains.kotlin.ir.generator.print
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.generators.tree.*
|
import org.jetbrains.kotlin.generators.tree.*
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.FunctionParameter
|
import org.jetbrains.kotlin.generators.tree.printer.*
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.GeneratedFile
|
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.printFunctionDeclaration
|
|
||||||
import org.jetbrains.kotlin.generators.tree.printer.printGeneratedType
|
|
||||||
import org.jetbrains.kotlin.ir.generator.*
|
import org.jetbrains.kotlin.ir.generator.*
|
||||||
import org.jetbrains.kotlin.ir.generator.model.*
|
import org.jetbrains.kotlin.ir.generator.model.*
|
||||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
||||||
@@ -100,12 +97,10 @@ private class TransformerPrinter(
|
|||||||
override = true,
|
override = true,
|
||||||
)
|
)
|
||||||
if (element.transformByChildren) {
|
if (element.transformByChildren) {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
println(element.visitorParameterName, ".transformChildren(this, data)")
|
println(element.visitorParameterName, ".transformChildren(this, data)")
|
||||||
println("return ", element.visitorParameterName)
|
println("return ", element.visitorParameterName)
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
} else {
|
} else {
|
||||||
println(" =")
|
println(" =")
|
||||||
withIndent {
|
withIndent {
|
||||||
@@ -162,7 +157,7 @@ private class TransformerVoidPrinter(
|
|||||||
override fun SmartPrinter.printAdditionalMethods() {
|
override fun SmartPrinter.printAdditionalMethods() {
|
||||||
println()
|
println()
|
||||||
val typeParameter = TypeVariable("T", listOf(IrTree.rootElement))
|
val typeParameter = TypeVariable("T", listOf(IrTree.rootElement))
|
||||||
printFunctionDeclaration(
|
printFunctionWithBlockBody(
|
||||||
name = "transformPostfix",
|
name = "transformPostfix",
|
||||||
parameters = listOf(FunctionParameter("body", Lambda(receiver = typeParameter, returnType = StandardTypes.unit))),
|
parameters = listOf(FunctionParameter("body", Lambda(receiver = typeParameter, returnType = StandardTypes.unit))),
|
||||||
returnType = typeParameter,
|
returnType = typeParameter,
|
||||||
@@ -170,27 +165,21 @@ private class TransformerVoidPrinter(
|
|||||||
extensionReceiver = typeParameter,
|
extensionReceiver = typeParameter,
|
||||||
visibility = Visibility.PROTECTED,
|
visibility = Visibility.PROTECTED,
|
||||||
isInline = true,
|
isInline = true,
|
||||||
)
|
) {
|
||||||
println(" {")
|
|
||||||
withIndent {
|
|
||||||
println("transformChildrenVoid()")
|
println("transformChildrenVoid()")
|
||||||
println("this.body()")
|
println("this.body()")
|
||||||
println("return this")
|
println("return this")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
println()
|
println()
|
||||||
printFunctionDeclaration(
|
printFunctionWithBlockBody(
|
||||||
name = "transformChildrenVoid",
|
name = "transformChildrenVoid",
|
||||||
parameters = emptyList(),
|
parameters = emptyList(),
|
||||||
returnType = StandardTypes.unit,
|
returnType = StandardTypes.unit,
|
||||||
extensionReceiver = IrTree.rootElement,
|
extensionReceiver = IrTree.rootElement,
|
||||||
visibility = Visibility.PROTECTED,
|
visibility = Visibility.PROTECTED,
|
||||||
)
|
) {
|
||||||
println(" {")
|
|
||||||
withIndent {
|
|
||||||
println("transformChildrenVoid(this@", visitorType.simpleName, ")")
|
println("transformChildrenVoid(this@", visitorType.simpleName, ")")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context(ImportCollector)
|
context(ImportCollector)
|
||||||
@@ -201,12 +190,10 @@ private class TransformerVoidPrinter(
|
|||||||
println()
|
println()
|
||||||
printVisitMethodDeclaration(element, hasDataParameter = false, modality = Modality.OPEN)
|
printVisitMethodDeclaration(element, hasDataParameter = false, modality = Modality.OPEN)
|
||||||
if (element.transformByChildrenVoid && !element.isPackageFragmentChild) {
|
if (element.transformByChildrenVoid && !element.isPackageFragmentChild) {
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
println(element.visitorParameterName, ".transformChildren(this, null)")
|
println(element.visitorParameterName, ".transformChildren(this, null)")
|
||||||
println("return ", element.visitorParameterName)
|
println("return ", element.visitorParameterName)
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
} else {
|
} else {
|
||||||
println(" =")
|
println(" =")
|
||||||
withIndent {
|
withIndent {
|
||||||
@@ -242,17 +229,14 @@ fun printTransformerVoid(generationPath: File, model: Model): GeneratedFile =
|
|||||||
TransformerVoidPrinter(this, elementTransformerVoidType).printVisitor(model.elements)
|
TransformerVoidPrinter(this, elementTransformerVoidType).printVisitor(model.elements)
|
||||||
println()
|
println()
|
||||||
val transformerParameter = FunctionParameter("transformer", elementTransformerVoidType)
|
val transformerParameter = FunctionParameter("transformer", elementTransformerVoidType)
|
||||||
printFunctionDeclaration(
|
printFunctionWithBlockBody(
|
||||||
name = "transformChildrenVoid",
|
name = "transformChildrenVoid",
|
||||||
parameters = listOf(transformerParameter),
|
parameters = listOf(transformerParameter),
|
||||||
returnType = StandardTypes.unit,
|
returnType = StandardTypes.unit,
|
||||||
extensionReceiver = IrTree.rootElement,
|
extensionReceiver = IrTree.rootElement,
|
||||||
)
|
) {
|
||||||
println(" {")
|
|
||||||
withIndent {
|
|
||||||
println("transformChildren(", transformerParameter.name, ", null)")
|
println("transformChildren(", transformerParameter.name, ", null)")
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TypeTransformerPrinter(
|
private class TypeTransformerPrinter(
|
||||||
@@ -340,8 +324,7 @@ private class TypeTransformerPrinter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
when (element.name) {
|
when (element.name) {
|
||||||
IrTree.memberAccessExpression.name -> {
|
IrTree.memberAccessExpression.name -> {
|
||||||
if (irTypeFields.singleOrNull()?.name != "typeArguments") {
|
if (irTypeFields.singleOrNull()?.name != "typeArguments") {
|
||||||
@@ -385,7 +368,6 @@ private class TypeTransformerPrinter(
|
|||||||
", data)"
|
", data)"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -146,8 +146,7 @@ abstract class AbstractVisitorPrinter<Element : AbstractElement<Element, Field>,
|
|||||||
print(" : ", it.render(), it.inheritanceClauseParenthesis())
|
print(" : ", it.render(), it.inheritanceClauseParenthesis())
|
||||||
}
|
}
|
||||||
print(visitorTypeParameters.multipleUpperBoundsList())
|
print(visitorTypeParameters.multipleUpperBoundsList())
|
||||||
println(" {")
|
printBlock {
|
||||||
withIndent {
|
|
||||||
printAdditionalMethods()
|
printAdditionalMethods()
|
||||||
for (element in elements) {
|
for (element in elements) {
|
||||||
if (element.isRootElement && visitSuperTypeByDefault) continue
|
if (element.isRootElement && visitSuperTypeByDefault) continue
|
||||||
@@ -155,7 +154,6 @@ abstract class AbstractVisitorPrinter<Element : AbstractElement<Element, Field>,
|
|||||||
printMethodsForElement(element)
|
printMethodsForElement(element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-5
@@ -6,8 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.generators.tree
|
package org.jetbrains.kotlin.generators.tree
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
|
import org.jetbrains.kotlin.generators.tree.printer.printBlock
|
||||||
import org.jetbrains.kotlin.utils.SmartPrinter
|
import org.jetbrains.kotlin.utils.SmartPrinter
|
||||||
import org.jetbrains.kotlin.utils.withIndent
|
|
||||||
|
|
||||||
abstract class AbstractVisitorVoidPrinter<Element, Field>(
|
abstract class AbstractVisitorVoidPrinter<Element, Field>(
|
||||||
printer: SmartPrinter,
|
printer: SmartPrinter,
|
||||||
@@ -50,13 +50,11 @@ abstract class AbstractVisitorVoidPrinter<Element, Field>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun SmartPrinter.printBody(parentInVisitor: Element?) {
|
fun SmartPrinter.printBody(parentInVisitor: Element?) {
|
||||||
println(" {")
|
printBlock {
|
||||||
if (parentInVisitor != null) {
|
if (parentInVisitor != null) {
|
||||||
withIndent {
|
|
||||||
println(parentInVisitor.visitFunctionName, "(", element.visitorParameterName, ")")
|
println(parentInVisitor.visitFunctionName, "(", element.visitorParameterName, ")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println("}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printer.run {
|
printer.run {
|
||||||
|
|||||||
+35
@@ -161,6 +161,41 @@ fun SmartPrinter.printFunctionDeclaration(
|
|||||||
print(typeParameters.multipleUpperBoundsList())
|
print(typeParameters.multipleUpperBoundsList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context(ImportCollector)
|
||||||
|
inline fun SmartPrinter.printFunctionWithBlockBody(
|
||||||
|
name: String,
|
||||||
|
parameters: List<FunctionParameter>,
|
||||||
|
returnType: TypeRef,
|
||||||
|
typeParameters: List<TypeVariable> = emptyList(),
|
||||||
|
extensionReceiver: TypeRef? = null,
|
||||||
|
visibility: Visibility = Visibility.PUBLIC,
|
||||||
|
modality: Modality? = null,
|
||||||
|
override: Boolean = false,
|
||||||
|
isInline: Boolean = false,
|
||||||
|
allParametersOnSeparateLines: Boolean = false,
|
||||||
|
blockBody: () -> Unit,
|
||||||
|
) {
|
||||||
|
printFunctionDeclaration(
|
||||||
|
name,
|
||||||
|
parameters,
|
||||||
|
returnType,
|
||||||
|
typeParameters,
|
||||||
|
extensionReceiver,
|
||||||
|
visibility,
|
||||||
|
modality,
|
||||||
|
override,
|
||||||
|
isInline,
|
||||||
|
allParametersOnSeparateLines,
|
||||||
|
)
|
||||||
|
printBlock(blockBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun SmartPrinter.printBlock(body: () -> Unit) {
|
||||||
|
println(" {")
|
||||||
|
withIndent(body)
|
||||||
|
println("}")
|
||||||
|
}
|
||||||
|
|
||||||
private val dataTP = TypeVariable("D")
|
private val dataTP = TypeVariable("D")
|
||||||
private val dataParameter = FunctionParameter("data", dataTP)
|
private val dataParameter = FunctionParameter("data", dataTP)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user