diff --git a/src/org/jetbrains/jet/j2k/Converter.kt b/src/org/jetbrains/jet/j2k/Converter.kt index 23b9e27cf88..6b80bb352a2 100644 --- a/src/org/jetbrains/jet/j2k/Converter.kt +++ b/src/org/jetbrains/jet/j2k/Converter.kt @@ -529,7 +529,7 @@ public open class Converter() { return false } private fun removeEmpty(statements: List): List { - return statements.filterNot { it == Statement.EMPTY_STATEMENT || it == Expression.EMPTY_EXPRESSION } + return statements.filterNot { it is EmptyStatement || it == Expression.EMPTY_EXPRESSION } } private fun isNotOpenMethod(method: PsiMethod): Boolean { diff --git a/src/org/jetbrains/jet/j2k/ast/Identifier.java b/src/org/jetbrains/jet/j2k/ast/Identifier.java deleted file mode 100644 index ce93ae46c91..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/Identifier.java +++ /dev/null @@ -1,77 +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 Identifier extends Expression { - @NotNull - public static Identifier EMPTY_IDENTIFIER = new Identifier(""); - - private final String myName; - private boolean myIsNullable = true; - private boolean myQuotingNeeded = true; - - public Identifier(String name) { - myName = name; - } - - public Identifier(String name, boolean isNullable) { - myName = name; - myIsNullable = isNullable; - } - - public Identifier(String name, boolean isNullable, boolean quotingNeeded) { - myName = name; - myIsNullable = isNullable; - myQuotingNeeded = quotingNeeded; - } - - public boolean isEmpty() { - return myName.length() == 0; - } - - public String getName() { - return myName; - } - - @NotNull - private static String quote(String str) { - return BACKTICK + str + BACKTICK; - } - - @Override - public boolean isNullable() { - return myIsNullable; - } - - private String ifNeedQuote() { - if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) { - return quote(myName); - } - return myName; - } - - @NotNull - @Override - public String toKotlin() { - return ifNeedQuote(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Identifier.kt b/src/org/jetbrains/jet/j2k/ast/Identifier.kt new file mode 100644 index 00000000000..4f56ff237a4 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/Identifier.kt @@ -0,0 +1,26 @@ +package org.jetbrains.jet.j2k.ast + + +public open class Identifier(val name: String, + val nullable: Boolean = true, + val quotingNeeded: Boolean = true): Expression() { + public override fun isEmpty(): Boolean { + return name.length() == 0 + } + private open fun ifNeedQuote(): String { + if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS?.contains(name)) || name.contains("$"))) { + return quote(name) + } + + return name + } + + public override fun toKotlin(): String = ifNeedQuote() + + class object { + public val EMPTY_IDENTIFIER: Identifier = Identifier("") + private open fun quote(str: String): String { + return "`" + str + "`" + } + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Statement.java b/src/org/jetbrains/jet/j2k/ast/Statement.java deleted file mode 100644 index 90db4244f26..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/Statement.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 abstract class Statement extends Element { - @NotNull - public static final Statement EMPTY_STATEMENT = new EmptyStatement(); - - /** - * @author ignatov - */ - private static class EmptyStatement extends Statement { - @NotNull - @Override - public String toKotlin() { - return EMPTY; - } - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Statements.kt b/src/org/jetbrains/jet/j2k/ast/Statements.kt index 49bd2e50d9a..8ebd8bf72b8 100644 --- a/src/org/jetbrains/jet/j2k/ast/Statements.kt +++ b/src/org/jetbrains/jet/j2k/ast/Statements.kt @@ -2,6 +2,14 @@ package org.jetbrains.jet.j2k.ast import java.util.List +public abstract class Statement(): Element() { + class object { + public val EMPTY_STATEMENT = object : Statement { + public override fun toKotlin() = "" + } + } +} + 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") @@ -31,7 +39,7 @@ public open class ReturnStatement(val expression: Expression): Statement() { public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() { public override fun toKotlin(): String { val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n" - if (elseStatement != Statement.EMPTY_STATEMENT) { + if (elseStatement !is EmptyStatement) { return result + "else\n" + elseStatement.toKotlin() } diff --git a/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt index bc2bd96052c..5aedf1b30bd 100644 --- a/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt @@ -12,7 +12,7 @@ import java.util.List import org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses public open class StatementVisitor(converter: Converter): ElementVisitor(converter) { - private var myResult: Statement = Statement.EMPTY_STATEMENT + private var myResult: Statement = public override fun getResult(): Statement { return myResult }