diff --git a/plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUParenthesizedExpression.kt b/plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUParenthesizedExpression.kt new file mode 100644 index 00000000000..a5340ca9396 --- /dev/null +++ b/plugins/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUParenthesizedExpression.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.uast.kotlin + +import org.jetbrains.kotlin.psi.KtParenthesizedExpression +import org.jetbrains.uast.UElement +import org.jetbrains.uast.UParenthesizedExpression + +class KotlinUParenthesizedExpression( + override val sourcePsi: KtParenthesizedExpression, + givenParent: UElement? +) : KotlinAbstractUExpression(givenParent), UParenthesizedExpression, KotlinUElementWithType { + override val expression by lz { + baseResolveProviderService.baseKotlinConverter.convertOrEmpty(sourcePsi.expression, this) + } +} diff --git a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinConverter.kt b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinConverter.kt index b7b4b3f1689..7b136ed88c3 100644 --- a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinConverter.kt +++ b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinConverter.kt @@ -270,6 +270,7 @@ internal object FirKotlinConverter : BaseKotlinConverter { is KtConstantExpression -> expr(build(::KotlinULiteralExpression)) is KtLabeledExpression -> expr(build(::KotlinULabeledExpression)) + is KtParenthesizedExpression -> expr(build(::KotlinUParenthesizedExpression)) is KtBlockExpression -> expr { // TODO: differentiate lambda diff --git a/plugins/uast-kotlin-fir/testData/declaration/if.kt b/plugins/uast-kotlin-fir/testData/declaration/if.kt index 3001a57aa17..6b2365fcbd8 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/if.kt +++ b/plugins/uast-kotlin-fir/testData/declaration/if.kt @@ -1,6 +1,6 @@ fun test(b: Boolean): Any { return if (b) - 42 + (4 * 10 + 2) else "42" } diff --git a/plugins/uast-kotlin-fir/testData/declaration/if.log.fe10.txt b/plugins/uast-kotlin-fir/testData/declaration/if.log.fe10.txt index 4aa6a03392c..b325fb59697 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/if.log.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/declaration/if.log.fe10.txt @@ -7,5 +7,10 @@ UFile (package = ) UReturnExpression UIfExpression USimpleNameReferenceExpression (identifier = b) - ULiteralExpression (value = 42) + UParenthesizedExpression + UBinaryExpression (operator = +) + UBinaryExpression (operator = *) + ULiteralExpression (value = 4) + ULiteralExpression (value = 10) + ULiteralExpression (value = 2) ULiteralExpression (value = "42") diff --git a/plugins/uast-kotlin-fir/testData/declaration/if.log.fir.txt b/plugins/uast-kotlin-fir/testData/declaration/if.log.fir.txt index 12ffc444efd..8f7b3a66556 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/if.log.fir.txt +++ b/plugins/uast-kotlin-fir/testData/declaration/if.log.fir.txt @@ -6,5 +6,6 @@ UFile (package = ) UReturnExpression UIfExpression [!] UnknownKotlinExpression (REFERENCE_EXPRESSION) - ULiteralExpression (value = "not-yet-compile-time-constant") + UParenthesizedExpression + [!] UnknownKotlinExpression (BINARY_EXPRESSION) ULiteralExpression (value = "42") diff --git a/plugins/uast-kotlin-fir/testData/declaration/if.render.fe10.txt b/plugins/uast-kotlin-fir/testData/declaration/if.render.fe10.txt index b57d738e133..3e1784d5d21 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/if.render.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/declaration/if.render.fe10.txt @@ -1,5 +1,5 @@ public final class IfKt { public static final fun test(@org.jetbrains.annotations.NotNull b: boolean) : java.lang.Object { - return if (b) 42 else "42" + return if (b) (4 * 10 + 2) else "42" } } diff --git a/plugins/uast-kotlin-fir/testData/declaration/if.render.fir.txt b/plugins/uast-kotlin-fir/testData/declaration/if.render.fir.txt index 22b339e31e5..5ae99f1a16c 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/if.render.fir.txt +++ b/plugins/uast-kotlin-fir/testData/declaration/if.render.fir.txt @@ -1,5 +1,5 @@ public final class IfKt { public static final fun test(b: boolean) : java.lang.Object { - return if ([!] UnknownKotlinExpression (REFERENCE_EXPRESSION)) "not-yet-compile-time-constant" else "42" + return if ([!] UnknownKotlinExpression (REFERENCE_EXPRESSION)) ([!] UnknownKotlinExpression (BINARY_EXPRESSION)) else "42" } } diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUParenthesizedExpression.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUParenthesizedExpression.kt deleted file mode 100644 index bb7a0e53776..00000000000 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/expressions/KotlinUParenthesizedExpression.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010-2016 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.uast.kotlin - -import org.jetbrains.kotlin.psi.KtParenthesizedExpression -import org.jetbrains.uast.UElement -import org.jetbrains.uast.UParenthesizedExpression - -class KotlinUParenthesizedExpression( - override val sourcePsi: KtParenthesizedExpression, - givenParent: UElement? -) : KotlinAbstractUExpression(givenParent), UParenthesizedExpression, KotlinUElementWithType { - override val expression by lz { KotlinConverter.convertOrEmpty(sourcePsi.expression, this) } -} \ No newline at end of file