FIR LC: approximate local type only if it's necessary and out of scope
This commit is contained in:
committed by
Roman Golyshev
parent
9ed2c9d371
commit
9524825662
+13
-5
@@ -11,21 +11,29 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
|
||||
public abstract class KtPsiTypeProvider : KtAnalysisSessionComponent() {
|
||||
public abstract fun asPsiType(type: KtType, context: PsiElement, mode: TypeMappingMode): PsiType?
|
||||
public abstract fun asPsiType(type: KtType, useSitePosition: PsiElement, mode: TypeMappingMode): PsiType?
|
||||
}
|
||||
|
||||
public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||
/**
|
||||
* Converts the given [KtType] to [PsiType].
|
||||
* Converts the given [KtType] to [PsiType] under [useSitePosition] context.
|
||||
*
|
||||
* [useSitePosition] is used as the parent of the resulting [PsiType],
|
||||
* which is in turn used to resolve [PsiType].
|
||||
*
|
||||
* [useSitePosition] is also used to determine if the given [KtType] needs to be approximated.
|
||||
* For example, if the given type is local yet available in the same scope of use site, we can
|
||||
* still use such local type. Otherwise, e.g., exposed to public as a return type, the resulting
|
||||
* type will be approximated accordingly.
|
||||
*
|
||||
* Returns `null` if the conversion encounters any erroneous cases, e.g., errors in type arguments.
|
||||
* A client can handle such case in its own way. For instance,
|
||||
* * UAST will return `UastErrorType` as a default error type.
|
||||
* * LC will return `NonExistentClass` from the [context].
|
||||
* * LC will return `NonExistentClass` created from the [useSitePosition].
|
||||
*/
|
||||
public fun KtType.asPsiType(
|
||||
context: PsiElement,
|
||||
useSitePosition: PsiElement,
|
||||
mode: TypeMappingMode = TypeMappingMode.DEFAULT,
|
||||
): PsiType? =
|
||||
analysisSession.psiTypeProvider.asPsiType(this, context, mode)
|
||||
analysisSession.psiTypeProvider.asPsiType(this, useSitePosition, mode)
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: Local
|
||||
PsiType: PsiType:Object
|
||||
PsiType: PsiType:Local
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: Local
|
||||
PsiType: PsiType:Object
|
||||
PsiType: PsiType:Local
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: () -> Local
|
||||
PsiType: PsiType:Function0<? extends Object>
|
||||
PsiType: PsiType:Function0<? extends Local>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: Local
|
||||
PsiType: PsiType:Object
|
||||
PsiType: PsiType:Local
|
||||
|
||||
Reference in New Issue
Block a user