diff --git a/j2k/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt b/j2k/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt deleted file mode 100644 index a43fef22c9f..00000000000 --- a/j2k/src/org/jetbrains/jet/j2k/ast/AssertStatement.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010-2013 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 - - -class AssertStatement(val condition: Expression, val detail: Expression) : Statement() { - override fun toKotlin(): String { - val lazyStringMessage = if (detail != Expression.Empty) - " {" + detail.toKotlin() + "}" - else - "" - return "assert(${condition.toKotlin()})$lazyStringMessage" - } -} diff --git a/j2k/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt b/j2k/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt index 6518a05bc97..04b61e433e9 100644 --- a/j2k/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt +++ b/j2k/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.kt @@ -30,8 +30,20 @@ open class StatementVisitor(public val converter: Converter) : JavaElementVisito protected set override fun visitAssertStatement(statement: PsiAssertStatement) { - result = AssertStatement(converter.convertExpression(statement.getAssertCondition()), - converter.convertExpression(statement.getAssertDescription())) + val descriptionExpr = statement.getAssertDescription() + val condition = converter.convertExpression(statement.getAssertCondition()) + if (descriptionExpr == null) { + result = MethodCallExpression.buildNotNull(null, "assert", listOf(condition)) + } + else { + val description = converter.convertExpression(descriptionExpr) + if (descriptionExpr is PsiLiteralExpression) { + result = MethodCallExpression.buildNotNull(null, "assert", listOf(condition, description)) + } + else { + result = MethodCallExpression.build(null, "assert", listOf(condition), listOf(), false, LambdaExpression(null, StatementList(listOf(description)))) + } + } } override fun visitBlockStatement(statement: PsiBlockStatement) { diff --git a/j2k/tests/test/org/jetbrains/jet/j2k/test/JavaToKotlinConverterTestGenerated.java b/j2k/tests/test/org/jetbrains/jet/j2k/test/JavaToKotlinConverterTestGenerated.java index 97953f10520..a968d0189bc 100644 --- a/j2k/tests/test/org/jetbrains/jet/j2k/test/JavaToKotlinConverterTestGenerated.java +++ b/j2k/tests/test/org/jetbrains/jet/j2k/test/JavaToKotlinConverterTestGenerated.java @@ -248,6 +248,11 @@ public class JavaToKotlinConverterTestGenerated extends AbstractJavaToKotlinConv doTest("j2k/tests/testData/ast/assertStatement/withStringDetail.java"); } + @TestMetadata("withStringDetail2.java") + public void testWithStringDetail2() throws Exception { + doTest("j2k/tests/testData/ast/assertStatement/withStringDetail2.java"); + } + } @TestMetadata("j2k/tests/testData/ast/assignmentExpression") diff --git a/j2k/tests/testData/ast/assertStatement/withStringDetail.kt b/j2k/tests/testData/ast/assertStatement/withStringDetail.kt index dbf44bd5eb8..720ccd99f52 100644 --- a/j2k/tests/testData/ast/assertStatement/withStringDetail.kt +++ b/j2k/tests/testData/ast/assertStatement/withStringDetail.kt @@ -1 +1 @@ -assert(true) { "string details" } \ No newline at end of file +assert(true, "string details") \ No newline at end of file diff --git a/j2k/tests/testData/ast/assertStatement/withStringDetail2.java b/j2k/tests/testData/ast/assertStatement/withStringDetail2.java new file mode 100644 index 00000000000..c8b9e98482f --- /dev/null +++ b/j2k/tests/testData/ast/assertStatement/withStringDetail2.java @@ -0,0 +1,2 @@ +//statement +assert true : "string details:" + x; \ No newline at end of file diff --git a/j2k/tests/testData/ast/assertStatement/withStringDetail2.kt b/j2k/tests/testData/ast/assertStatement/withStringDetail2.kt new file mode 100644 index 00000000000..97aa2c8f30f --- /dev/null +++ b/j2k/tests/testData/ast/assertStatement/withStringDetail2.kt @@ -0,0 +1 @@ +assert(true) { "string details:" + x } \ No newline at end of file