[FIR/IR generator] Reduce duplication when printing curly-braced blocks
This commit is contained in:
committed by
Space Team
parent
18ed85c26e
commit
fab63e38aa
+1
-3
@@ -146,8 +146,7 @@ abstract class AbstractVisitorPrinter<Element : AbstractElement<Element, Field>,
|
||||
print(" : ", it.render(), it.inheritanceClauseParenthesis())
|
||||
}
|
||||
print(visitorTypeParameters.multipleUpperBoundsList())
|
||||
println(" {")
|
||||
withIndent {
|
||||
printBlock {
|
||||
printAdditionalMethods()
|
||||
for (element in elements) {
|
||||
if (element.isRootElement && visitSuperTypeByDefault) continue
|
||||
@@ -155,7 +154,6 @@ abstract class AbstractVisitorPrinter<Element : AbstractElement<Element, Field>,
|
||||
printMethodsForElement(element)
|
||||
}
|
||||
}
|
||||
println("}")
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -6,8 +6,8 @@
|
||||
package org.jetbrains.kotlin.generators.tree
|
||||
|
||||
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.withIndent
|
||||
|
||||
abstract class AbstractVisitorVoidPrinter<Element, Field>(
|
||||
printer: SmartPrinter,
|
||||
@@ -50,13 +50,11 @@ abstract class AbstractVisitorVoidPrinter<Element, Field>(
|
||||
)
|
||||
|
||||
fun SmartPrinter.printBody(parentInVisitor: Element?) {
|
||||
println(" {")
|
||||
if (parentInVisitor != null) {
|
||||
withIndent {
|
||||
printBlock {
|
||||
if (parentInVisitor != null) {
|
||||
println(parentInVisitor.visitFunctionName, "(", element.visitorParameterName, ")")
|
||||
}
|
||||
}
|
||||
println("}")
|
||||
}
|
||||
|
||||
printer.run {
|
||||
|
||||
+35
@@ -161,6 +161,41 @@ fun SmartPrinter.printFunctionDeclaration(
|
||||
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 dataParameter = FunctionParameter("data", dataTP)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user