diff --git a/src/org/jetbrains/jet/j2k/ast/CatchStatement.java b/src/org/jetbrains/jet/j2k/ast/CatchStatement.java deleted file mode 100644 index 044d4808b6e..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/CatchStatement.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 CatchStatement extends Statement { - private final Parameter myVariable; - private final Block myBlock; - - public CatchStatement(Parameter variable, Block block) { - myVariable = variable; - myBlock = block; - } - - @NotNull - @Override - public String toKotlin() { - return "catch" + SPACE + "(" + myVariable.toKotlin() + ")" + SPACE + myBlock.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/CatchStatement.kt b/src/org/jetbrains/jet/j2k/ast/CatchStatement.kt new file mode 100644 index 00000000000..3261b93ff8e --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/CatchStatement.kt @@ -0,0 +1,8 @@ +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/ClassObjectAccessExpression.java b/src/org/jetbrains/jet/j2k/ast/ClassObjectAccessExpression.java deleted file mode 100644 index 78aefcb3f3e..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ClassObjectAccessExpression.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 ClassObjectAccessExpression extends Expression { - private final Element myTypeElement; - - public ClassObjectAccessExpression(Element typeElement) { - myTypeElement = typeElement; - } - - @NotNull - @Override - public String toKotlin() { - return "getJavaClass" + "<" + myTypeElement.toKotlin() + ">"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ClassObjectAccessExpression.kt b/src/org/jetbrains/jet/j2k/ast/ClassObjectAccessExpression.kt new file mode 100644 index 00000000000..fa3dbd0c3cf --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/ClassObjectAccessExpression.kt @@ -0,0 +1,8 @@ +package org.jetbrains.jet.j2k.ast + + +public open class ClassObjectAccessExpression(val typeElement: Element): Expression() { + public override fun toKotlin(): String { + return "getJavaClass<" + typeElement.toKotlin() + ">" + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.java b/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.java deleted file mode 100644 index 165babb208c..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.java +++ /dev/null @@ -1,56 +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.LinkedList; -import java.util.List; - -/** - * @author ignatov - */ -public class DeclarationStatement extends Statement { - private final List myElements; - - public DeclarationStatement(List elements) { - myElements = elements; - } - - @NotNull - private static List toStringList(@NotNull List elements) { - List result = new LinkedList(); - for (Element e : elements) { - if (e instanceof LocalVariable) { - LocalVariable v = (LocalVariable) e; - - final String varKeyword = v.hasModifier(Modifier.FINAL) ? "val" : "var"; - result.add( - varKeyword + SPACE + e.toKotlin() - ); - } - } - return result; - } - - @NotNull - @Override - public String toKotlin() { - return AstUtil.join(toStringList(myElements), N); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.kt b/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.kt new file mode 100644 index 00000000000..926aca9bc66 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/DeclarationStatement.kt @@ -0,0 +1,19 @@ +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.java b/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.java deleted file mode 100644 index a7d71d772cd..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.java +++ /dev/null @@ -1,30 +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 DefaultSwitchLabelStatement extends Statement { - @NotNull - @Override - public String toKotlin() { - return "else"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.kt b/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.kt new file mode 100644 index 00000000000..d5967637481 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/DefaultSwitchLabelStatement.kt @@ -0,0 +1,6 @@ +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.java b/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.java deleted file mode 100644 index 9592d8c8883..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.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 DoWhileStatement extends WhileStatement { - public DoWhileStatement(Expression condition, Statement statement) { - super(condition, statement); - } - - @NotNull - @Override - public String toKotlin() { - return "do" + N + - myStatement.toKotlin() + N + - "while" + SPACE + "(" + myCondition.toKotlin() + ")"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.kt b/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.kt new file mode 100644 index 00000000000..2a0d6ba669d --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/DoWhileStatement.kt @@ -0,0 +1,8 @@ +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/WhileStatement.java b/src/org/jetbrains/jet/j2k/ast/WhileStatement.java deleted file mode 100644 index 9ee87e671cb..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/WhileStatement.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; - -/** - * @author ignatov - */ -public class WhileStatement extends Statement { - final Expression myCondition; - final Statement myStatement; - - public WhileStatement(Expression condition, Statement statement) { - myCondition = condition; - myStatement = statement; - } - - @NotNull - @Override - public String toKotlin() { - return "while" + SPACE + "(" + myCondition.toKotlin() + ")" + N + - myStatement.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/WhileStatement.kt b/src/org/jetbrains/jet/j2k/ast/WhileStatement.kt new file mode 100644 index 00000000000..b79beeeead3 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/WhileStatement.kt @@ -0,0 +1,8 @@ +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() + } +}