diff --git a/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt b/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt index 9bb98985358..2fc0bc75d43 100644 --- a/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/ArrayWithoutInitializationExpression.kt @@ -15,14 +15,12 @@ public open class ArrayWithoutInitializationExpression(val `type` : Type, val ex } private fun constructInnerType(hostType : ArrayType, expressions: List) : String { - if (expressions.size() == 1) - { + if (expressions.size() == 1) { return oneDim(hostType, expressions[0]) } val innerType = hostType.elementType - if (expressions.size() > 1 && innerType is ArrayType) - { + if (expressions.size() > 1 && innerType is ArrayType) { return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType, expressions.subList(1, expressions.size())) + "}") } @@ -35,11 +33,7 @@ public open class ArrayWithoutInitializationExpression(val `type` : Type, val ex } private open fun oneDim(`type` : Type, size : Expression, init : String) : String { - val commaWithInit = (if (init.isEmpty()) - "" - else - ", " + init) - return getConstructorName(`type`) + "(" + size.toKotlin() + commaWithInit + ")" + return getConstructorName(`type`) + "(" + size.toKotlin() + init.withPrefix(", ") + ")" } private open fun getConstructorName(`type` : Type) : String = `type`.convertedToNotNull().toKotlin() diff --git a/src/org/jetbrains/jet/j2k/ast/AssignmentExpression.kt b/src/org/jetbrains/jet/j2k/ast/AssignmentExpression.kt index 5f2b6aec37f..d23bd782875 100644 --- a/src/org/jetbrains/jet/j2k/ast/AssignmentExpression.kt +++ b/src/org/jetbrains/jet/j2k/ast/AssignmentExpression.kt @@ -2,7 +2,5 @@ package org.jetbrains.jet.j2k.ast public open class AssignmentExpression(val left : Expression, val right : Expression, val op : String) : Expression() { - public override fun toKotlin() : String { - return left.toKotlin() + " "+ op + " "+ right.toKotlin() - } + public override fun toKotlin() : String = left.toKotlin() + " "+ op + " "+ right.toKotlin() } diff --git a/src/org/jetbrains/jet/j2k/ast/BreakStatement.kt b/src/org/jetbrains/jet/j2k/ast/BreakStatement.kt deleted file mode 100644 index 6ff50b40df5..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/BreakStatement.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.jet.j2k.ast - - -public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() { - public override fun toKotlin() : String { - return if (label.isEmpty()) "break" else "break@" + label.toKotlin() - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/CaseContainer.kt b/src/org/jetbrains/jet/j2k/ast/CaseContainer.kt deleted file mode 100644 index 91979d27894..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/CaseContainer.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.util.AstUtil -import java.util.LinkedList -import java.util.List - -public open class CaseContainer(val caseStatement: List, statements: List): Statement() { - private val myBlock: Block - - { - val newStatements: List = statements.filterNot { it is BreakStatement || it is ContinueStatement } - myBlock = Block(newStatements, false) - } - - public override fun toKotlin(): String { - return AstUtil.joinNodes(caseStatement, ", ") + " -> " + myBlock.toKotlin() - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/CatchStatement.kt b/src/org/jetbrains/jet/j2k/ast/CatchStatement.kt deleted file mode 100644 index 3261b93ff8e..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/CatchStatement.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.jet.j2k.ast - - -public open class CatchStatement(val variable: Parameter, val block: Block): Statement() { - public override fun toKotlin(): String { - return "catch (" + variable.toKotlin() + ") " + block.toKotlin() - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Class.kt b/src/org/jetbrains/jet/j2k/ast/Class.kt index 240a8e85f28..53c8f5d7d8e 100644 --- a/src/org/jetbrains/jet/j2k/ast/Class.kt +++ b/src/org/jetbrains/jet/j2k/ast/Class.kt @@ -36,10 +36,9 @@ public open class Class(converter : Converter, } open fun primaryConstructorBodyToKotlin() : String? { - var maybeConstructor : Constructor? = getPrimaryConstructor() - if (maybeConstructor != null && !(maybeConstructor?.block?.isEmpty() ?: true)) - { - return maybeConstructor?.primaryBodyToKotlin() + val maybeConstructor : Constructor? = getPrimaryConstructor() + if (maybeConstructor != null && !(maybeConstructor.block?.isEmpty() ?: true)) { + return maybeConstructor.primaryBodyToKotlin() } return "" @@ -48,8 +47,7 @@ public open class Class(converter : Converter, private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() } open fun typeParameterWhereToKotlin() : String { - if (hasWhere()) - { + if (hasWhere()) { val wheres = typeParameters.filter { it is TypeParameter }.map { (it as TypeParameter).getWhereToKotlin() } return " where " + wheres.makeString(", ") + " " } @@ -75,26 +73,20 @@ public open class Class(converter : Converter, constructorTypeParameters, f.params, block) } - open fun typeParametersToKotlin() : String { - return (if (typeParameters.size() > 0) - "<" + typeParameters.map { it.toKotlin() }.makeString(", ") + ">" - else - "") - } + open fun typeParametersToKotlin() : String = typeParameters.toKotlin(", ", "<", ">") - open fun baseClassSignatureWithParams() : List { - if (TYPE.equals("class") && extendsTypes.size() == 1) - { - val baseParams = baseClassParams.map { it.toKotlin() }.makeString(", ") + open fun baseClassSignatureWithParams() : List { + if (TYPE.equals("class") && extendsTypes.size() == 1) { + val baseParams = baseClassParams.toKotlin(", ") return arrayList(extendsTypes[0].toKotlin() + "(" + baseParams + ")") } - return nodesToKotlin(extendsTypes) + return extendsTypes.map { it.toKotlin() } } open fun implementTypesToKotlin() : String { val allTypes : List = arrayList() allTypes.addAll(baseClassSignatureWithParams()) - allTypes.addAll(nodesToKotlin(implementsTypes)) + allTypes.addAll(implementsTypes.map { it.toKotlin() }) return if (allTypes.size() == 0) "" else @@ -104,18 +96,15 @@ public open class Class(converter : Converter, open fun modifiersToKotlin() : String { val modifierList : List = arrayList() modifierList.add(accessModifier()) - if (needAbstractModifier()) - { + if (needAbstractModifier()) { modifierList.add(Modifier.ABSTRACT) } - if (needOpenModifier()) - { + if (needOpenModifier()) { modifierList.add(Modifier.OPEN) } - if (modifierList.size() > 0) - { + if (modifierList.size() > 0) { return modifierList.makeString(" ") + " " } @@ -127,20 +116,16 @@ public open class Class(converter : Converter, open fun needAbstractModifier() = isAbstract() open fun bodyToKotlin() : String { - return " {\n" + AstUtil.joinNodes(getNonStatic(membersExceptConstructors()), "\n") + "\n" + primaryConstructorBodyToKotlin() + "\n" + classObjectToKotlin() + "\n}" + return " {\n" + getNonStatic(membersExceptConstructors()).toKotlin("\n") + "\n" + primaryConstructorBodyToKotlin() + "\n" + classObjectToKotlin() + "\n}" } private fun classObjectToKotlin() : String { val staticMembers : List = arrayList() staticMembers.addAll(secondaryConstructorsAsStaticInitFunction()) staticMembers.addAll(getStatic(membersExceptConstructors())) - if (staticMembers.size() > 0) - { - return "class object {\n" + AstUtil.joinNodes(staticMembers, "\n") + "\n}" - } - - return "" + return staticMembers.toKotlin("\n", "class object {\n", "\n}") } + public override fun toKotlin() : String = modifiersToKotlin() + TYPE + " " + name.toKotlin() + @@ -152,18 +137,8 @@ public open class Class(converter : Converter, class object { open fun getMembers(members : List, converter : Converter) : List { - if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS).sure()) - { - val withoutPrivate : List = arrayList() - for (m : Member in members) - { - if (m.accessModifier().equals("public") || m.accessModifier().equals("protected")) - { - withoutPrivate.add(m) - } - - } - return withoutPrivate + if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) { + return members.filter { it.accessModifier() == "public" || it.accessModifier() == "protected" } } return members } diff --git a/src/org/jetbrains/jet/j2k/ast/ContinueStatement.kt b/src/org/jetbrains/jet/j2k/ast/ContinueStatement.kt deleted file mode 100644 index c2898ba6f9b..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ContinueStatement.kt +++ /dev/null @@ -1,12 +0,0 @@ -package org.jetbrains.jet.j2k.ast - - -public open class ContinueStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER): Statement() { - public override fun toKotlin(): String { - if (label.isEmpty()) { - return "continue" - } - - return "continue@" + label.toKotlin() - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.kt b/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.kt deleted file mode 100644 index 926aca9bc66..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.jetbrains.jet.j2k.ast - -import org.jetbrains.jet.j2k.util.AstUtil -import java.util.LinkedList -import java.util.List - -public open class DeclarationStatement(val elements: List): Statement() { - public override fun toKotlin(): String { - return elements.filter { it is LocalVariable }.map { convertDeclaration(it as LocalVariable) }.makeString("\n") - } - - private fun convertDeclaration(v: LocalVariable): String { - val varKeyword: String? = (if (v.hasModifier(Modifier.FINAL)) - "val" - else - "var") - return varKeyword + " " + v.toKotlin() - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.kt b/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.kt deleted file mode 100644 index d5967637481..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.jet.j2k.ast - - -public open class DefaultSwitchLabelStatement(): Statement() { - public override fun toKotlin() = "else" -} diff --git a/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.kt b/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.kt deleted file mode 100644 index 2a0d6ba669d..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.jet.j2k.ast - - -public open class DoWhileStatement(condition: Expression, statement: Statement): WhileStatement(condition, statement) { - public override fun toKotlin(): String { - return "do\n" + statement.toKotlin() + "\nwhile (" + condition.toKotlin() + ")" - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ExpressionListStatement.java b/src/org/jetbrains/jet/j2k/ast/ExpressionListStatement.java deleted file mode 100644 index 810dbd14f6b..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ExpressionListStatement.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.util.AstUtil; - -import java.util.List; - -/** - * @author ignatov - */ -public class ExpressionListStatement extends Expression { - private final List myExpressions; - - public ExpressionListStatement(List expressions) { - myExpressions = expressions; - } - - @NotNull - @Override - public String toKotlin() { - return AstUtil.joinNodes(myExpressions, N); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/LabelStatement.java b/src/org/jetbrains/jet/j2k/ast/LabelStatement.java deleted file mode 100644 index 0d0c7ebdfa9..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/LabelStatement.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; - -/** - * @author ignatov - */ -public class LabelStatement extends Statement { - private final Identifier myName; - private final Statement myStatement; - - public LabelStatement(Identifier name, Statement statement) { - myName = name; - myStatement = statement; - } - - @NotNull - @Override - public String toKotlin() { - return AT + myName.toKotlin() + SPACE + myStatement.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ReturnStatement.kt b/src/org/jetbrains/jet/j2k/ast/ReturnStatement.kt deleted file mode 100644 index 2403273b126..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ReturnStatement.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.jetbrains.jet.j2k.ast - -public open class ReturnStatement(val expression: Expression): Statement() { - public override fun toKotlin() = "return " + expression.toKotlin() -} diff --git a/src/org/jetbrains/jet/j2k/ast/Statements.kt b/src/org/jetbrains/jet/j2k/ast/Statements.kt new file mode 100644 index 00000000000..dd68b37cc25 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/Statements.kt @@ -0,0 +1,91 @@ +package org.jetbrains.jet.j2k.ast + +import java.util.List + +public open class DeclarationStatement(val elements: List): Statement() { + public override fun toKotlin(): String { + return elements.filter { it is LocalVariable }.map { convertDeclaration(it as LocalVariable) }.makeString("\n") + } + + private fun convertDeclaration(v: LocalVariable): String { + val varKeyword: String? = (if (v.hasModifier(Modifier.FINAL)) + "val" + else + "var") + return varKeyword + " " + v.toKotlin() + } +} + +public open class ExpressionListStatement(val expressions: List): Expression() { + public override fun toKotlin() = expressions.toKotlin("\n") +} + +public open class LabelStatement(val name: Identifier, val statement: Statement): Statement() { + public override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin() +} + +public open class ReturnStatement(val expression: Expression): Statement() { + public override fun toKotlin() = "return " + expression.toKotlin() +} + +// Loops -------------------------------------------------------------------------------------------------- + +public open class WhileStatement(val condition: Expression, val statement: Statement): Statement() { + public override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + statement.toKotlin() +} + +public open class DoWhileStatement(condition: Expression, statement: Statement): WhileStatement(condition, statement) { + public override fun toKotlin() = "do\n" + statement.toKotlin() + "\nwhile (" + condition.toKotlin() + ")" +} + +public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() { + public override fun toKotlin() = "break" + label.withPrefix("@") +} + +public open class ContinueStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER): Statement() { + public override fun toKotlin() = "continue" + label.withPrefix("@") +} + +// Exceptions ---------------------------------------------------------------------------------------------- + +public open class TryStatement(val block: Block, val catches: List, val finallyBlock: Block): Statement() { + public override fun toKotlin(): String { + return "try\n" + block.toKotlin() + "\n" + catches.toKotlin("\n") + "\n" + (if (finallyBlock.isEmpty()) + "" + else + "finally\n" + finallyBlock.toKotlin()) + } +} + +public open class ThrowStatement(val expression: Expression): Expression() { + public override fun toKotlin() = "throw " + expression.toKotlin() +} + +public open class CatchStatement(val variable: Parameter, val block: Block): Statement() { + public override fun toKotlin(): String = "catch (" + variable.toKotlin() + ") " + block.toKotlin() +} + +// Switch -------------------------------------------------------------------------------------------------- + +public open class SwitchContainer(val expression: Expression, val caseContainers: List): Statement() { + public override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}" +} + +public open class CaseContainer(val caseStatement: List, statements: List): Statement() { + private val myBlock: Block + + { + val newStatements: List = statements.filterNot { it is BreakStatement || it is ContinueStatement } + myBlock = Block(newStatements, false) + } + + public override fun toKotlin() = caseStatement.toKotlin(", ") + " -> " + myBlock.toKotlin() +} + +public open class SwitchLabelStatement(val expression: Expression): Statement() { + public override fun toKotlin() = expression.toKotlin() +} + +public open class DefaultSwitchLabelStatement(): Statement() { + public override fun toKotlin() = "else" +} diff --git a/src/org/jetbrains/jet/j2k/ast/SwitchContainer.java b/src/org/jetbrains/jet/j2k/ast/SwitchContainer.java deleted file mode 100644 index 49f41aac5fc..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/SwitchContainer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.util.AstUtil; - -import java.util.List; - -/** - * @author ignatov - */ -public class SwitchContainer extends Statement { - private final Expression myExpression; - private final List myCaseContainers; - - public SwitchContainer(final Expression expression, final List caseContainers) { - myExpression = expression; - myCaseContainers = caseContainers; - } - - @NotNull - @Override - public String toKotlin() { - return "when" + SPACE + "(" + myExpression.toKotlin() + ")" + SPACE + "{" + N + - AstUtil.joinNodes(myCaseContainers, N) + N + - "}"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/SwitchLabelStatement.java b/src/org/jetbrains/jet/j2k/ast/SwitchLabelStatement.java deleted file mode 100644 index adec84ff6be..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/SwitchLabelStatement.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; - -/** - * @author ignatov - */ -public class SwitchLabelStatement extends Statement { - private final Expression myExpression; - - public SwitchLabelStatement(final Expression expression) { - myExpression = expression; - } - - @NotNull - @Override - public String toKotlin() { - return myExpression.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ThrowStatement.java b/src/org/jetbrains/jet/j2k/ast/ThrowStatement.java deleted file mode 100644 index f0b0cbf1a99..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ThrowStatement.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; - -/** - * @author ignatov - */ -public class ThrowStatement extends Expression { - private final Expression myExpression; - - public ThrowStatement(Expression expression) { - myExpression = expression; - } - - @NotNull - @Override - public String toKotlin() { - return "throw" + SPACE + myExpression.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/TryStatement.java b/src/org/jetbrains/jet/j2k/ast/TryStatement.java deleted file mode 100644 index 7bc3ba4bc93..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/TryStatement.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.util.AstUtil; - -import java.util.List; - -/** - * @author ignatov - */ -public class TryStatement extends Statement { - private final Block myBlock; - private final List myCatches; - private final Block myFinallyBlock; - - public TryStatement(Block block, List catches, Block finallyBlock) { - myBlock = block; - myCatches = catches; - myFinallyBlock = finallyBlock; - } - - @NotNull - @Override - public String toKotlin() { - return "try" + N + - myBlock.toKotlin() + N + - AstUtil.joinNodes(myCatches, N) + N + - (myFinallyBlock.isEmpty() ? EMPTY : "finally" + N + myFinallyBlock.toKotlin()); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Util.kt b/src/org/jetbrains/jet/j2k/ast/Util.kt index 084e17ac1b0..9061acf5355 100644 --- a/src/org/jetbrains/jet/j2k/ast/Util.kt +++ b/src/org/jetbrains/jet/j2k/ast/Util.kt @@ -2,11 +2,20 @@ package org.jetbrains.jet.j2k.ast import java.util.List -fun List.toKotlin(separator: String): String { +fun List.toKotlin(separator: String, prefix: String = "", suffix: String = ""): String { val result = StringBuilder() - for(x in this) { - if (result.length() > 0) result.append(separator) - result.append(x.toKotlin()) + if (size() > 0) { + result.append(prefix) + var first = true + for(x in this) { + if (!first) result.append(separator) + first = false + result.append(x.toKotlin()) + } + result.append(suffix) } return result.toString()!! } + +fun String.withPrefix(prefix: String) = if (isEmpty()) "" else prefix + this +fun Expression.withPrefix(prefix: String) = if (isEmpty()) "" else prefix + toKotlin() diff --git a/src/org/jetbrains/jet/j2k/ast/WhileStatement.kt b/src/org/jetbrains/jet/j2k/ast/WhileStatement.kt deleted file mode 100644 index b79beeeead3..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/WhileStatement.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.jet.j2k.ast - - -public open class WhileStatement(val condition: Expression, val statement: Statement): Statement() { - public override fun toKotlin(): String { - return "while (" + condition.toKotlin() + ")\n" + statement.toKotlin() - } -}