From 47ede5bdc8406781981daffe3a8b826962292c13 Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Tue, 1 Jun 2021 10:59:07 -0700 Subject: [PATCH] FIR IDE/UAST: get PsiType from KtTypeReference --- .../generators/tests/idea/GenerateTests.kt | 8 +++++ idea/idea-frontend-api/build.gradle.kts | 1 + .../frontend/api/components/KtTypeProvider.kt | 10 +++++- .../KtFirAnalysisSessionComponent.kt | 6 ++++ .../components/KtFirExpressionTypeProvider.kt | 4 --- .../api/fir/components/KtFirTypeProvider.kt | 16 ++++++++- .../FirKotlinUastResolveProviderService.kt | 5 +-- .../ConstructorDelegate.render.fir.txt | 4 +-- .../DefaultImpls.render.fir.txt | 2 +- .../legacyRenderLog/SuperCalls.render.fir.txt | 6 ++-- .../ConstructorDelegate.types.fir.txt | 4 +-- .../legacyTypes/DefaultImpls.types.fir.txt | 2 +- .../legacyTypes/SuperCalls.types.fir.txt | 6 ++-- .../ConstructorDelegate.values.fir.txt | 4 +-- .../legacyValues/DefaultImpls.values.fir.txt | 2 +- .../legacyValues/SuperCalls.values.fir.txt | 6 ++-- .../testData/type/unresolved.kt | 11 ++++++ .../testData/type/unresolved.types.fe10.txt | 20 +++++++++++ .../testData/type/unresolved.types.fir.txt | 12 +++++++ .../kotlin/FE1UastTypesTestGenerated.java | 36 +++++++++++++++++++ .../kotlin/FirUastTypesTestGenerated.java | 36 +++++++++++++++++++ 21 files changed, 175 insertions(+), 26 deletions(-) create mode 100644 plugins/uast-kotlin-fir/testData/type/unresolved.kt create mode 100644 plugins/uast-kotlin-fir/testData/type/unresolved.types.fe10.txt create mode 100644 plugins/uast-kotlin-fir/testData/type/unresolved.types.fir.txt create mode 100644 plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FE1UastTypesTestGenerated.java create mode 100644 plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FirUastTypesTestGenerated.java diff --git a/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt b/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt index d0e5a8ce9bc..0aad1d5426b 100644 --- a/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt +++ b/generators/idea-generator/tests/org/jetbrains/kotlin/generators/tests/idea/GenerateTests.kt @@ -1660,6 +1660,10 @@ fun main(args: Array) { testClass { model("declaration") } + + testClass { + model("type") + } } testGroup("plugins/uast-kotlin-fir/tests", "plugins/uast-kotlin/testData") { @@ -1684,6 +1688,10 @@ fun main(args: Array) { testClass { model("declaration") } + + testClass { + model("type") + } } testGroup("plugins/uast-kotlin-fir/tests", "plugins/uast-kotlin/testData") { diff --git a/idea/idea-frontend-api/build.gradle.kts b/idea/idea-frontend-api/build.gradle.kts index 1bf03ccc6e5..9beaa6fe6b3 100644 --- a/idea/idea-frontend-api/build.gradle.kts +++ b/idea/idea-frontend-api/build.gradle.kts @@ -9,6 +9,7 @@ dependencies { compileOnly(project(":compiler:psi")) compileOnly(project(":compiler:frontend")) compileOnly(project(":core:compiler.common")) + compileOnly(project(":core:compiler.common.jvm")) compileOnly(project(":idea:idea-frontend-independent")) compileOnly(intellijCoreDep()) compileOnly(intellijDep()) diff --git a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtTypeProvider.kt b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtTypeProvider.kt index 1928f951801..deed8a39012 100644 --- a/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtTypeProvider.kt +++ b/idea/idea-frontend-api/src/org/jetbrains/kotlin/idea/frontend/api/components/KtTypeProvider.kt @@ -5,10 +5,13 @@ package org.jetbrains.kotlin.idea.frontend.api.components +import com.intellij.psi.PsiType import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner import org.jetbrains.kotlin.idea.frontend.api.symbols.KtNamedClassOrObjectSymbol import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeNullability +import org.jetbrains.kotlin.load.kotlin.TypeMappingMode +import org.jetbrains.kotlin.psi.KtTypeReference abstract class KtTypeProvider : KtAnalysisSessionComponent() { abstract val builtinTypes: KtBuiltinTypes @@ -17,6 +20,8 @@ abstract class KtTypeProvider : KtAnalysisSessionComponent() { abstract fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType + abstract fun getPsiType(ktTypeReference: KtTypeReference, mode: TypeMappingMode): PsiType + abstract fun withNullability(type: KtType, newNullability: KtTypeNullability): KtType } @@ -36,6 +41,9 @@ interface KtTypeProviderMixIn : KtAnalysisSessionMixIn { fun KtNamedClassOrObjectSymbol.buildSelfClassType(): KtType = analysisSession.typeProvider.buildSelfClassType(this) + fun KtTypeReference.getPsiType(mode: TypeMappingMode = TypeMappingMode.DEFAULT): PsiType = + analysisSession.typeProvider.getPsiType(this, mode) + fun KtType.withNullability(newNullability: KtTypeNullability): KtType = analysisSession.typeProvider.withNullability(this, newNullability) } @@ -60,4 +68,4 @@ abstract class KtBuiltinTypes : ValidityTokenOwner { abstract val NULLABLE_ANY: KtType abstract val NULLABLE_NOTHING: KtType -} \ No newline at end of file +} diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirAnalysisSessionComponent.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirAnalysisSessionComponent.kt index 95d4bc6933c..c2159de12e1 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirAnalysisSessionComponent.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirAnalysisSessionComponent.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.components +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic @@ -14,9 +15,11 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext +import org.jetbrains.kotlin.idea.asJava.asPsiType import org.jetbrains.kotlin.idea.frontend.api.diagnostics.KtDiagnosticWithPsi import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession import org.jetbrains.kotlin.idea.frontend.api.fir.diagnostics.KT_DIAGNOSTIC_CONVERTER +import org.jetbrains.kotlin.load.kotlin.TypeMappingMode internal interface KtFirAnalysisSessionComponent { val analysisSession: KtFirAnalysisSession @@ -27,6 +30,9 @@ internal interface KtFirAnalysisSessionComponent { fun ConeKotlinType.asKtType() = analysisSession.firSymbolBuilder.typeBuilder.buildKtType(this) + fun ConeKotlinType.asPsiType(mode: TypeMappingMode, psiContext: PsiElement) = + asPsiType(rootModuleSession, analysisSession.firResolveState, mode, psiContext) + fun FirPsiDiagnostic<*>.asKtDiagnostic(): KtDiagnosticWithPsi<*> = KT_DIAGNOSTIC_CONVERTER.convert(analysisSession, this as FirDiagnostic<*>) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt index a87d2af142e..755a1387e8d 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirExpressionTypeProvider.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.coneType -import org.jetbrains.kotlin.idea.asJava.asPsiType import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFirOfType import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFirSafe @@ -63,9 +62,6 @@ internal class KtFirExpressionTypeProvider( } } - private fun ConeKotlinType.asPsiType(mode: TypeMappingMode, psiContext: PsiElement) = - asPsiType(rootModuleSession, analysisSession.firResolveState, mode, psiContext) - private fun FirNamedReference.getReferencedElementType(): ConeKotlinType { val symbols = when (this) { is FirResolvedNamedReference -> listOf(resolvedSymbol) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirTypeProvider.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirTypeProvider.kt index 33d2d050f8e..fc2fb1c34dd 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirTypeProvider.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/components/KtFirTypeProvider.kt @@ -5,11 +5,15 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.components +import com.intellij.psi.PsiType import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.typeContext +import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef +import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.withNullability +import org.jetbrains.kotlin.idea.fir.low.level.api.api.getOrBuildFir import org.jetbrains.kotlin.idea.frontend.api.components.KtBuiltinTypes import org.jetbrains.kotlin.idea.frontend.api.components.KtTypeProvider import org.jetbrains.kotlin.idea.frontend.api.fir.KtFirAnalysisSession @@ -21,6 +25,9 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtNamedClassOrObjectSymbol import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken import org.jetbrains.kotlin.idea.frontend.api.types.KtType import org.jetbrains.kotlin.idea.frontend.api.types.KtTypeNullability +import org.jetbrains.kotlin.idea.frontend.api.withValidityAssertion +import org.jetbrains.kotlin.load.kotlin.TypeMappingMode +import org.jetbrains.kotlin.psi.KtTypeReference internal class KtFirTypeProvider( override val analysisSession: KtFirAnalysisSession, @@ -39,7 +46,6 @@ internal class KtFirTypeProvider( return approximatedConeType?.asKtType() } - override fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType { require(symbol is KtFirNamedClassOrObjectSymbol) val type = symbol.firRef.withFir(FirResolvePhase.SUPER_TYPES) { firClass -> @@ -52,6 +58,14 @@ internal class KtFirTypeProvider( return type.asKtType() } + override fun getPsiType(ktTypeReference: KtTypeReference, mode: TypeMappingMode): PsiType = withValidityAssertion { + when (val fir = ktTypeReference.getOrBuildFir(firResolveState)) { + // NB: [FirErrorTypeRef] is a subtype of [FirResolvedTypeRef], and the error type in it will be properly handled by [asPsiType]. + is FirResolvedTypeRef -> fir.coneType.asPsiType(mode, ktTypeReference) + else -> error("Unexpected ${fir::class}") + } + } + override fun withNullability(type: KtType, newNullability: KtTypeNullability): KtType { require(type is KtFirType) return type.coneType.withNullability(newNullability.toConeNullability(), rootModuleSession.typeContext).asKtType() diff --git a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt index 11972002e10..6bfdde6af0d 100644 --- a/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt +++ b/plugins/uast-kotlin-fir/src/org/jetbrains/uast/kotlin/FirKotlinUastResolveProviderService.kt @@ -38,8 +38,9 @@ interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderSer } override fun resolveToType(ktTypeReference: KtTypeReference, source: UElement): PsiType? { - // TODO: use type conversions in firLightUtils.kt - return PsiType.NULL + analyseWithCustomToken(ktTypeReference, AlwaysAccessibleValidityTokenFactory) { + return ktTypeReference.getPsiType(TypeMappingMode.DEFAULT_UAST) + } } override fun getExpressionType(uExpression: UExpression): PsiType? { diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/ConstructorDelegate.render.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/ConstructorDelegate.render.fir.txt index 8659baf4145..ec03557b979 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/ConstructorDelegate.render.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/ConstructorDelegate.render.fir.txt @@ -8,7 +8,7 @@ public abstract interface Base { public abstract fun print() : void = UastEmptyExpression } -public final class BaseImpl : null { +public final class BaseImpl : Base { private final var x: int public fun BaseImpl(x: int) = UastEmptyExpression public final fun getX() : int = UastEmptyExpression @@ -17,6 +17,6 @@ public final class BaseImpl : null { } } -public final class Derived : null, null { +public final class Derived : Base, java.lang.CharSequence { public fun Derived(b: Base) = UastEmptyExpression } diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/DefaultImpls.render.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/DefaultImpls.render.fir.txt index 7e5cc58cb97..2e31f5da83f 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/DefaultImpls.render.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/DefaultImpls.render.fir.txt @@ -4,6 +4,6 @@ public abstract interface Foo { } } -public final class Baz : null { +public final class Baz : Foo { public fun Baz() = UastEmptyExpression } diff --git a/plugins/uast-kotlin-fir/testData/legacyRenderLog/SuperCalls.render.fir.txt b/plugins/uast-kotlin-fir/testData/legacyRenderLog/SuperCalls.render.fir.txt index 4a96904de0d..e9324c42781 100644 --- a/plugins/uast-kotlin-fir/testData/legacyRenderLog/SuperCalls.render.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyRenderLog/SuperCalls.render.fir.txt @@ -14,11 +14,11 @@ public class A { } } -public final class B : null { +public final class B : A { public fun B(param: java.lang.String) = UastEmptyExpression } -public final class C : null { +public final class C : A { public fun C(p: java.lang.String) = UastEmptyExpression public fun C(i: int) { [!] UnknownKotlinExpression (CALL_EXPRESSION) @@ -28,7 +28,7 @@ public final class C : null { } } -public final class O : null { +public final class O : A { public static final var INSTANCE: O private fun O() = UastEmptyExpression } diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/ConstructorDelegate.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/ConstructorDelegate.types.fir.txt index ba70c1c636a..0cff6eb084a 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/ConstructorDelegate.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/ConstructorDelegate.types.fir.txt @@ -7,7 +7,7 @@ UFile (package = ) [public final class ConstructorDelegateKt {...] [!] UnknownKotlinExpression (CALL_EXPRESSION) [[!] UnknownKotlinExpression (CALL_EXPRESSION)] UClass (name = Base) [public abstract interface Base {...}] UMethod (name = print) [public abstract fun print() : void = UastEmptyExpression] - UClass (name = BaseImpl) [public final class BaseImpl : null {...}] + UClass (name = BaseImpl) [public final class BaseImpl : Base {...}] UField (name = x) [private final var x: int] UMethod (name = BaseImpl) [public fun BaseImpl(x: int) = UastEmptyExpression] UParameter (name = x) [var x: int] @@ -15,6 +15,6 @@ UFile (package = ) [public final class ConstructorDelegateKt {...] UMethod (name = print) [public fun print() : void {...}] UBlockExpression [{...}] : PsiType:Unit [!] UnknownKotlinExpression (CALL_EXPRESSION) [[!] UnknownKotlinExpression (CALL_EXPRESSION)] - UClass (name = Derived) [public final class Derived : null, null {...}] + UClass (name = Derived) [public final class Derived : Base, java.lang.CharSequence {...}] UMethod (name = Derived) [public fun Derived(b: Base) = UastEmptyExpression] UParameter (name = b) [var b: Base] diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/DefaultImpls.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/DefaultImpls.types.fir.txt index 5983478af39..ba6fb29b6c5 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/DefaultImpls.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/DefaultImpls.types.fir.txt @@ -4,5 +4,5 @@ UFile (package = ) [public abstract interface Foo {...] UBlockExpression [{...}] UReturnExpression [return "Hello!"] ULiteralExpression (value = "Hello!") ["Hello!"] : PsiType:String - UClass (name = Baz) [public final class Baz : null {...}] + UClass (name = Baz) [public final class Baz : Foo {...}] UMethod (name = Baz) [public fun Baz() = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyTypes/SuperCalls.types.fir.txt b/plugins/uast-kotlin-fir/testData/legacyTypes/SuperCalls.types.fir.txt index a5c7941d0f1..b59961ac98a 100644 --- a/plugins/uast-kotlin-fir/testData/legacyTypes/SuperCalls.types.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyTypes/SuperCalls.types.fir.txt @@ -16,10 +16,10 @@ UFile (package = ) [public final class SuperCallsKt {...] UMethod (name = foo) [public fun foo(a: long) : void {...}] UParameter (name = a) [var a: long] UBlockExpression [{...}] : PsiType:Unit - UClass (name = B) [public final class B : null {...}] + UClass (name = B) [public final class B : A {...}] UMethod (name = B) [public fun B(param: java.lang.String) = UastEmptyExpression] UParameter (name = param) [var param: java.lang.String] - UClass (name = C) [public final class C : null {...}] + UClass (name = C) [public final class C : A {...}] UMethod (name = C) [public fun C(p: java.lang.String) = UastEmptyExpression] UParameter (name = p) [var p: java.lang.String] UMethod (name = C) [public fun C(i: int) {...}] @@ -30,6 +30,6 @@ UFile (package = ) [public final class SuperCallsKt {...] UParameter (name = a) [var a: long] UBlockExpression [{...}] : PsiType:Unit [!] UnknownKotlinExpression (DOT_QUALIFIED_EXPRESSION) [[!] UnknownKotlinExpression (DOT_QUALIFIED_EXPRESSION)] - UClass (name = O) [public final class O : null {...}] + UClass (name = O) [public final class O : A {...}] UField (name = INSTANCE) [public static final var INSTANCE: O] UMethod (name = O) [private fun O() = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/ConstructorDelegate.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/ConstructorDelegate.values.fir.txt index 91ef83e9444..84da5f592ab 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/ConstructorDelegate.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/ConstructorDelegate.values.fir.txt @@ -7,7 +7,7 @@ UFile (package = ) [public final class ConstructorDelegateKt {...] [!] UnknownKotlinExpression (CALL_EXPRESSION) [[!] UnknownKotlinExpression (CALL_EXPRESSION)] = Undetermined UClass (name = Base) [public abstract interface Base {...}] UMethod (name = print) [public abstract fun print() : void = UastEmptyExpression] - UClass (name = BaseImpl) [public final class BaseImpl : null {...}] + UClass (name = BaseImpl) [public final class BaseImpl : Base {...}] UField (name = x) [private final var x: int] UMethod (name = BaseImpl) [public fun BaseImpl(x: int) = UastEmptyExpression] UParameter (name = x) [var x: int] @@ -15,6 +15,6 @@ UFile (package = ) [public final class ConstructorDelegateKt {...] UMethod (name = print) [public fun print() : void {...}] UBlockExpression [{...}] = Undetermined [!] UnknownKotlinExpression (CALL_EXPRESSION) [[!] UnknownKotlinExpression (CALL_EXPRESSION)] = Undetermined - UClass (name = Derived) [public final class Derived : null, null {...}] + UClass (name = Derived) [public final class Derived : Base, java.lang.CharSequence {...}] UMethod (name = Derived) [public fun Derived(b: Base) = UastEmptyExpression] UParameter (name = b) [var b: Base] diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/DefaultImpls.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/DefaultImpls.values.fir.txt index 3a8acc0ea8e..0a15a6930a5 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/DefaultImpls.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/DefaultImpls.values.fir.txt @@ -4,5 +4,5 @@ UFile (package = ) [public abstract interface Foo {...] UBlockExpression [{...}] = Nothing UReturnExpression [return "Hello!"] = Nothing ULiteralExpression (value = "Hello!") ["Hello!"] = "Hello!" - UClass (name = Baz) [public final class Baz : null {...}] + UClass (name = Baz) [public final class Baz : Foo {...}] UMethod (name = Baz) [public fun Baz() = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/legacyValues/SuperCalls.values.fir.txt b/plugins/uast-kotlin-fir/testData/legacyValues/SuperCalls.values.fir.txt index f3cfa76ea7b..6aefb21d6f9 100644 --- a/plugins/uast-kotlin-fir/testData/legacyValues/SuperCalls.values.fir.txt +++ b/plugins/uast-kotlin-fir/testData/legacyValues/SuperCalls.values.fir.txt @@ -16,10 +16,10 @@ UFile (package = ) [public final class SuperCallsKt {...] UMethod (name = foo) [public fun foo(a: long) : void {...}] UParameter (name = a) [var a: long] UBlockExpression [{...}] = Undetermined - UClass (name = B) [public final class B : null {...}] + UClass (name = B) [public final class B : A {...}] UMethod (name = B) [public fun B(param: java.lang.String) = UastEmptyExpression] UParameter (name = param) [var param: java.lang.String] - UClass (name = C) [public final class C : null {...}] + UClass (name = C) [public final class C : A {...}] UMethod (name = C) [public fun C(p: java.lang.String) = UastEmptyExpression] UParameter (name = p) [var p: java.lang.String] UMethod (name = C) [public fun C(i: int) {...}] @@ -30,6 +30,6 @@ UFile (package = ) [public final class SuperCallsKt {...] UParameter (name = a) [var a: long] UBlockExpression [{...}] = Undetermined [!] UnknownKotlinExpression (DOT_QUALIFIED_EXPRESSION) [[!] UnknownKotlinExpression (DOT_QUALIFIED_EXPRESSION)] = Undetermined - UClass (name = O) [public final class O : null {...}] + UClass (name = O) [public final class O : A {...}] UField (name = INSTANCE) [public static final var INSTANCE: O] UMethod (name = O) [private fun O() = UastEmptyExpression] diff --git a/plugins/uast-kotlin-fir/testData/type/unresolved.kt b/plugins/uast-kotlin-fir/testData/type/unresolved.kt new file mode 100644 index 00000000000..aefbb3afc8b --- /dev/null +++ b/plugins/uast-kotlin-fir/testData/type/unresolved.kt @@ -0,0 +1,11 @@ +fun foo(x: Unresolved) { +} + +class A( + val prop: Unresolved +) : UnresolvedBase(prop) { + + override fun bar() : UnresolvedBase { + } + +} diff --git a/plugins/uast-kotlin-fir/testData/type/unresolved.types.fe10.txt b/plugins/uast-kotlin-fir/testData/type/unresolved.types.fe10.txt new file mode 100644 index 00000000000..cffb9557688 --- /dev/null +++ b/plugins/uast-kotlin-fir/testData/type/unresolved.types.fe10.txt @@ -0,0 +1,20 @@ +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 + UClass (name = A) [public final class A : {...}] + UField (name = prop) [@org.jetbrains.annotations.NotNull private final var prop: error.NonExistentClass] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UMethod (name = bar) [public fun bar() : error.NonExistentClass {...}] + UBlockExpression [{...}] : PsiType:void + UMethod (name = getProp) [public final fun getProp() : error.NonExistentClass = UastEmptyExpression] + UMethod (name = A) [public fun A(@org.jetbrains.annotations.NotNull prop: error.NonExistentClass) {...}] + UParameter (name = prop) [@org.jetbrains.annotations.NotNull var prop: error.NonExistentClass] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UBlockExpression [{...}] + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [(prop)] + UIdentifier (Identifier (UnresolvedBase)) [UIdentifier (Identifier (UnresolvedBase))] + USimpleNameReferenceExpression (identifier = , resolvesTo = null) [] + USimpleNameReferenceExpression (identifier = prop) [prop] : PsiType: diff --git a/plugins/uast-kotlin-fir/testData/type/unresolved.types.fir.txt b/plugins/uast-kotlin-fir/testData/type/unresolved.types.fir.txt new file mode 100644 index 00000000000..fa306edd8bd --- /dev/null +++ b/plugins/uast-kotlin-fir/testData/type/unresolved.types.fir.txt @@ -0,0 +1,12 @@ +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 + 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) = UastEmptyExpression] + UParameter (name = prop) [var prop: error.NonExistentClass] + UMethod (name = getProp) [public final fun getProp() : error.NonExistentClass = UastEmptyExpression] + UMethod (name = bar) [public fun bar() : error.NonExistentClass {...}] + UBlockExpression [{...}] : PsiType:Unit diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FE1UastTypesTestGenerated.java b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FE1UastTypesTestGenerated.java new file mode 100644 index 00000000000..bd7a2d71a17 --- /dev/null +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FE1UastTypesTestGenerated.java @@ -0,0 +1,36 @@ +/* + * 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.test.kotlin; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("plugins/uast-kotlin-fir/testData/type") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class FE1UastTypesTestGenerated extends AbstractFE1UastTypesTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInType() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/uast-kotlin-fir/testData/type"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("unresolved.kt") + public void testUnresolved() throws Exception { + runTest("plugins/uast-kotlin-fir/testData/type/unresolved.kt"); + } +} diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FirUastTypesTestGenerated.java b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FirUastTypesTestGenerated.java new file mode 100644 index 00000000000..53232b18252 --- /dev/null +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/test/kotlin/FirUastTypesTestGenerated.java @@ -0,0 +1,36 @@ +/* + * 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.test.kotlin; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("plugins/uast-kotlin-fir/testData/type") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class FirUastTypesTestGenerated extends AbstractFirUastTypesTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInType() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/uast-kotlin-fir/testData/type"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("unresolved.kt") + public void testUnresolved() throws Exception { + runTest("plugins/uast-kotlin-fir/testData/type/unresolved.kt"); + } +}