New J2K: Add ';' in a case of For loop and While loop empty body

This commit is contained in:
Ilya Kirillov
2018-11-10 20:25:40 +03:00
committed by Ilya Kirillov
parent 3ddc05fdd9
commit 4310575de9
2 changed files with 25 additions and 8 deletions
@@ -86,13 +86,17 @@ class NewCodeBuilder {
}
}
override fun visitKtForInStatement(ktForInStatement: JKKtForInStatement) {
override fun visitForInStatement(forInStatement: JKForInStatement) {
printer.printWithNoIndent("for (")
ktForInStatement.declaration.accept(this)
forInStatement.declaration.accept(this)
printer.printWithNoIndent(" in ")
ktForInStatement.iterationExpression.accept(this)
forInStatement.iterationExpression.accept(this)
printer.printWithNoIndent(") ")
ktForInStatement.body.accept(this)
if (forInStatement.body.isEmpty()) {
printer.printWithNoIndent(";")
} else {
forInStatement.body.accept(this)
}
}
override fun visitKtThrowExpression(ktThrowExpression: JKKtThrowExpression) {
@@ -477,11 +481,15 @@ class NewCodeBuilder {
printer.print("while(")
whileStatement.condition.accept(this)
printer.printWithNoIndent(")")
renderStatementOrBlock(whileStatement.body, multiline = true)
if (whileStatement.body.isEmpty()) {
printer.printWithNoIndent(";")
} else {
renderStatementOrBlock(whileStatement.body, multiline = true)
}
}
override fun visitLocalVariable(localVariable: JKLocalVariable) {
if (localVariable.parent !is JKKtForInStatement) {
if (localVariable.parent !is JKForInStatement) {
if (localVariable.modifierList.modality == JKModalityModifier.Modality.FINAL) {
printer.print("val")
} else {
@@ -600,7 +608,8 @@ class NewCodeBuilder {
}
override fun visitKtConstructor(ktConstructor: JKKtConstructor) {
printer.print("constructor")
ktConstructor.modifierList.accept(this)
printer.print(" constructor")
renderParameterList(ktConstructor.parameters)
if (ktConstructor.delegationCall !is JKStubExpression) {
builder.append(" : ")
@@ -492,4 +492,12 @@ class JKForInStatementImpl(declaration: JKDeclaration, iterationExpression: JKEx
override var iterationExpression: JKExpression by child(iterationExpression)
override var body: JKStatement by child(body)
override fun <R, D> accept(visitor: JKVisitor<R, D>, data: D): R = visitor.visitForInStatement(this, data)
}
}
fun JKStatement.isEmpty(): Boolean =
when (this) {
is JKEmptyStatement -> true
is JKBlockStatement -> block is JKBodyStub || block.statements.isEmpty()
is JKExpressionStatement -> expression is JKStubExpression
else -> false
}