FIR/UAST: commonize parenthesized expression

This commit is contained in:
Jinseong Jeon
2021-05-27 00:46:18 -07:00
committed by Ilya Kirillov
parent c089b8ed04
commit c21fce6cbc
8 changed files with 31 additions and 33 deletions
@@ -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)
}
}
@@ -270,6 +270,7 @@ internal object FirKotlinConverter : BaseKotlinConverter {
is KtConstantExpression -> expr<ULiteralExpression>(build(::KotlinULiteralExpression))
is KtLabeledExpression -> expr<ULabeledExpression>(build(::KotlinULabeledExpression))
is KtParenthesizedExpression -> expr<UParenthesizedExpression>(build(::KotlinUParenthesizedExpression))
is KtBlockExpression -> expr<UBlockExpression> {
// TODO: differentiate lambda
+1 -1
View File
@@ -1,6 +1,6 @@
fun test(b: Boolean): Any {
return if (b)
42
(4 * 10 + 2)
else
"42"
}
@@ -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")
@@ -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")
@@ -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"
}
}
@@ -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"
}
}
@@ -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) }
}