Analysis API: get rid of KtTypeAndAnnotations & add annotations for every type
This commit is contained in:
+1
-1
@@ -7,10 +7,10 @@ package org.jetbrains.kotlin.light.classes.symbol
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.light.LightIdentifier
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
|
||||
import org.jetbrains.kotlin.asJava.classes.cannotModify
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElementBase
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedConstantValue
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
|
||||
internal class FirAnnotationParameterList(
|
||||
|
||||
+2
-2
@@ -10,12 +10,12 @@ import com.intellij.psi.PsiAnnotationMemberValue
|
||||
import com.intellij.psi.PsiAnnotationParameterList
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.impl.PsiImplUtil
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtAnnotationCall
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
internal class FirLightAnnotationForAnnotationCall(
|
||||
private val annotationCall: KtAnnotationCall,
|
||||
private val annotationCall: KtAnnotationApplication,
|
||||
parent: PsiElement,
|
||||
) : FirLightAbstractAnnotation(parent) {
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import com.intellij.psi.PsiAnnotationMemberValue
|
||||
import com.intellij.psi.PsiAnnotationParameterList
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.impl.PsiImplUtil
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedConstantValue
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtFileSymbol
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ internal class FirLightClassForEnumEntry(
|
||||
|
||||
private val _extendsList: PsiReferenceList? by lazyPub {
|
||||
val mappedType = analyzeWithSymbolAsContext(enumEntrySymbol) {
|
||||
enumEntrySymbol.annotatedType.type.asPsiType(this@FirLightClassForEnumEntry, KtTypeMappingMode.SUPER_TYPE) as? PsiClassType
|
||||
enumEntrySymbol.type.asPsiType(this@FirLightClassForEnumEntry, KtTypeMappingMode.SUPER_TYPE) as? PsiClassType
|
||||
?: return@lazyPub null
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.*
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithMembers
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtTypeAndAnnotations
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.isPrivateOrPrivateToThis
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.HackToForceAllowRunningAnalyzeOnEDT
|
||||
import org.jetbrains.kotlin.analysis.api.tokens.hackyAllowRunningOnEdt
|
||||
@@ -306,7 +305,7 @@ internal fun FirLightClassBase.createField(
|
||||
)
|
||||
}
|
||||
|
||||
internal fun FirLightClassBase.createInheritanceList(forExtendsList: Boolean, superTypes: List<KtTypeAndAnnotations>): PsiReferenceList {
|
||||
internal fun FirLightClassBase.createInheritanceList(forExtendsList: Boolean, superTypes: List<KtType>): PsiReferenceList {
|
||||
|
||||
val role = if (forExtendsList) PsiReferenceList.Role.EXTENDS_LIST else PsiReferenceList.Role.IMPLEMENTS_LIST
|
||||
|
||||
@@ -334,9 +333,8 @@ internal fun FirLightClassBase.createInheritanceList(forExtendsList: Boolean, su
|
||||
|
||||
//TODO Add support for kotlin.collections.
|
||||
superTypes.asSequence()
|
||||
.filter { it.type.needToAddTypeIntoList() }
|
||||
.mapNotNull { typeAnnotated ->
|
||||
val type = typeAnnotated.type
|
||||
.filter { it.needToAddTypeIntoList() }
|
||||
.mapNotNull { type ->
|
||||
if (type !is KtNonErrorClassType) return@mapNotNull null
|
||||
analyzeWithSymbolAsContext(type.classSymbol) {
|
||||
mapSuperType(type, this@createInheritanceList, kotlinCollectionAsIs = true)
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ internal class FirLightFieldForEnumEntry(
|
||||
|
||||
private val _type: PsiType by lazyPub {
|
||||
analyzeWithSymbolAsContext(enumEntrySymbol) {
|
||||
enumEntrySymbol.annotatedType.type.asPsiType(this@FirLightFieldForEnumEntry)
|
||||
enumEntrySymbol.type.asPsiType(this@FirLightFieldForEnumEntry)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ internal class FirLightFieldForPropertySymbol(
|
||||
it.getKtType()?.asPsiType(this@FirLightFieldForPropertySymbol, KtTypeMappingMode.RETURN_TYPE)
|
||||
}
|
||||
else -> {
|
||||
propertySymbol.annotatedType.type.asPsiType(this@FirLightFieldForPropertySymbol, KtTypeMappingMode.RETURN_TYPE)
|
||||
propertySymbol.type.asPsiType(this@FirLightFieldForPropertySymbol, KtTypeMappingMode.RETURN_TYPE)
|
||||
}
|
||||
}
|
||||
} ?: nonExistentType()
|
||||
@@ -92,7 +92,7 @@ internal class FirLightFieldForPropertySymbol(
|
||||
|
||||
val nullability = if (!(propertySymbol is KtKotlinPropertySymbol && propertySymbol.isLateInit)) {
|
||||
analyzeWithSymbolAsContext(propertySymbol) {
|
||||
getTypeNullability(propertySymbol.annotatedType.type)
|
||||
getTypeNullability(propertySymbol.type)
|
||||
}
|
||||
} else NullabilityType.Unknown
|
||||
|
||||
|
||||
-8
@@ -26,14 +26,6 @@ internal fun <L : Any> L.invalidAccess(): Nothing =
|
||||
error("Cls delegate shouldn't be accessed for fir light classes! Qualified name: ${javaClass.name}")
|
||||
|
||||
|
||||
internal fun KtAnalysisSession.mapSuperType(
|
||||
type: KtTypeAndAnnotations,
|
||||
psiContext: PsiElement,
|
||||
kotlinCollectionAsIs: Boolean = false
|
||||
): PsiClassType? {
|
||||
return mapSuperType(type.type, psiContext, kotlinCollectionAsIs)
|
||||
}
|
||||
|
||||
internal fun KtAnalysisSession.mapSuperType(
|
||||
type: KtType,
|
||||
psiContext: PsiElement,
|
||||
|
||||
+2
-2
@@ -75,7 +75,7 @@ internal class FirLightAccessorMethodForSymbol(
|
||||
val nullabilityType = if (nullabilityApplicable) {
|
||||
analyzeWithSymbolAsContext(containingPropertySymbol) {
|
||||
getTypeNullability(
|
||||
containingPropertySymbol.annotatedType.type
|
||||
containingPropertySymbol.type
|
||||
)
|
||||
}
|
||||
} else NullabilityType.Unknown
|
||||
@@ -151,7 +151,7 @@ internal class FirLightAccessorMethodForSymbol(
|
||||
private val _returnedType: PsiType by lazyPub {
|
||||
if (!isGetter) return@lazyPub PsiType.VOID
|
||||
analyzeWithSymbolAsContext(containingPropertySymbol) {
|
||||
containingPropertySymbol.annotatedType.type.asPsiType(
|
||||
containingPropertySymbol.type.asPsiType(
|
||||
this@FirLightAccessorMethodForSymbol,
|
||||
KtTypeMappingMode.RETURN_TYPE,
|
||||
containingClass.isAnnotationType
|
||||
|
||||
+3
-3
@@ -66,7 +66,7 @@ internal class FirLightSimpleMethodForSymbol(
|
||||
isVoidReturnType ->
|
||||
return@l NullabilityType.Unknown
|
||||
else ->
|
||||
functionSymbol.annotatedType.type
|
||||
functionSymbol.type
|
||||
}
|
||||
getTypeNullability(ktType)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ internal class FirLightSimpleMethodForSymbol(
|
||||
override fun isConstructor(): Boolean = false
|
||||
|
||||
private val isVoidReturnType: Boolean
|
||||
get() = functionSymbol.annotatedType.type.run {
|
||||
get() = functionSymbol.type.run {
|
||||
isUnit && nullabilityType != NullabilityType.Nullable
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ internal class FirLightSimpleMethodForSymbol(
|
||||
isVoidReturnType ->
|
||||
return@lazyPub PsiType.VOID
|
||||
else ->
|
||||
functionSymbol.annotatedType.type
|
||||
functionSymbol.type
|
||||
}
|
||||
ktType.asPsiType(
|
||||
this@FirLightSimpleMethodForSymbol,
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ internal abstract class FirLightParameterBaseForSymbol(
|
||||
return if (nullabilityApplicable) {
|
||||
analyzeWithSymbolAsContext(parameterSymbol) {
|
||||
getTypeNullability(
|
||||
parameterSymbol.annotatedType.type
|
||||
parameterSymbol.type
|
||||
)
|
||||
}
|
||||
} else NullabilityType.Unknown
|
||||
@@ -47,7 +47,7 @@ internal abstract class FirLightParameterBaseForSymbol(
|
||||
|
||||
private val _type by lazyPub {
|
||||
val convertedType = analyzeWithSymbolAsContext(parameterSymbol) {
|
||||
val ktType = parameterSymbol.annotatedType.type
|
||||
val ktType = parameterSymbol.type
|
||||
val typeMappingMode = when {
|
||||
ktType.isSuspendFunctionType -> KtTypeMappingMode.DEFAULT
|
||||
// TODO: extract type mapping mode from annotation?
|
||||
|
||||
+7
-6
@@ -9,17 +9,18 @@ import com.intellij.psi.PsiAnnotation
|
||||
import com.intellij.psi.PsiIdentifier
|
||||
import com.intellij.psi.PsiModifierList
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.annotations
|
||||
import org.jetbrains.kotlin.asJava.classes.lazyPub
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.analysis.api.isValid
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtTypeAndAnnotations
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
internal class FirLightParameterForReceiver private constructor(
|
||||
private val receiverTypeAndAnnotations: KtTypeAndAnnotations,
|
||||
private val receiverType: KtType,
|
||||
private val context: KtSymbol,
|
||||
methodName: String,
|
||||
method: FirLightMethod
|
||||
@@ -37,7 +38,7 @@ internal class FirLightParameterForReceiver private constructor(
|
||||
val extensionTypeAndAnnotations = callableSymbol.receiverType ?: return null
|
||||
|
||||
return FirLightParameterForReceiver(
|
||||
receiverTypeAndAnnotations = extensionTypeAndAnnotations,
|
||||
receiverType = extensionTypeAndAnnotations,
|
||||
context = callableSymbol,
|
||||
methodName = callableSymbol.name.asString(),
|
||||
method = method
|
||||
@@ -59,7 +60,7 @@ internal class FirLightParameterForReceiver private constructor(
|
||||
override val kotlinOrigin: KtParameter? = null
|
||||
|
||||
private val _annotations: List<PsiAnnotation> by lazyPub {
|
||||
receiverTypeAndAnnotations.annotations.map {
|
||||
receiverType.annotations.map {
|
||||
FirLightAnnotationForAnnotationCall(it, this)
|
||||
}
|
||||
}
|
||||
@@ -71,7 +72,7 @@ internal class FirLightParameterForReceiver private constructor(
|
||||
|
||||
private val _type: PsiType by lazyPub {
|
||||
analyzeWithSymbolAsContext(context) {
|
||||
receiverTypeAndAnnotations.type.asPsiType(this@FirLightParameterForReceiver)
|
||||
receiverType.asPsiType(this@FirLightParameterForReceiver)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ internal class FirLightParameterForReceiver private constructor(
|
||||
override fun equals(other: Any?): Boolean =
|
||||
this === other ||
|
||||
(other is FirLightParameterForReceiver &&
|
||||
receiverTypeAndAnnotations == other.receiverTypeAndAnnotations)
|
||||
receiverType == other.receiverType)
|
||||
|
||||
override fun hashCode(): Int = kotlinOrigin.hashCode()
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ internal class FirLightSuspendContinuationParameter(
|
||||
private val _type by lazyPub {
|
||||
analyzeWithSymbolAsContext(functionSymbol) {
|
||||
buildClassType(StandardClassIds.Continuation) {
|
||||
argument(functionSymbol.annotatedType.type)
|
||||
argument(functionSymbol.type)
|
||||
}.asPsiType(this@FirLightSuspendContinuationParameter)
|
||||
} ?: nonExistentType()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user