FIR/UAST: commonize safe qualified expression

This commit is contained in:
Jinseong Jeon
2021-06-08 23:40:20 -07:00
committed by TeamCityServer
parent 2999d0bd4b
commit fa613a32b2
5 changed files with 18 additions and 21 deletions

View File

@@ -1,17 +1,6 @@
/*
* 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.
* 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
@@ -30,8 +19,8 @@ class KotlinUSafeQualifiedExpression(
givenParent: UElement?
) : KotlinAbstractUExpression(givenParent), UQualifiedReferenceExpression, UMultiResolvable,
KotlinUElementWithType, KotlinEvaluatableUElement {
override val receiver by lz { KotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
override val selector by lz { KotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
override val receiver by lz { baseResolveProviderService.baseKotlinConverter.convertOrEmpty(sourcePsi.receiverExpression, this) }
override val selector by lz { baseResolveProviderService.baseKotlinConverter.convertOrEmpty(sourcePsi.selectorExpression, this) }
override val accessType = KotlinQualifiedExpressionAccessTypes.SAFE
override val resolvedName: String?

View File

@@ -312,6 +312,7 @@ internal object FirKotlinConverter : BaseKotlinConverter {
is KtCallableReferenceExpression -> expr<UCallableReferenceExpression>(build(::KotlinUCallableReferenceExpression))
is KtClassLiteralExpression -> expr<UClassLiteralExpression>(build(::KotlinUClassLiteralExpression))
is KtDotQualifiedExpression -> expr<UQualifiedReferenceExpression>(build(::KotlinUQualifiedReferenceExpression))
is KtSafeQualifiedExpression -> expr<UQualifiedReferenceExpression>(build(::KotlinUSafeQualifiedExpression))
is KtSimpleNameExpression -> expr<USimpleNameReferenceExpression>(build(::FirKotlinUSimpleReferenceExpression))
else -> expr<UExpression>(build(::UnknownKotlinExpression))

View File

@@ -1,4 +1,5 @@
fun foo(x: Unresolved) {
fun foo(x: Unresolved?) {
x?.prop
}
class A(

View File

@@ -1,9 +1,12 @@
UFile (package = ) [public final class UnresolvedKt {...]
UClass (name = UnresolvedKt) [public final class UnresolvedKt {...}]
UMethod (name = foo) [public static final fun foo(@org.jetbrains.annotations.NotNull x: error.NonExistentClass) : void {...}]
UParameter (name = x) [@org.jetbrains.annotations.NotNull var x: error.NonExistentClass]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]
UBlockExpression [{...}] : PsiType:void
UMethod (name = foo) [public static final fun foo(@org.jetbrains.annotations.Nullable x: error.NonExistentClass) : void {...}]
UParameter (name = x) [@org.jetbrains.annotations.Nullable var x: error.NonExistentClass]
UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable]
UBlockExpression [{...}] : PsiType:<ErrorType>
UQualifiedReferenceExpression [x?.prop] : PsiType:<ErrorType>
USimpleNameReferenceExpression (identifier = x) [x] : PsiType:<ErrorType>
USimpleNameReferenceExpression (identifier = prop) [prop] : PsiType:<ErrorType>
UClass (name = A) [public final class A : <ErrorType> {...}]
UField (name = prop) [@org.jetbrains.annotations.NotNull private final var prop: error.NonExistentClass]
UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull]

View File

@@ -2,7 +2,10 @@ UFile (package = ) [public final class UnresolvedKt {...]
UClass (name = UnresolvedKt) [public final class UnresolvedKt {...}]
UMethod (name = foo) [public static final fun foo(x: error.NonExistentClass) : void {...}]
UParameter (name = x) [var x: error.NonExistentClass]
UBlockExpression [{...}] : PsiType:Unit
UBlockExpression [{...}] : PsiType:NonExistentClass
UQualifiedReferenceExpression [x?.prop] : PsiType:NonExistentClass
USimpleNameReferenceExpression (identifier = x) [x] : PsiType:NonExistentClass
USimpleNameReferenceExpression (identifier = prop) [prop] : PsiType:NonExistentClass
UClass (name = A) [public final class A : error.NonExistentClass {...}]
UField (name = prop) [private final var prop: error.NonExistentClass]
UMethod (name = A) [public fun A(prop: error.NonExistentClass) {...}]