[Analysis API] KtPsiTypeProvider: disable for non-jvm platforms
Otherwise, it will throw exception like: ``` IllegalStateException: No 'FirJvmTypeMapper' ``` Anyway, PsiType is JVM conception, so it is not supposed to be used outside the JVM platform ^KT-60318
This commit is contained in:
committed by
Space Team
parent
7fa7d8ea8d
commit
7a24d0ee82
+5
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,8 @@ import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.load.kotlin.getOptimalModeForReturnType
|
||||
import org.jetbrains.kotlin.load.kotlin.getOptimalModeForValueParameter
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.platform.has
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import java.text.StringCharacterIterator
|
||||
@@ -51,6 +53,8 @@ internal class KtFe10PsiTypeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
if (!analysisSession.useSiteModule.platform.has<JvmPlatform>()) return null
|
||||
|
||||
return asPsiTypeElement(simplifyType(kotlinType), useSitePosition, mode.toTypeMappingMode(type, isAnnotationMethod))
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.descriptors.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.jvmTypeMapper
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.moduleData
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
@@ -39,6 +40,8 @@ import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.load.kotlin.getOptimalModeForReturnType
|
||||
import org.jetbrains.kotlin.load.kotlin.getOptimalModeForValueParameter
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.platform.has
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
@@ -64,6 +67,8 @@ internal class KtFirPsiTypeProvider(
|
||||
}
|
||||
}
|
||||
|
||||
if (!rootModuleSession.moduleData.platform.has<JvmPlatform>()) return null
|
||||
|
||||
return coneType.simplifyType(rootModuleSession, useSitePosition)
|
||||
.asPsiTypeElement(rootModuleSession, mode.toTypeMappingMode(type, isAnnotationMethod), useSitePosition, allowErrorTypes)
|
||||
}
|
||||
|
||||
+7
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,9 @@ public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
* A client can handle such case in its own way. For instance,
|
||||
* * UAST will return `UastErrorType` as a default error type.
|
||||
*
|
||||
* If [allowErrorTypes] set to true then erroneous types will be replaced with `error.NonExistentClass` type
|
||||
* If [allowErrorTypes] set to true then erroneous types will be replaced with `error.NonExistentClass` type.
|
||||
*
|
||||
* Note: [PsiTypeElement] is JVM conception, so this method will return `null` for non-JVM platforms.
|
||||
*/
|
||||
public fun KtType.asPsiTypeElement(
|
||||
useSitePosition: PsiElement,
|
||||
@@ -55,7 +57,9 @@ public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
*
|
||||
* This simply unwraps [PsiTypeElement] returned from [asPsiTypeElement].
|
||||
* Use this version if type annotation is not required. Otherwise, use [asPsiTypeElement] to get [PsiTypeElement] as an owner of
|
||||
* annotations on [PsiType] and annotate the resulting [PsiType] with proper [PsiAnnotation].
|
||||
* annotations on [PsiType] and annotate the resulting [PsiType] with proper [PsiAnnotation][com.intellij.psi.PsiAnnotation].
|
||||
*
|
||||
* Note: [PsiType] is JVM conception, so this method will return `null` for non-JVM platforms.
|
||||
*/
|
||||
public fun KtType.asPsiType(
|
||||
useSitePosition: PsiElement,
|
||||
|
||||
Reference in New Issue
Block a user