[kotlin] Migrate 'KtType' to 'KaType'

^KT-67996

GitOrigin-RevId: d079b3ca7817c537905abc2336e1a584533ca25d
This commit is contained in:
Yan Zhulanow
2024-06-24 02:00:19 +09:00
committed by intellij-monorepo-bot
parent b6d506d3f4
commit 2e7eb91e72
117 changed files with 459 additions and 459 deletions

View File

@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaNamedFunctionSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.idea.base.codeInsight.ShortenReferencesFacility
import org.jetbrains.kotlin.idea.base.utils.fqname.isImported
@@ -359,7 +359,7 @@ private fun isSuspensionRestricted(function: KtNamedFunction): Boolean {
}
}
private fun KaSession.isSuspensionRestricted(lambdaType: KtType): Boolean {
private fun KaSession.isSuspensionRestricted(lambdaType: KaType): Boolean {
assert(lambdaType.isSuspendFunctionType)
val receiverTypeSymbol = (lambdaType as? KaFunctionType)?.receiverType?.expandedSymbol

View File

@@ -33,7 +33,7 @@ object CallParameterInfoProvider {
val argumentExpressionsBeforeCurrent = getArgumentOrIndexExpressions(sourceElement).take(currentArgumentIndex).filterNotNull()
for (argumentExpression in argumentExpressionsBeforeCurrent) {
val parameterForArgument = argumentMapping[argumentExpression] ?: continue
val argumentType = argumentExpression.getKtType() ?: error("Argument should have a KtType")
val argumentType = argumentExpression.getKtType() ?: error("Argument should have a KaType")
if (argumentType.isNotSubTypeOf(parameterForArgument.returnType, subtypingErrorTypePolicy)) {
return true
}

View File

@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaFlexibleType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.base.analysis.isExcludedFromAutoImport
import org.jetbrains.kotlin.idea.base.psi.isExpectDeclaration
@@ -199,7 +199,7 @@ class KtSymbolFromIndexProvider private constructor(
context(KaSession)
fun getTopLevelExtensionCallableSymbolsByName(
name: Name,
receiverTypes: List<KtType>,
receiverTypes: List<KaType>,
psiFilter: (KtCallableDeclaration) -> Boolean = { true }
): Sequence<KaCallableSymbol> =
getExtensionCallableSymbolsByName(name, receiverTypes, psiFilter, KotlinTopLevelExtensionsByReceiverTypeIndex)
@@ -207,7 +207,7 @@ class KtSymbolFromIndexProvider private constructor(
context(KaSession)
fun getDeclaredInObjectExtensionCallableSymbolsByName(
name: Name,
receiverTypes: List<KtType>,
receiverTypes: List<KaType>,
psiFilter: (KtCallableDeclaration) -> Boolean = { true }
): Sequence<KaCallableSymbol> =
getExtensionCallableSymbolsByName(name, receiverTypes, psiFilter, KotlinExtensionsInObjectsByReceiverTypeIndex)
@@ -215,7 +215,7 @@ class KtSymbolFromIndexProvider private constructor(
context(KaSession)
private fun getExtensionCallableSymbolsByName(
name: Name,
receiverTypes: List<KtType>,
receiverTypes: List<KaType>,
psiFilter: (KtCallableDeclaration) -> Boolean,
indexHelper: KotlinExtensionsByReceiverTypeStubIndexHelper,
): Sequence<KaCallableSymbol> {
@@ -238,7 +238,7 @@ class KtSymbolFromIndexProvider private constructor(
context(KaSession)
fun getTopLevelExtensionCallableSymbolsByNameFilter(
nameFilter: (Name) -> Boolean,
receiverTypes: List<KtType>,
receiverTypes: List<KaType>,
psiFilter: (KtCallableDeclaration) -> Boolean = { true }
): Sequence<KaCallableSymbol> {
val receiverTypeNames = receiverTypes.flatMapTo(hashSetOf()) { findAllNamesForType(it) }
@@ -262,7 +262,7 @@ class KtSymbolFromIndexProvider private constructor(
}
context(KaSession)
private fun Sequence<KaCallableSymbol>.filterExtensionsByReceiverTypes(receiverTypes: List<KtType>): Sequence<KaCallableSymbol> {
private fun Sequence<KaCallableSymbol>.filterExtensionsByReceiverTypes(receiverTypes: List<KaType>): Sequence<KaCallableSymbol> {
val nonNullableReceiverTypes = receiverTypes.map { it.withNullability(KaTypeNullability.NON_NULLABLE) }
return filter { symbol ->
@@ -283,7 +283,7 @@ class KtSymbolFromIndexProvider private constructor(
private fun getShortName(fqName: String) = Name.identifier(fqName.substringAfterLast('.'))
context(KaSession)
private fun findAllNamesForType(type: KtType): Set<String> = buildSet {
private fun findAllNamesForType(type: KaType): Set<String> = buildSet {
if (type is KaFlexibleType) {
return findAllNamesForType(type.lowerBound)
}

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.signatures.KaFunctionSignature
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaAnnotatedSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithVisibility
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.references.KtReference
@@ -105,7 +105,7 @@ fun filterCandidateByReceiverTypeAndVisibility(
* If explicit receiver is present and can be resolved, returns its type. Otherwise, returns empty list.
*/
context(KaSession)
fun collectReceiverTypesForElement(callElement: KtElement, explicitReceiver: KtExpression?): List<KtType> {
fun collectReceiverTypesForElement(callElement: KtElement, explicitReceiver: KtExpression?): List<KaType> {
return if (explicitReceiver != null) {
collectReceiverTypesForExplicitReceiverExpression(explicitReceiver)
} else {
@@ -115,7 +115,7 @@ fun collectReceiverTypesForElement(callElement: KtElement, explicitReceiver: KtE
}
context(KaSession)
fun collectReceiverTypesForExplicitReceiverExpression(explicitReceiver: KtExpression): List<KtType> {
fun collectReceiverTypesForExplicitReceiverExpression(explicitReceiver: KtExpression): List<KaType> {
explicitReceiver.referenceExpression()?.mainReference?.let { receiverReference ->
val receiverSymbol = receiverReference.resolveToExpandedSymbol()
if (receiverSymbol == null || receiverSymbol is KaPackageSymbol) return emptyList()
@@ -128,7 +128,7 @@ fun collectReceiverTypesForExplicitReceiverExpression(explicitReceiver: KtExpres
val isSafeCall = explicitReceiver.parent is KtSafeQualifiedExpression
val explicitReceiverType = explicitReceiver.getKtType() ?: error("Receiver should have a KtType")
val explicitReceiverType = explicitReceiver.getKtType() ?: error("Receiver should have a KaType")
val adjustedType = if (isSafeCall) {
explicitReceiverType.withNullability(KaTypeNullability.NON_NULLABLE)
} else {
@@ -138,7 +138,7 @@ fun collectReceiverTypesForExplicitReceiverExpression(explicitReceiver: KtExpres
}
context(KaSession)
private fun KaNamedClassOrObjectSymbol.buildClassTypeBySymbolWithTypeArgumentsFromExpression(expression: KtExpression): KtType =
private fun KaNamedClassOrObjectSymbol.buildClassTypeBySymbolWithTypeArgumentsFromExpression(expression: KtExpression): KaType =
buildClassType(this) {
if (expression is KtCallExpression) {
val typeArgumentTypes = expression.typeArguments.map { it.typeReference?.getKtType() }

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.base.analysis.api.utils
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.KtStarTypeProjection
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
* An accurate estimation requires the use of the constraint system, which can lead to a loss in performance.
*/
context(KaSession)
infix fun KtType.isPossiblySubTypeOf(superType: KtType): Boolean {
infix fun KaType.isPossiblySubTypeOf(superType: KaType): Boolean {
if (this is KaTypeParameterType) return this.hasCommonSubTypeWith(superType)
if (superType is KaTypeParameterType) return superType.symbol.upperBounds.all { this isPossiblySubTypeOf it }
@@ -29,7 +29,7 @@ infix fun KtType.isPossiblySubTypeOf(superType: KtType): Boolean {
}
context(KaSession)
private fun buildClassTypeWithStarProjections(symbol: KaClassSymbol, nullability: KaTypeNullability): KtType =
private fun buildClassTypeWithStarProjections(symbol: KaClassSymbol, nullability: KaTypeNullability): KaType =
buildClassType(symbol) {
repeat(symbol.typeParameters.size) {
argument(KtStarTypeProjection(token))

View File

@@ -6,7 +6,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.KaCompoundArrayAccessCall
import org.jetbrains.kotlin.analysis.api.resolution.KaFunctionCall
import org.jetbrains.kotlin.analysis.api.resolution.calls
import org.jetbrains.kotlin.analysis.api.components.DefaultTypeClassIds
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.ClassId
@@ -14,10 +14,10 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.isNull
import org.jetbrains.kotlin.types.Variance
class ExpectedExpressionMatcher(val types: List<KtType>? = null, val nullability: KaTypeNullability? = null) {
class ExpectedExpressionMatcher(val types: List<KaType>? = null, val nullability: KaTypeNullability? = null) {
context(KaSession)
fun match(candidateType: KtType): Boolean {
fun match(candidateType: KaType): Boolean {
if (types != null && types.none { candidateType.isSubTypeOf(it) }) {
return false
}
@@ -191,7 +191,7 @@ private fun getForElvis(target: KtElement): ExpectedExpressionMatcher? {
else -> buildClassType(DefaultTypeClassIds.ANY)
}
fun constructType(classId: ClassId): KtType {
fun constructType(classId: ClassId): KaType {
return buildClassType(classId) {
argument(elementType, Variance.OUT_VARIANCE)
}

View File

@@ -195,7 +195,7 @@ class KotlinNameSuggester(
* - `List<User>` -> {users}
*/
context(KaSession)
fun suggestTypeNames(type: KtType): Sequence<String> {
fun suggestTypeNames(type: KaType): Sequence<String> {
return sequence {
val presentableType = getPresentableType(type)
@@ -225,14 +225,14 @@ class KotlinNameSuggester(
return@sequence
}
fun getClassId(type: KtType): ClassId = when (type) {
fun getClassId(type: KaType): ClassId = when (type) {
is KaClassType -> type.classId
is KaTypeParameterType -> ClassId(FqName.ROOT, FqName.topLevel(type.name), false)
else -> ClassId(FqName.ROOT, FqName.topLevel(Name.identifier("Value")), false)
}
suspend fun SequenceScope<String>.registerClassNames(type: KtType, preprocessor: (String) -> String = { it }) {
suspend fun SequenceScope<String>.registerClassNames(type: KaType, preprocessor: (String) -> String = { it }) {
val classId = getClassId(type)
KotlinNameSuggester(case, EscapingRules.NONE, ignoreCompanionNames)
@@ -274,7 +274,7 @@ class KotlinNameSuggester(
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun getPresentableType(type: KtType): KtType = type.approximateToSuperPublicDenotableOrSelf(approximateLocalTypes = true)
private fun getPresentableType(type: KaType): KaType = type.approximateToSuperPublicDenotableOrSelf(approximateLocalTypes = true)
/**
* Suggests type alias name for a given type element.
@@ -571,7 +571,7 @@ class KotlinNameSuggester(
}
context(KaSession)
private fun getPrimitiveType(type: KtType): PrimitiveType? {
private fun getPrimitiveType(type: KaType): PrimitiveType? {
return when {
type.isBoolean -> PrimitiveType.BOOLEAN
type.isChar -> PrimitiveType.CHAR
@@ -590,7 +590,7 @@ private val ITERABLE_LIKE_CLASS_IDS =
.map { ClassId.topLevel(it) }
context(KaSession)
private fun getIterableElementType(type: KtType): KtType? {
private fun getIterableElementType(type: KaType): KaType? {
if (type is KaClassType && type.classId in ITERABLE_LIKE_CLASS_IDS) {
return type.typeArguments.singleOrNull()?.type
}

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.base.fir.analysisApiPlatform.sessions
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.resolution.successfulFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.analyzeInModalWindow
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
import org.jetbrains.kotlin.idea.test.AbstractMultiModuleTest
@@ -65,7 +65,7 @@ class CyclicDependenciesSymbolResolutionTest : AbstractMultiModuleTest() {
private fun KtNamedFunction.getBodyCallExpression(): KtCallExpression = bodyExpression!! as KtCallExpression
context(KaSession)
private fun KtCallExpression.assertCalleeNameAndType(file: KtFile, expectedName: String, expectedType: KtType) {
private fun KtCallExpression.assertCalleeNameAndType(file: KtFile, expectedName: String, expectedType: KaType) {
val ktFunction = file.declarations.first() as KtNamedFunction
val ktCall = ktFunction.bodyExpression!! as KtCallExpression

View File

@@ -8,7 +8,7 @@ import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedFunctionSymbol
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.base.analysis.api.utils.getJvmName
@@ -93,7 +93,7 @@ internal class SymbolBasedKotlinMainFunctionDetector : KotlinMainFunctionDetecto
}
context(KaSession)
private fun buildMainParameterType(): KtType {
private fun buildMainParameterType(): KaType {
return buildClassType(StandardClassIds.Array) {
val argumentType = buildClassType(StandardClassIds.String) {
nullability = KaTypeNullability.NON_NULLABLE
@@ -105,7 +105,7 @@ internal class SymbolBasedKotlinMainFunctionDetector : KotlinMainFunctionDetecto
}
context(KaSession)
private fun KtType.isResolvedClassType(): Boolean = when (this) {
private fun KaType.isResolvedClassType(): Boolean = when (this) {
is KaClassType -> typeArguments.mapNotNull { it.type }.all { it.isResolvedClassType() }
else -> false
}

View File

@@ -20,7 +20,7 @@ interface ContextProvider<E : KtElement, C> {
* The context should not store:
* - Everything that came from [org.jetbrains.kotlin.analysis.api.KaSession] like:
* - [org.jetbrains.kotlin.analysis.api.symbols.KtSymbol], consider using [org.jetbrains.kotlin.analysis.api.symbols.pointers.KaSymbolPointer] instead.
* - [org.jetbrains.kotlin.analysis.api.types.KtType]
* - [org.jetbrains.kotlin.analysis.api.types.KaType]
* - [org.jetbrains.kotlin.analysis.api.resolution.KaCall]
* - The [org.jetbrains.kotlin.analysis.api.KaSession] instance itself.
* - [com.intellij.psi.PsiElement], consider using [com.intellij.psi.SmartPsiElementPointer] instead.

View File

@@ -24,7 +24,7 @@ abstract class KotlinApplicatorBasedQuickFix<T : PsiElement, in I : KotlinApplic
* Should not store inside
* - Everything that came from [org.jetbrains.kotlin.analysis.api.KaSession] like :
* - [org.jetbrains.kotlin.analysis.api.symbols.KtSymbol] consider using [org.jetbrains.kotlin.analysis.api.symbols.pointers.KaSymbolPointer] instead
* - [org.jetbrains.kotlin.analysis.api.types.KtType]
* - [org.jetbrains.kotlin.analysis.api.types.KaType]
* - [org.jetbrains.kotlin.analysis.api.resolution.KaCall]
* - [org.jetbrains.kotlin.analysis.api.KaSession] instance itself
* - [PsiElement] consider using [com.intellij.psi.SmartPsiElementPointer] instead

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
import org.jetbrains.kotlin.idea.quickfix.AddToStringFix
import org.jetbrains.kotlin.psi.KtExpression
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.psi.KtProperty
object AddToStringFixFactories {
context(KaSession)
private fun getFixes(element: PsiElement?, expectedType: KtType, actualType: KtType): List<AddToStringFix> {
private fun getFixes(element: PsiElement?, expectedType: KaType, actualType: KaType): List<AddToStringFix> {
if (element !is KtExpression) return emptyList()
return buildList {
if (expectedType.isString || expectedType.isCharSequence) {

View File

@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
@@ -55,7 +55,7 @@ internal object AddTypeAnnotationToValueParameterFixFactory {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun getTypeName(type: KtType): String {
private fun getTypeName(type: KaType): String {
val typeName = type.render(
KtTypeRendererForSource.WITH_SHORT_NAMES,
Variance.INVARIANT

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.psi.replaced
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -113,8 +113,8 @@ object CastExpressionFixFactories {
context(KaSession)
private fun createFixes(
isDueToNullability: Boolean,
actualType: KtType,
expectedType: KtType,
actualType: KaType,
expectedType: KaType,
element: PsiElement,
): List<CastExpressionModCommandAction> {
// `null` related issue should not be handled by a cast fix.

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithMembers
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -68,7 +68,7 @@ object ChangeTypeQuickFixFactories {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun getActualType(ktType: KtType): KtType {
private fun getActualType(ktType: KaType): KaType {
val typeKind = ktType.functionTypeKind
when (typeKind) {
FunctionTypeKind.KFunction -> typeKind.nonReflectKind()
@@ -87,7 +87,7 @@ object ChangeTypeQuickFixFactories {
}
context(KaSession)
private fun KtElement.returnType(candidateType: KtType): KtType {
private fun KtElement.returnType(candidateType: KaType): KaType {
val (initializers, functionOrGetter) = when (this) {
is KtNamedFunction -> listOfNotNull(this.initializer) to this
is KtProperty -> listOfNotNull(this.initializer, this.getter?.initializer) to this.getter
@@ -121,7 +121,7 @@ object ChangeTypeQuickFixFactories {
}
context(KaSession)
private fun KtProperty.getPropertyInitializerType(): KtType? {
private fun KtProperty.getPropertyInitializerType(): KaType? {
val initializer = initializer
return if (typeReference != null && initializer != null) {
//copy property initializer to calculate initializer's type without property's declared type
@@ -187,7 +187,7 @@ object ChangeTypeQuickFixFactories {
}
context(KaSession)
private fun registerVariableTypeFixes(declaration: KtProperty, type: KtType): List<KotlinQuickFixAction<KtExpression>> {
private fun registerVariableTypeFixes(declaration: KtProperty, type: KaType): List<KotlinQuickFixAction<KtExpression>> {
val expectedType = declaration.getReturnKtType()
val expression = declaration.initializer
return buildList {
@@ -271,7 +271,7 @@ object ChangeTypeQuickFixFactories {
}
context(KaSession)
private fun createTypeInfo(ktType: KtType) = with(CallableReturnTypeUpdaterUtils.TypeInfo) {
private fun createTypeInfo(ktType: KaType) = with(CallableReturnTypeUpdaterUtils.TypeInfo) {
createByKtTypes(ktType)
}
@@ -334,10 +334,10 @@ object ChangeTypeQuickFixFactories {
}
context(KaSession)
fun KtType.isNumberOrUNumberType(): Boolean = isNumberType() || isUNumberType()
fun KaType.isNumberOrUNumberType(): Boolean = isNumberType() || isUNumberType()
context(KaSession)
fun KtType.isNumberType(): Boolean = isPrimitive && !isBoolean && !isChar
fun KaType.isNumberType(): Boolean = isPrimitive && !isBoolean && !isChar
context(KaSession)
fun KtType.isUNumberType(): Boolean = isUByte || isUShort || isUInt || isULong
fun KaType.isUNumberType(): Boolean = isUByte || isUShort || isUInt || isULong

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
import org.jetbrains.kotlin.idea.quickfix.ReplaceImplicitReceiverCallFix
@@ -110,7 +110,7 @@ object ReplaceCallFixFactories {
}
context(KaSession)
private fun KtType.isMap(): Boolean {
private fun KaType.isMap(): Boolean {
val symbol = this.expandedSymbol ?: return false
if (symbol.name?.asString()?.endsWith("Map") != true) return false
val mapSymbol = getClassOrObjectSymbolByClassId(StandardClassIds.Map) ?: return false

View File

@@ -6,7 +6,7 @@ import com.intellij.modcommand.ModPsiUpdater
import com.intellij.modcommand.Presentation
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.builtins.StandardNames.FqNames.arrayClassFqNameToPrimitiveType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
@@ -78,7 +78,7 @@ object SurroundWithArrayOfWithSpreadOperatorInFunctionFixFactory {
context(KaSession)
private fun createFix(
expectedArrayType: KtType,
expectedArrayType: KaType,
element: KtExpression,
): List<SurroundWithArrayModCommandAction> {
val arrayClassId = (expectedArrayType as? KaUsualClassType)?.classId

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.psi.replaced
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -33,7 +33,7 @@ data class PrimitiveLiteralData(
)
context(KaSession)
fun preparePrimitiveLiteral(element: KtExpression, type: KtType): PrimitiveLiteralData {
fun preparePrimitiveLiteral(element: KtExpression, type: KaType): PrimitiveLiteralData {
val typeName = type.expandedSymbol?.classId?.asSingleFqName()?.toUnsafe()
val expectedTypeIsFloat = type.isFloat
val expectedTypeIsDouble = type.isDouble

View File

@@ -8,7 +8,7 @@ import org.jetbrains.kotlin.analysis.api.lifetime.KaLifetimeOwner
import org.jetbrains.kotlin.analysis.api.lifetime.KaLifetimeToken
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.base.analysis.api.utils.isPossiblySubTypeOf
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinAutoImportCallableWeigher
@@ -57,7 +57,7 @@ interface ExpressionImportWeigher {
}
context(KaSession)
private fun calculateReceiverTypes(element: KtNameReferenceExpression): List<KtType> {
private fun calculateReceiverTypes(element: KtNameReferenceExpression): List<KaType> {
val receiverExpression = element.getParentOfType<KtQualifiedExpression>(false)?.receiverExpression
return if (receiverExpression != null) {
@@ -73,7 +73,7 @@ interface ExpressionImportWeigher {
}
context(KaSession)
private fun calculateValueArgumentTypes(element: KtNameReferenceExpression): List<KtType?> {
private fun calculateValueArgumentTypes(element: KtNameReferenceExpression): List<KaType?> {
val callExpression = element.getParentOfType<KtCallElement>(strict = false)
val valueArgumentList = callExpression?.valueArgumentList ?: return emptyList()
@@ -101,8 +101,8 @@ internal abstract class AbstractExpressionImportWeigher : ExpressionImportWeighe
protected abstract fun ownWeigh(symbol: KaDeclarationSymbol): Int
context(KaSession)
protected fun weighType(presentType: KtType, typeFromImport: KtType, baseWeight: Int): Int? {
val adjustedType: KtType
protected fun weighType(presentType: KaType, typeFromImport: KaType, baseWeight: Int): Int? {
val adjustedType: KaType
val nullablesWeight = if (presentType.nullability.isNullable == typeFromImport.nullability.isNullable) {
adjustedType = presentType
2
@@ -124,8 +124,8 @@ internal class CallExpressionImportWeigher(
override val token: KaLifetimeToken,
// the weigher is not saved in any context/state, and weigh() is called when element is still valid
private val element: KtNameReferenceExpression,
private val presentReceiverTypes: List<KtType>,
private val valueArgumentTypes: List<KtType?>,
private val presentReceiverTypes: List<KaType>,
private val valueArgumentTypes: List<KaType?>,
) : AbstractExpressionImportWeigher(), KaLifetimeOwner {
context(KaSession)
@@ -145,8 +145,8 @@ internal class CallExpressionImportWeigher(
context(KaSession)
private fun calculateWeight(
symbolToBeImported: KaCallableSymbol,
presentReceiverTypes: List<KtType>,
presentValueArgumentTypes: List<KtType?>,
presentReceiverTypes: List<KaType>,
presentValueArgumentTypes: List<KaType?>,
): Int {
var weight = 0
@@ -211,8 +211,8 @@ internal class CallExpressionImportWeigher(
internal class OperatorExpressionImportWeigher(
override val token: KaLifetimeToken,
private val operatorName: Name?,
private val leftOperandType: KtType? = null,
private val rightOperandType: KtType? = null,
private val leftOperandType: KaType? = null,
private val rightOperandType: KaType? = null,
) : AbstractExpressionImportWeigher(), KaLifetimeOwner {
context(KaSession)

View File

@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaTypeAliasSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.abbreviatedTypeOrSelf
import org.jetbrains.kotlin.analysis.api.types.symbol
import org.jetbrains.kotlin.psi.*
@@ -66,7 +66,7 @@ internal class KotlinTypeDeclarationProvider : TypeDeclarationProvider {
return PsiElement.EMPTY_ARRAY
}
private fun KtCallableDeclaration.getTypeDeclarationFromCallable(typeFromSymbol: (KaCallableSymbol) -> KtType?): Array<PsiElement> {
private fun KtCallableDeclaration.getTypeDeclarationFromCallable(typeFromSymbol: (KaCallableSymbol) -> KaType?): Array<PsiElement> {
analyze(this) {
val symbol = symbol as? KaCallableSymbol ?: return PsiElement.EMPTY_ARRAY
val type = typeFromSymbol(symbol) ?: return PsiElement.EMPTY_ARRAY

View File

@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.codeinsight.utils.ChooseValueExpression
@@ -140,7 +140,7 @@ object CallableReturnTypeUpdaterUtils {
context(KaSession)
@OptIn(KaExperimentalApi::class)
@ApiStatus.Internal
fun <T> calculateAllTypes(declaration: KtCallableDeclaration, allTypesConsumer: (KtType, Sequence<KtType>, Boolean) -> T?): T? {
fun <T> calculateAllTypes(declaration: KtCallableDeclaration, allTypesConsumer: (KaType, Sequence<KaType>, Boolean) -> T?): T? {
val declarationType = declaration.getReturnKtType()
val overriddenTypes = (declaration.symbol as? KaCallableSymbol)?.directlyOverriddenSymbols
?.map { it.returnType }
@@ -195,7 +195,7 @@ object CallableReturnTypeUpdaterUtils {
context(KaSession)
private fun selectForUnitTest(
declaration: KtCallableDeclaration,
allTypes: List<KtType>
allTypes: List<KaType>
): TypeInfo? {
// This helps to be sure no nullable types are suggested
if (declaration.containingKtFile.findDescendantOfType<PsiComment>()?.takeIf {
@@ -226,14 +226,14 @@ object CallableReturnTypeUpdaterUtils {
companion object {
context(KaSession)
fun createByKtTypes(
ktType: KtType,
otherTypes: Sequence<KtType> = emptySequence(),
ktType: KaType,
otherTypes: Sequence<KaType> = emptySequence(),
useTemplate: Boolean = false
): TypeInfo = TypeInfo(createTypeByKtType(ktType), otherTypes.map { createTypeByKtType(it) }.toList(), useTemplate)
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun createTypeByKtType(ktType: KtType): Type = Type(
private fun createTypeByKtType(ktType: KaType): Type = Type(
isUnit = ktType.isUnit,
isError = ktType is KaErrorType,
longTypeRepresentation = ktType.render(KtTypeRendererForSource.WITH_QUALIFIED_NAMES, position = Variance.OUT_VARIANCE),

View File

@@ -9,7 +9,7 @@ import com.intellij.psi.createSmartPointer
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.LanguageFeature
@@ -130,7 +130,7 @@ internal class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
context(KaSession)
private fun generateArraysEqualsCall(
type: KtType, canUseContentFunctions: Boolean, arg1: String, arg2: String
type: KaType, canUseContentFunctions: Boolean, arg1: String, arg2: String
): String {
return if (canUseContentFunctions) {
val methodName = if (type.isNestedArray) "contentDeepEquals" else "contentEquals"
@@ -143,7 +143,7 @@ internal class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
context(KaSession)
private fun generateArrayHashCodeCall(
variableType: KtType?, canUseContentFunctions: Boolean, argument: String
variableType: KaType?, canUseContentFunctions: Boolean, argument: String
): String {
return if (canUseContentFunctions) {
val methodName = if (variableType?.isNestedArray == true) "contentDeepHashCode" else "contentHashCode"

View File

@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.inspections
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.codeInsight.inspections.shared.AbstractFunctionNameInspection
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtNamedFunction
@@ -18,7 +18,7 @@ class FunctionNameInspection : AbstractFunctionNameInspection() {
}
context(KaSession)
private fun KtType.hasShortName(shortName: String): Boolean {
private fun KaType.hasShortName(shortName: String): Boolean {
val typeShortName =
expandedSymbol
?.classId

View File

@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.singleVariableAccessCall
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.symbols.KaValueParameterSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaPossiblyNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.isPossiblySubTypeOf
import org.jetbrains.kotlin.idea.base.psi.replaced
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -356,7 +356,7 @@ internal class JoinDeclarationAndAssignmentInspection :
}
context(KaSession)
private fun isSubtype(type: KtType?, superType: KtType?): Boolean {
private fun isSubtype(type: KaType?, superType: KaType?): Boolean {
if (type == null || superType == null) return false
return type.isPossiblySubTypeOf(superType)
}
@@ -366,7 +366,7 @@ internal class JoinDeclarationAndAssignmentInspection :
private fun PsiElement.nextSiblings(): Sequence<PsiElement> = siblings(forward = true, withItself = false)
context(KaSession)
private fun equalNullableTypes(type1: KtType?, type2: KtType?): Boolean {
private fun equalNullableTypes(type1: KaType?, type2: KaType?): Boolean {
if (type1 == null) return type2 == null
if (type2 == null) return false
return type1.isEqualTo(type2)

View File

@@ -5,7 +5,7 @@ import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemsHolder
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
@@ -35,7 +35,7 @@ internal class KotlinEqualsBetweenInconvertibleTypesInspection : AbstractKotlinI
)
context(KaSession)
private fun KtExpression.getTypeIfComparable(): KtType? {
private fun KtExpression.getTypeIfComparable(): KaType? {
val type = getKtType()?.withNullability(KaTypeNullability.NON_NULLABLE)
return type?.takeIf { it.isPrimitive || it.isString || it.isEnum() }
}

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.types.KaDynamicType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.psi.previousStatement
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle

View File

@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaJavaFieldSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaSyntheticJavaPropertySymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.isPrivateOrPrivateToThis
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.base.analysis.api.utils.isJavaSourceOrLibrary
import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings
@@ -397,7 +397,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
private fun canConvert(
symbol: KaCallableSymbol,
callExpression: KtExpression,
receiverType: KtType,
receiverType: KaType,
propertyName: String
): Boolean {
val allOverriddenSymbols = listOf(symbol) + symbol.allOverriddenSymbols
@@ -423,7 +423,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
*/
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun receiverOrItsAncestorsContainVisibleFieldWithSameName(receiverType: KtType, propertyName: String): Boolean {
private fun receiverOrItsAncestorsContainVisibleFieldWithSameName(receiverType: KaType, propertyName: String): Boolean {
val fieldWithSameName = receiverType.scope?.declarationScope?.getCallableSymbols()
?.filter { it is KaJavaFieldSymbol && it.name.toString() == propertyName && !it.visibility.isPrivateOrPrivateToThis() }
?.singleOrNull()
@@ -434,7 +434,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
@OptIn(KaExperimentalApi::class)
private fun getSyntheticProperty(
propertyNames: List<String>,
receiverType: KtType
receiverType: KaType
): KaSyntheticJavaPropertySymbol? {
val syntheticJavaPropertiesScope = receiverType.syntheticJavaPropertiesScope ?: return null
@@ -465,7 +465,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
context(KaSession)
private fun syntheticPropertyTypeEqualsToExpected(
syntheticProperty: KaSyntheticJavaPropertySymbol,
callReturnType: KtType,
callReturnType: KaType,
propertyAccessorKind: PropertyAccessorKind
): Boolean {
val propertyExpectedType = if (propertyAccessorKind is PropertyAccessorKind.Setter) {
@@ -483,7 +483,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
callExpression: KtExpression,
propertyAccessorKind: PropertyAccessorKind,
syntheticPropertyName: Name,
receiverType: KtType
receiverType: KaType
): Boolean {
val qualifiedExpressionForSelector = callExpression.getQualifiedExpressionForSelector()
val newExpression = if (propertyAccessorKind is PropertyAccessorKind.Setter) {
@@ -544,7 +544,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
private fun receiverTypeOfNewExpressionEqualsToExpectedReceiverType(
callExpression: KtExpression,
newExpression: KtExpression,
expectedReceiverType: KtType
expectedReceiverType: KaType
): Boolean {
val resolvedCall = getSuccessfullyResolvedCall(callExpression, newExpression) ?: return false
val replacementReceiverType =

View File

@@ -441,7 +441,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun processInCheck(kotlinType: KtType?, range: KtExpression?, anchor: KotlinAnchor, negated: Boolean) {
private fun processInCheck(kotlinType: KaType?, range: KtExpression?, anchor: KotlinAnchor, negated: Boolean) {
if (kotlinType != null && (kotlinType.isInt || kotlinType.isLong)) {
if (range is KtBinaryExpression) {
val op = range.operationReference.getReferencedNameAsName().asString()
@@ -515,7 +515,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
if ((relation == RelationType.EQ || relation == RelationType.NE) ||
(leftDfType is DfPrimitiveType && rightDfType is DfPrimitiveType)
) {
val balancedType: KtType? = balanceType(leftType, rightType, forceEqualityByContent)
val balancedType: KaType? = balanceType(leftType, rightType, forceEqualityByContent)
val adjustedContentEquality = forceEqualityByContent && balancedType.toDfType() !is DfPrimitiveType
addImplicitConversion(left, balancedType)
processExpression(right)
@@ -680,7 +680,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun KtType?.isSubTypeOf(wantedType: ClassId) =
private fun KaType?.isSubTypeOf(wantedType: ClassId) =
this is KaClassType && classId == wantedType ||
this != null && getAllSuperTypes().any { type -> type is KaClassType && type.classId == wantedType }
@@ -880,7 +880,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
private fun processWhenExpression(expr: KtWhenExpression) {
val subjectExpression = expr.subjectExpression
val dfVar: DfaVariableValue?
val kotlinType: KtType?
val kotlinType: KaType?
if (subjectExpression == null) {
dfVar = null
kotlinType = null
@@ -922,7 +922,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun processWhenCondition(dfVar: DfaVariableValue?, dfVarType: KtType?, condition: KtWhenCondition) {
private fun processWhenCondition(dfVar: DfaVariableValue?, dfVarType: KaType?, condition: KtWhenCondition) {
when (condition) {
is KtWhenConditionWithExpression -> {
val expr = condition.expression
@@ -1135,7 +1135,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun processForRange(expr: KtForExpression, parameterVar: DfaVariableValue, parameterType: KtType?): () -> Unit {
private fun processForRange(expr: KtForExpression, parameterVar: DfaVariableValue, parameterType: KaType?): () -> Unit {
val range = expr.loopRange
if (parameterVar.dfType is DfIntegralType) {
when (range) {
@@ -1221,7 +1221,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun findSpecialField(type: KtType?): SpecialField? {
private fun findSpecialField(type: KaType?): SpecialField? {
type ?: return null
return when {
type.isEnum() -> SpecialField.ENUM_ORDINAL
@@ -1838,12 +1838,12 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun addImplicitConversion(expression: KtExpression?, expectedType: KtType?) {
private fun addImplicitConversion(expression: KtExpression?, expectedType: KaType?) {
addImplicitConversion(expression?.getKotlinType(), expectedType)
}
context(KaSession)
private fun addImplicitConversion(actualType: KtType?, expectedType: KtType?) {
private fun addImplicitConversion(actualType: KaType?, expectedType: KaType?) {
actualType ?: return
expectedType ?: return
if (actualType == expectedType) return
@@ -1865,11 +1865,11 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun KtType?.isInlineClass() =
private fun KaType?.isInlineClass() =
((this as? KaClassType)?.expandedSymbol as? KaNamedClassOrObjectSymbol)?.isInline == true
context(KaSession)
private fun balanceType(leftType: KtType?, rightType: KtType?, forceEqualityByContent: Boolean): KtType? = when {
private fun balanceType(leftType: KaType?, rightType: KaType?, forceEqualityByContent: Boolean): KaType? = when {
leftType == null || rightType == null -> null
leftType.isNothing && leftType.isMarkedNullable -> rightType.withNullability(KaTypeNullability.NULLABLE)
rightType.isNothing && rightType.isMarkedNullable -> leftType.withNullability(KaTypeNullability.NULLABLE)
@@ -1880,7 +1880,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
}
context(KaSession)
private fun balanceType(left: KtType?, right: KtType?): KtType? {
private fun balanceType(left: KaType?, right: KaType?): KaType? {
if (left == null || right == null) return null
if (left == right) return left
if (left.canBeNull() && !right.canBeNull()) {

View File

@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.*
context(KaSession)
internal fun KtType?.toDfType(): DfType {
internal fun KaType?.toDfType(): DfType {
if (this == null) return DfType.TOP
if (canBeNull()) {
var notNullableType = this.withNullability(KaTypeNullability.NON_NULLABLE).toDfTypeNotNullable()
@@ -53,7 +53,7 @@ internal fun KtType?.toDfType(): DfType {
}
context(KaSession)
private fun KtType.toDfTypeNotNullable(): DfType {
private fun KaType.toDfTypeNotNullable(): DfType {
return when (this) {
is KaClassType -> {
// TODO: anonymous objects
@@ -109,7 +109,7 @@ private fun KtType.toDfTypeNotNullable(): DfType {
}
context(KaSession)
internal fun KtExpression.getKotlinType(): KtType? {
internal fun KtExpression.getKotlinType(): KaType? {
var parent = this.parent
if (parent is KtDotQualifiedExpression && parent.selectorExpression == this) {
parent = parent.parent
@@ -138,7 +138,7 @@ internal fun KtExpression.getKotlinType(): KtType? {
}
context(KaSession)
internal fun KtType.getJvmAwareArrayElementType(): KtType? {
internal fun KaType.getJvmAwareArrayElementType(): KaType? {
if (!isArrayOrPrimitiveArray) return null
val type = arrayElementType ?: return null
if (this.isClassTypeWithClassId(StandardClassIds.Array) && type.isPrimitive) {
@@ -185,7 +185,7 @@ internal fun mathOpFromAssignmentToken(token: IElementType): LongRangeBinOp? = w
}
context(KaSession)
internal fun KtType.toPsiPrimitiveType(): PsiPrimitiveType = when ((this as? KaClassType)?.classId) {
internal fun KaType.toPsiPrimitiveType(): PsiPrimitiveType = when ((this as? KaClassType)?.classId) {
DefaultTypeClassIds.BOOLEAN -> PsiTypes.booleanType()
DefaultTypeClassIds.BYTE -> PsiTypes.byteType()
DefaultTypeClassIds.CHAR -> PsiTypes.charType()
@@ -198,7 +198,7 @@ internal fun KtType.toPsiPrimitiveType(): PsiPrimitiveType = when ((this as? KaC
}
context(KaSession)
internal fun KtType.canBeNull() = isMarkedNullable || hasFlexibleNullability
internal fun KaType.canBeNull() = isMarkedNullable || hasFlexibleNullability
context(KaSession)
internal fun getConstant(expr: KtConstantExpression): DfType {

View File

@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.KaImplicitReceiverValue
import org.jetbrains.kotlin.analysis.api.resolution.KaSmartCastedReceiverValue
import org.jetbrains.kotlin.analysis.api.resolution.singleCallOrNull
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -53,8 +53,8 @@ internal fun isSmartCastNecessary(expr: KtExpression, value: Boolean): Boolean {
}
context(KaSession)
private fun getValuesInExpression(expr: KtExpression): Map<KaSymbol, KtType> {
val map = hashMapOf<KaSymbol, KtType>()
private fun getValuesInExpression(expr: KtExpression): Map<KaSymbol, KaType> {
val map = hashMapOf<KaSymbol, KaType>()
SyntaxTraverser.psiTraverser(expr)
.filter(KtReferenceExpression::class.java)
.forEach { e ->

View File

@@ -5,7 +5,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.inspections.jdk2k
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.resolution.singleVariableAccessCall
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.psi.imports.addImport
@@ -102,10 +102,10 @@ object ToExtensionFunctionWithNullableReceiverForMutableCollection : Transformat
callExpression.valueArguments.firstOrNull()?.getArgumentExpression()?.getKtType()?.isMutableListOrSubtype() == true
context(KaSession)
private fun KtType?.isMutableList(): Boolean =
private fun KaType?.isMutableList(): Boolean =
this?.expandedSymbol?.classId?.asSingleFqName() == StandardNames.FqNames.mutableList
context(KaSession)
private fun KtType?.isMutableListOrSubtype(): Boolean =
private fun KaType?.isMutableListOrSubtype(): Boolean =
isMutableList() || this?.expandedSymbol?.superTypes?.reversed()?.any { it.isMutableList() } == true
}

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.types.KaFlexibleType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.name.ClassId
@@ -136,5 +136,5 @@ class UselessCallOnCollectionInspection : AbstractUselessCallInspection() {
}
context(KaSession)
private fun KtType.isList() = this.fullyExpandedType.isClassTypeWithClassId(ClassId.topLevel(StandardNames.FqNames.list))
private fun KaType.isList() = this.fullyExpandedType.isClassTypeWithClassId(ClassId.topLevel(StandardNames.FqNames.list))
}

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.*
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings
@@ -272,7 +272,7 @@ private fun getCalleeReferenceExpression(callableExpression: KtExpression): KtNa
}
context(KaSession)
private fun KtLambdaExpression.lambdaParameterType(): KtType? {
private fun KtLambdaExpression.lambdaParameterType(): KaType? {
val argument = parentValueArgument() ?: return null
val callExpression = argument.getStrictParentOfType<KtCallExpression>() ?: return null
return callExpression.resolveToCall()?.successfulFunctionCallOrNull()?.argumentMapping?.get(argument.getArgumentExpression())?.returnType
@@ -391,7 +391,7 @@ private fun KtExpression.isObject(): Boolean {
return getKtType()?.expandedSymbol?.classKind?.isObject == true
}
private fun isExtensionFunctionType(type: KtType): Boolean {
private fun isExtensionFunctionType(type: KaType): Boolean {
val functionalType = type as? KaFunctionType ?: return false
return functionalType.hasReceiver
}

View File

@@ -9,7 +9,7 @@ import com.intellij.psi.createSmartPointer
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -49,7 +49,7 @@ internal class ReplaceUnderscoreWithTypeArgumentIntention :
isUnderscoreTypeArgument(element)
context(KaSession)
private fun KtTypeProjection.resolveType(): KtType? {
private fun KtTypeProjection.resolveType(): KaType? {
val typeArgumentList = parent as KtTypeArgumentList
val call = (typeArgumentList.parent as? KtCallExpression)?.resolveToCall()?.singleFunctionCallOrNull() ?: return null
val argumentsTypes = call.typeArgumentsMapping.map { it.value }.toTypedArray()

View File

@@ -9,7 +9,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedFunctionSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.asUnit
@@ -93,8 +93,8 @@ internal class ConvertToForEachFunctionCallIntention :
}
context(KaSession)
private fun KtType.isLoopRangeType(): Boolean {
fun KtType.fqNameMatches() = (this as? KaUsualClassType)?.classId?.asSingleFqName() in loopRangeTypeFqNames
private fun KaType.isLoopRangeType(): Boolean {
fun KaType.fqNameMatches() = (this as? KaUsualClassType)?.classId?.asSingleFqName() in loopRangeTypeFqNames
return fqNameMatches() || getAllSuperTypes().any { it.fqNameMatches() }
}

View File

@@ -7,7 +7,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtExpression
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtPostfixExpression
import org.jetbrains.kotlin.psi.KtQualifiedExpression
class KtCallChainHintsProvider : AbstractKtInlayHintsProvider() {
private data class ExpressionWithType(val expression: KtExpression, val type: KtType)
private data class ExpressionWithType(val expression: KtExpression, val type: KaType)
override fun collectFromElement(element: PsiElement, sink: InlayTreeSink) {
val topmostDotQualifiedExpression = (element as? KtQualifiedExpression)

View File

@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.idea.base.psi.getLineNumber
import org.jetbrains.kotlin.idea.base.psi.isMultiLine
@@ -282,8 +282,8 @@ private fun isMultilineLocalProperty(element: PsiElement): Boolean {
}
context(KaSession)
private fun renderKtTypeHint(element: KtCallableDeclaration, multilineLocalProperty: Boolean): KtType? =
calculateAllTypes<KtType>(element) { declarationType, allTypes, cannotBeNull ->
private fun renderKtTypeHint(element: KtCallableDeclaration, multilineLocalProperty: Boolean): KaType? =
calculateAllTypes<KaType>(element) { declarationType, allTypes, cannotBeNull ->
if (declarationType is KaErrorType) return@calculateAllTypes null
if (declarationType.isUnit && multilineLocalProperty) {
@@ -316,7 +316,7 @@ private fun renderKtTypeHint(element: KtCallableDeclaration, multilineLocalPrope
}
context(KaSession)
private fun isUnclearType(type: KtType, element: KtCallableDeclaration): Boolean {
private fun isUnclearType(type: KaType, element: KtCallableDeclaration): Boolean {
if (element !is KtProperty) return true
val initializer = element.initializer ?: return true

View File

@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.analysis.api.types.KaFlexibleType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KaIntersectionType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.name.StandardClassIds
context(KaSession)
@ApiStatus.Internal
internal fun PresentationTreeBuilder.printKtType(type: KtType) {
internal fun PresentationTreeBuilder.printKtType(type: KaType) {
// See org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer.renderType
type.abbreviatedType?.let { abbreviatedType ->
printKtType(abbreviatedType)
@@ -181,7 +181,7 @@ private fun PresentationTreeBuilder.printClassId(classId: ClassId, name: String)
)
}
private fun isMutabilityFlexibleType(lower: KtType, upper: KtType): Boolean {
private fun isMutabilityFlexibleType(lower: KaType, upper: KaType): Boolean {
// see org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KaFlexibleTypeRenderer.AS_SHORT.isMutabilityFlexibleType
if (lower !is KaClassType || upper !is KaClassType) return false
@@ -189,7 +189,7 @@ private fun isMutabilityFlexibleType(lower: KtType, upper: KtType): Boolean {
}
private fun isNullabilityFlexibleType(lower: KtType, upper: KtType): Boolean {
private fun isNullabilityFlexibleType(lower: KaType, upper: KaType): Boolean {
if (lower.nullability == KaTypeNullability.NON_NULLABLE && upper.nullability == KaTypeNullability.NULLABLE) {
if (lower is KaTypeParameterType && upper is KaTypeParameterType && lower.symbol == upper.symbol) {
return true
@@ -201,7 +201,7 @@ private fun isNullabilityFlexibleType(lower: KtType, upper: KtType): Boolean {
return false
}
private fun isNonNullableFlexibleType(lower: KtType, upper: KtType): Boolean {
private fun isNonNullableFlexibleType(lower: KaType, upper: KaType): Boolean {
if (lower is KaClassType && upper is KaClassType &&
lower.classId == upper.classId &&
lower.nullability == KaTypeNullability.NON_NULLABLE &&

View File

@@ -385,7 +385,7 @@ internal class KotlinIdeDeclarationRenderer(
return object : KaClassTypeQualifierRenderer {
override fun renderClassTypeQualifier(
analysisSession: KaSession,
type: KtType,
type: KaType,
qualifiers: List<KaClassTypeQualifier>,
typeRenderer: KtTypeRenderer,
printer: PrettyPrinter
@@ -408,7 +408,7 @@ internal class KotlinIdeDeclarationRenderer(
override fun renderName(
analysisSession: KaSession,
name: Name,
owner: KtType,
owner: KaType,
typeRenderer: KtTypeRenderer,
printer: PrettyPrinter
): Unit = with(analysisSession) {
@@ -760,7 +760,7 @@ internal class KotlinIdeDeclarationRenderer(
append("::class")
}
private fun PrettyPrinter.renderType(type: KtType) {
private fun PrettyPrinter.renderType(type: KaType) {
if (type.annotations.isNotEmpty()) {
for (annotation in type.annotations) {
append('@')

View File

@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaClassTypeQualifier
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.idea.base.psi.classIdIfNonLocal
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -83,7 +83,7 @@ object CreateKotlinCallableActionTextBuilder {
context (KaSession)
@OptIn(KaExperimentalApi::class)
private fun KaSymbol.renderAsReceiver(isAbstract: Boolean, ktType: KtType?): String? {
private fun KaSymbol.renderAsReceiver(isAbstract: Boolean, ktType: KaType?): String? {
return when (this) {
is KaCallableSymbol -> ktType?.selfOrSuperTypeWithAbstractMatch(isAbstract)
?.render(RENDERER_OPTION_FOR_CREATE_FROM_USAGE_TEXT, Variance.INVARIANT)
@@ -94,7 +94,7 @@ object CreateKotlinCallableActionTextBuilder {
}
context (KaSession)
private fun KtType.selfOrSuperTypeWithAbstractMatch(isAbstract: Boolean): KtType? {
private fun KaType.selfOrSuperTypeWithAbstractMatch(isAbstract: Boolean): KaType? {
if (this.hasAbstractDeclaration() == isAbstract || this is KaClassType && (symbol as? KaClassSymbol)?.classKind == KaClassKind.INTERFACE) return this
return getDirectSuperTypes().firstNotNullOfOrNull { it.selfOrSuperTypeWithAbstractMatch(isAbstract) }
}
@@ -105,7 +105,7 @@ object CreateKotlinCallableActionTextBuilder {
classIdRenderer = object : KaClassTypeQualifierRenderer {
override fun renderClassTypeQualifier(
analysisSession: KaSession,
type: KtType,
type: KaType,
qualifiers: List<KaClassTypeQualifier>,
typeRenderer: KtTypeRenderer,
printer: PrettyPrinter

View File

@@ -8,7 +8,7 @@ import com.intellij.openapi.util.NlsSafe
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaClassLikeSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.getExpectedKotlinType
import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.resolveExpression
import org.jetbrains.kotlin.psi.KtCallExpression
@@ -22,7 +22,7 @@ internal class CreateMethodFromKotlinUsageRequest (
functionCall: KtCallExpression,
modifiers: Collection<JvmModifier>,
val receiverExpression: KtExpression?,
val receiverType: KtType?, // (in case receiverExpression is null) it can be notnull when there's implicit receiver: `blah { unknownFunc() }`
val receiverType: KaType?, // (in case receiverExpression is null) it can be notnull when there's implicit receiver: `blah { unknownFunc() }`
val isExtension: Boolean,
val isAbstractClassOrInterface: Boolean,
val isForCompanion: Boolean,

View File

@@ -3,7 +3,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage
import com.intellij.lang.jvm.actions.ExpectedTypeWithNullability
import com.intellij.lang.jvm.types.JvmType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.toNullability
class ExpectedKotlinType(val ktType: KtType, jvmType: JvmType) : ExpectedTypeWithNullability(jvmType, ktType.nullability.toNullability())
class ExpectedKotlinType(val ktType: KaType, jvmType: JvmType) : ExpectedTypeWithNullability(jvmType, ktType.nullability.toNullability())

View File

@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.KtStarTypeProjection
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaClassKind
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.canRefactor
@@ -196,7 +196,7 @@ object K2CreateFunctionFromUsageBuilder {
* Returns the type of the class containing this [KtSimpleNameExpression] if the class is abstract. Otherwise, returns null.
*/
context (KaSession)
private fun KtSimpleNameExpression.getAbstractTypeOfContainingClass(): KtType? {
private fun KtSimpleNameExpression.getAbstractTypeOfContainingClass(): KaType? {
val containingClass = getStrictParentOfType<KtClassOrObject>() as? KtClass ?: return null
if (containingClass is KtEnumEntry || containingClass.isAnnotation()) return null
@@ -208,14 +208,14 @@ object K2CreateFunctionFromUsageBuilder {
}
if (containingClass.modifierList.hasAbstractModifier() || classSymbol.classKind == KaClassKind.INTERFACE) return classType
// KtType.getAbstractSuperType() does not guarantee it's the closest abstract super type. We can implement it as a
// KaType.getAbstractSuperType() does not guarantee it's the closest abstract super type. We can implement it as a
// breadth-first search, but it can cost a lot in terms of the memory usage.
return classType.getAbstractSuperType()
}
context (KaSession)
private fun KtType.getAbstractSuperType(): KtType? {
fun List<KtType>.firstAbstractEditableType() = firstOrNull { it.hasAbstractDeclaration() && it.canRefactor() }
private fun KaType.getAbstractSuperType(): KaType? {
fun List<KaType>.firstAbstractEditableType() = firstOrNull { it.hasAbstractDeclaration() && it.canRefactor() }
return getDirectSuperTypes().firstAbstractEditableType() ?: getAllSuperTypes().firstAbstractEditableType()
}
@@ -223,7 +223,7 @@ object K2CreateFunctionFromUsageBuilder {
* Returns class or superclass of the express's type if the class or the super class is abstract. Otherwise, returns null.
*/
context (KaSession)
private fun KtExpression.getTypeOfAbstractSuperClass(): KtType? {
private fun KtExpression.getTypeOfAbstractSuperClass(): KaType? {
val type = getKtType() ?: return null
if (type.hasAbstractDeclaration()) return type
return type.getAllSuperTypes().firstOrNull { it.hasAbstractDeclaration() }
@@ -233,7 +233,7 @@ object K2CreateFunctionFromUsageBuilder {
* Returns the receiver's type if it is abstract, or it has an abstract superclass. Otherwise, returns null.
*/
context (KaSession)
private fun KtSimpleNameExpression.getAbstractTypeOfReceiver(): KtType? {
private fun KtSimpleNameExpression.getAbstractTypeOfReceiver(): KaType? {
// If no explicit receiver exists, the containing class can be an implicit receiver.
val receiver = getReceiverExpression() ?: return getAbstractTypeOfContainingClass()
return receiver.getTypeOfAbstractSuperClass()
@@ -244,7 +244,7 @@ object K2CreateFunctionFromUsageBuilder {
return computeImplicitReceiverType(calleeExpression)?.convertToClass()
}
context (KaSession)
private fun computeImplicitReceiverType(calleeExpression: KtSimpleNameExpression): KtType? {
private fun computeImplicitReceiverType(calleeExpression: KtSimpleNameExpression): KaType? {
val implicitReceiver = calleeExpression.containingKtFile.getScopeContextForPosition(calleeExpression).implicitReceivers.firstOrNull()
if (implicitReceiver != null) {
val callable = (calleeExpression.getParentOfTypeAndBranch<KtFunction> { bodyExpression }
@@ -252,7 +252,7 @@ object K2CreateFunctionFromUsageBuilder {
?: return null
if (callable !is KtFunctionLiteral && callable.receiverTypeReference == null) return null
var type: KtType? = implicitReceiver.type
var type: KaType? = implicitReceiver.type
if (type is KaTypeParameterType) {
type = type.getDirectSuperTypes().firstOrNull()
}

View File

@@ -56,7 +56,7 @@ object K2CreateFunctionFromUsageUtil {
fun KtModifierList?.hasAbstractModifier(): Boolean = this?.hasModifier(KtTokens.ABSTRACT_KEYWORD) == true
context (KaSession)
internal fun KtType.hasAbstractDeclaration(): Boolean {
internal fun KaType.hasAbstractDeclaration(): Boolean {
val classSymbol = expandedSymbol ?: return false
if (classSymbol.classKind == KaClassKind.INTERFACE) return true
val declaration = classSymbol.psi as? KtDeclaration ?: return false
@@ -64,7 +64,7 @@ object K2CreateFunctionFromUsageUtil {
}
context (KaSession)
internal fun KtType.canRefactor(): Boolean = expandedSymbol?.psi?.canRefactorElement() == true
internal fun KaType.canRefactor(): Boolean = expandedSymbol?.psi?.canRefactorElement() == true
context (KaSession)
internal fun KtExpression.resolveExpression(): KaSymbol? {
@@ -74,7 +74,7 @@ object K2CreateFunctionFromUsageUtil {
}
context (KaSession)
internal fun KtType.convertToClass(): KtClass? = expandedSymbol?.psi as? KtClass
internal fun KaType.convertToClass(): KtClass? = expandedSymbol?.psi as? KtClass
context (KaSession)
internal fun KtElement.getExpectedKotlinType(): ExpectedKotlinType? {
@@ -117,7 +117,7 @@ object K2CreateFunctionFromUsageUtil {
// Given: `println("a = ${A().foo()}")`
// Expected type of `foo()` is `String`
context (KaSession)
private fun getExpectedTypeByStringTemplateEntry(expression: KtExpression): KtType? {
private fun getExpectedTypeByStringTemplateEntry(expression: KtExpression): KaType? {
var e:PsiElement = expression
while (e is KtExpression && e !is KtStringTemplateEntry) {
val parent = e.parent
@@ -133,7 +133,7 @@ object K2CreateFunctionFromUsageUtil {
// Given: `fun f(): T = expression`
// Expected type of `expression` is `T`
context (KaSession)
private fun getExpectedTypeByFunctionExpressionBody(expression: KtExpression): KtType? {
private fun getExpectedTypeByFunctionExpressionBody(expression: KtExpression): KaType? {
var e:PsiElement = expression
while (e is KtExpression && e !is KtFunction) {
e=e.parent
@@ -146,7 +146,7 @@ object K2CreateFunctionFromUsageUtil {
context (KaSession)
@OptIn(KaExperimentalApi::class)
private fun KtType.convertToJvmType(useSitePosition: PsiElement): JvmType? = asPsiType(useSitePosition, allowErrorTypes = false)
private fun KaType.convertToJvmType(useSitePosition: PsiElement): JvmType? = asPsiType(useSitePosition, allowErrorTypes = false)
context (KaSession)
private fun KtExpression.getClassOfExpressionType(): PsiElement? = when (val symbol = resolveExpression()) {
@@ -234,7 +234,7 @@ object K2CreateFunctionFromUsageUtil {
context (KaSession)
@OptIn(KaExperimentalApi::class)
private fun JvmType.toKtType(useSitePosition: PsiElement): KtType? = when (this) {
private fun JvmType.toKtType(useSitePosition: PsiElement): KaType? = when (this) {
is PsiType -> if (isValid) {
try {
asKtType(useSitePosition)
@@ -243,7 +243,7 @@ object K2CreateFunctionFromUsageUtil {
// Some requests from Java side do not have a type. For example, in `var foo = dep.<caret>foo();`, we cannot guess
// the type of `foo()`. In this case, the request passes "PsiType:null" whose name is "null" as a text. The analysis
// API cannot get a KtType from this weird type. We return `Any?` for this case.
// API cannot get a KaType from this weird type. We return `Any?` for this case.
builtinTypes.nullableAny
}
} else {
@@ -254,7 +254,7 @@ object K2CreateFunctionFromUsageUtil {
}
context (KaSession)
fun ExpectedType.toKtTypeWithNullability(useSitePosition: PsiElement): KtType? {
fun ExpectedType.toKtTypeWithNullability(useSitePosition: PsiElement): KaType? {
val nullability = if (this is ExpectedTypeWithNullability) this.nullability else null
val ktTypeNullability = when (nullability) {
Nullability.NOT_NULL -> KaTypeNullability.NON_NULLABLE
@@ -275,7 +275,7 @@ object K2CreateFunctionFromUsageUtil {
// inspect `type` recursively and call `predicate` on all types inside, return true if all calls returned true
context (KaSession)
private fun accept(type: KtType?, visited: MutableSet<KtType>, predicate: (KtType) -> Boolean) : Boolean {
private fun accept(type: KaType?, visited: MutableSet<KaType>, predicate: (KaType) -> Boolean) : Boolean {
if (type == null || !visited.add(type)) return true
if (!predicate.invoke(type)) return false
return when (type) {
@@ -293,14 +293,14 @@ object K2CreateFunctionFromUsageUtil {
}
context (KaSession)
private fun acceptTypeQualifiers(qualifiers: List<KaClassTypeQualifier>, visited: MutableSet<KtType>, predicate: (KtType) -> Boolean) =
private fun acceptTypeQualifiers(qualifiers: List<KaClassTypeQualifier>, visited: MutableSet<KaType>, predicate: (KaType) -> Boolean) =
qualifiers.flatMap { it.typeArguments }.map { it.type }.all { accept(it, visited, predicate) }
/**
* return [ktType] if it's accessible in the newly created method, or some other sensible type that is (e.g. super type), or null if can't figure out which type to use
*/
context (KaSession)
private fun makeAccessibleInCreationPlace(ktType: KtType, call: KtElement): KtType? {
private fun makeAccessibleInCreationPlace(ktType: KaType, call: KtElement): KaType? {
var type = ktType
do {
if (allTypesInsideAreAccessible(type, call)) return ktType
@@ -310,7 +310,7 @@ object K2CreateFunctionFromUsageUtil {
}
context (KaSession)
private fun allTypesInsideAreAccessible(ktType: KtType, call: KtElement) : Boolean {
private fun allTypesInsideAreAccessible(ktType: KaType, call: KtElement) : Boolean {
fun KtTypeParameter.getOwningTypeParameterOwner(): KtTypeParameterListOwner? {
val parameterList = parent as? KtTypeParameterList ?: return null
return parameterList.parent as? KtTypeParameterListOwner

View File

@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.k2.codeinsight.quickFixes.createFromUsage.K2CreateFunctionFromUsageUtil.convertToClass
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.K2ExtractableSubstringInfo
@@ -62,7 +62,7 @@ object K2CreateParameterFromUsageBuilder {
return CreateParameterFromUsageAction(expression, name, valVar, namedDeclaration)
}
}
fun generateCreateParameterActionForComponentFunctionMissing(arg: PsiElement, destructingType: KtType): IntentionAction? {
fun generateCreateParameterActionForComponentFunctionMissing(arg: PsiElement, destructingType: KaType): IntentionAction? {
val decl = arg.findParentOfType<KtDestructuringDeclaration>(strict = false) ?: return null
val lastEntry = decl.entries.lastOrNull()
val name = lastEntry?.name?:return null
@@ -99,7 +99,7 @@ object K2CreateParameterFromUsageBuilder {
override fun getFamilyName(): String = KotlinBundle.message("fix.create.from.usage.family")
context(KaSession)
private fun getExpectedType(expression: KtExpression): KtType {
private fun getExpectedType(expression: KtExpression): KaType {
if (expression is KtDestructuringDeclarationEntry) {
val type = expression.getReturnKtType()
return if (type is KaErrorType) builtinTypes.ANY else type

View File

@@ -150,7 +150,7 @@ private val ITERABLE_CLASS_IDS: Set<ClassId> = setOf(
)
context(KaSession)
internal fun canBeIterated(type: KtType, checkNullability: Boolean = true): Boolean {
internal fun canBeIterated(type: KaType, checkNullability: Boolean = true): Boolean {
return when (type) {
is KaFlexibleType -> canBeIterated(type.lowerBoundIfFlexible())
is KaIntersectionType -> type.conjuncts.all { canBeIterated(it) }

View File

@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisFromWriteAct
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisFromWriteAction
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.util.application.isUnitTestMode
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
@@ -62,7 +62,7 @@ internal object StatementFilter : (KtExpression) -> Boolean {
}
}
internal class ExpressionTypeFilter(val predicate: KaSession.(KtType) -> Boolean) : (KtExpression) -> Boolean {
internal class ExpressionTypeFilter(val predicate: KaSession.(KaType) -> Boolean) : (KtExpression) -> Boolean {
@OptIn(KaAllowAnalysisOnEdt::class)
override fun invoke(expression: KtExpression): Boolean {
allowAnalysisOnEdt {

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.codeInsight.postfix
import com.intellij.codeInsight.template.postfix.templates.StringBasedPostfixTemplate
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.psi.KtExpression
@@ -40,6 +40,6 @@ private val ARRAY_CLASS_FQ_NAMES: Set<FqNameUnsafe> = buildSet {
add(StandardNames.FqNames.uLongArrayFqName.toUnsafe())
}
private fun KtType.canSpread(): Boolean {
private fun KaType.canSpread(): Boolean {
return this is KaClassType && classId.asSingleFqName().toUnsafe() in ARRAY_CLASS_FQ_NAMES
}

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaClassKind
import org.jetbrains.kotlin.analysis.api.symbols.KaEnumEntrySymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
@@ -144,7 +144,7 @@ private sealed class CaseBranch {
class Instance(val classId: ClassId) : CaseBranch()
}
private fun isSealedType(type: KtType): Boolean {
private fun isSealedType(type: KaType): Boolean {
if (type is KaClassType) {
val symbol = type.symbol
if (symbol is KaNamedClassOrObjectSymbol) {

View File

@@ -4,7 +4,7 @@ package org.jetbrains.kotlin.idea.codeInsight.postfix
import com.intellij.codeInsight.template.postfix.templates.StringBasedPostfixTemplate
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.psi.*
internal class KotlinWithPostfixTemplate : StringBasedPostfixTemplate {
@@ -39,6 +39,6 @@ private object WhenTargetFilter : (KtExpression) -> Boolean {
}
context(KaSession)
private fun isWithTargetType(type: KtType): Boolean {
private fun isWithTargetType(type: KaType): Boolean {
return !type.isUnit && !type.isMarkedNullable && !type.isPrimitive
}

View File

@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KaClassTypeQualifierRenderer
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtExpression
@@ -29,7 +29,7 @@ internal fun getCommentText(comment: PsiComment): String {
context(KaSession)
@OptIn(KaExperimentalApi::class)
internal fun KtType.renderNames(): Array<String> = arrayOf(
internal fun KaType.renderNames(): Array<String> = arrayOf(
render(KtTypeRendererForSource.WITH_SHORT_NAMES.with {
classIdRenderer = KaClassTypeQualifierRenderer.WITH_SHORT_NAMES
}, Variance.INVARIANT),
@@ -46,7 +46,7 @@ internal val MatchingHandler.withinHierarchyTextFilterSet: Boolean
get() = this is SubstitutionHandler && (this.isSubtype || this.isStrictSubtype)
context(KaSession)
fun KtExpression.findDispatchReceiver(): KtType? {
fun KtExpression.findDispatchReceiver(): KaType? {
val symbol = resolveToCall()?.successfulFunctionCallOrNull()?.partiallyAppliedSymbol?.symbol ?: return null
val containingClass = symbol.containingSymbol as? KaClassSymbol ?: return null
val classId = containingClass.classId ?: return null

View File

@@ -9,7 +9,7 @@ import com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.k2.codeinsight.structuralsearch.renderNames
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.*
@@ -52,7 +52,7 @@ class KotlinExprTypePredicate(
}
context(KaSession)
fun match(type: KtType): Boolean {
fun match(type: KaType): Boolean {
val typesToTest = mutableListOf(type)
if (withinHierarchy) typesToTest.addAll(type.getAllSuperTypes())
if (regex) {

View File

@@ -8,7 +8,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFlexibleType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.psi.KtExpression
@@ -55,7 +55,7 @@ private fun getClassType(declaration: KtDestructuringDeclaration): KaClassType?
return toNonErrorClassType(type)
}
private fun toNonErrorClassType(type: KtType?): KaClassType? {
private fun toNonErrorClassType(type: KaType?): KaClassType? {
return when (type) {
is KaClassType -> type
is KaFlexibleType -> type.lowerBound as? KaClassType

View File

@@ -7,7 +7,7 @@ import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisFromWriteAct
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisFromWriteAction
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.lexer.KtSingleValueToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -28,7 +28,7 @@ object NegatedBinaryExpressionSimplificationUtils {
@OptIn(KaAllowAnalysisFromWriteAction::class)
allowAnalysisFromWriteAction {
analyze(expression) {
fun KtType?.isFloatingPoint() = this != null && (isFloat || isDouble)
fun KaType?.isFloatingPoint() = this != null && (isFloat || isDouble)
return !expression.left?.getKtType().isFloatingPoint() && !expression.right?.getKtType().isFloatingPoint()
}
}

View File

@@ -45,7 +45,7 @@ fun addTypeArguments(element: KtCallElement, context: String, project: Project)
}
context(KaSession)
private fun KtType.containsErrorType(): Boolean = when (this) {
private fun KaType.containsErrorType(): Boolean = when (this) {
is KaErrorType -> true
is KaFunctionType -> {
(receiverType?.containsErrorType() == true)

View File

@@ -6,7 +6,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.singleFunctionCallOrNull
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.symbols.KaTypeParameterSymbol
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
import org.jetbrains.kotlin.psi.KtElement
@@ -26,7 +26,7 @@ object TypeParameterUtils {
}
context(KaSession)
fun typeReferencesTypeParameter(typeParameter: KaTypeParameterSymbol, type: KtType): Boolean {
fun typeReferencesTypeParameter(typeParameter: KaTypeParameterSymbol, type: KaType): Boolean {
return when (type) {
is KaTypeParameterType -> type.symbol == typeParameter
is KaClassType -> type.typeArguments.mapNotNull { it.type }.any { typeReferencesTypeParameter(typeParameter, it) }

View File

@@ -12,17 +12,17 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaClassKind
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFlexibleType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
context(KaSession)
fun KtType.isNullableAnyType() = isAny && isMarkedNullable
fun KaType.isNullableAnyType() = isAny && isMarkedNullable
context(KaSession)
fun KtType.isNonNullableBooleanType() = isBoolean && !isMarkedNullable
fun KaType.isNonNullableBooleanType() = isBoolean && !isMarkedNullable
context(KaSession)
fun KtType.isEnum(): Boolean {
fun KaType.isEnum(): Boolean {
if (this !is KaClassType) return false
val classSymbol = symbol
return classSymbol is KaClassSymbol && classSymbol.classKind == KaClassKind.ENUM_CLASS

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.fixes.AbstractKotlinApplicableQuickFix
import org.jetbrains.kotlin.idea.compilerPlugin.parcelize.KotlinParcelizeBundle
import org.jetbrains.kotlin.idea.compilerPlugin.parcelize.quickfixes.ParcelMigrateToParcelizeQuickFixApplicator
@@ -41,7 +41,7 @@ class K2ParcelMigrateToParcelizeQuickFix(clazz: KtClass) : AbstractKotlinApplica
private object Resolver : ParcelMigrateToParcelizeResolver<KaSession> {
context(KaSession)
private val KtType.classId: ClassId?
private val KaType.classId: ClassId?
get() = expandedSymbol?.classId
context(KaSession)
@@ -64,7 +64,7 @@ class K2ParcelMigrateToParcelizeQuickFix(clazz: KtClass) : AbstractKotlinApplica
}
context(KaSession)
private fun KaClassLikeSymbol.buildStarProjectedType(): KtType =
private fun KaClassLikeSymbol.buildStarProjectedType(): KaType =
buildClassType(this@buildStarProjectedType) {
repeat(typeParameters.size) {
argument(KtStarTypeProjection(token))
@@ -72,7 +72,7 @@ class K2ParcelMigrateToParcelizeQuickFix(clazz: KtClass) : AbstractKotlinApplica
}
context(KaSession)
private fun KtType.hasSuperTypeClassId(superTypeClassId: ClassId): Boolean {
private fun KaType.hasSuperTypeClassId(superTypeClassId: ClassId): Boolean {
val superClassSymbol = getClassOrObjectSymbolByClassId(superTypeClassId) ?: return false
return isSubTypeOf(superClassSymbol.buildStarProjectedType())
}

View File

@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaPossibleMultiplatformSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolKind
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.collectReceiverTypesForExplicitReceiverExpression
import org.jetbrains.kotlin.idea.base.analysis.api.utils.isJavaSourceOrLibrary
import org.jetbrains.kotlin.idea.base.analysis.api.utils.isPossiblySubTypeOf
@@ -114,14 +114,14 @@ internal open class FirCallableCompletionContributor(
protected data class CallableWithMetadataForCompletion(
private val _signature: KaCallableSignature<*>,
private val _explicitReceiverTypeHint: KtType?,
private val _explicitReceiverTypeHint: KaType?,
val options: CallableInsertionOptions,
val symbolOrigin: CompletionSymbolOrigin,
) : KaLifetimeOwner {
override val token: KaLifetimeToken
get() = _signature.token
val signature: KaCallableSignature<*> get() = withValidityAssertion { _signature }
val explicitReceiverTypeHint: KtType? get() = withValidityAssertion { _explicitReceiverTypeHint }
val explicitReceiverTypeHint: KaType? get() = withValidityAssertion { _explicitReceiverTypeHint }
}
context(KaSession)
@@ -338,12 +338,12 @@ internal open class FirCallableCompletionContributor(
context(KaSession)
protected fun collectDotCompletionForCallableReceiver(
typesOfPossibleReceiver: List<KtType>,
typesOfPossibleReceiver: List<KaType>,
visibilityChecker: CompletionVisibilityChecker,
scopeContext: KaScopeContext,
extensionChecker: KaCompletionExtensionCandidateChecker?,
sessionParameters: FirCompletionSessionParameters,
explicitReceiverTypeHint: KtType? = null
explicitReceiverTypeHint: KaType? = null
): Sequence<CallableWithMetadataForCompletion> = sequence {
val nonExtensionMembers = typesOfPossibleReceiver.flatMap { typeOfPossibleReceiver ->
collectNonExtensionsForType(
@@ -428,7 +428,7 @@ internal open class FirCallableCompletionContributor(
context(KaSession)
private fun collectTopLevelExtensionsFromIndexAndResolveExtensionScope(
receiverTypes: List<KtType>,
receiverTypes: List<KaType>,
extensionChecker: KaCompletionExtensionCandidateChecker?,
visibilityChecker: CompletionVisibilityChecker,
sessionParameters: FirCompletionSessionParameters,
@@ -453,7 +453,7 @@ internal open class FirCallableCompletionContributor(
extensionChecker: KaCompletionExtensionCandidateChecker?,
visibilityChecker: CompletionVisibilityChecker,
sessionParameters: FirCompletionSessionParameters,
explicitReceiverTypes: List<KtType>? = null,
explicitReceiverTypes: List<KaType>? = null,
): Sequence<Pair<KtCallableSignatureWithContainingScopeKind, CallableInsertionOptions>> {
val receiversTypes = explicitReceiverTypes ?: scopeContext.implicitReceivers.map { it.type }
@@ -466,7 +466,7 @@ internal open class FirCallableCompletionContributor(
context(KaSession)
private fun collectSuitableExtensions(
scope: KaScope,
receiverTypes: List<KtType>,
receiverTypes: List<KaType>,
hasSuitableExtensionReceiver: KaCompletionExtensionCandidateChecker?,
visibilityChecker: CompletionVisibilityChecker,
sessionParameters: FirCompletionSessionParameters,
@@ -511,7 +511,7 @@ internal open class FirCallableCompletionContributor(
scopeKind: KaScopeKind,
isImportDefinitelyNotRequired: Boolean = false,
options: CallableInsertionOptions = getOptions(signature, isImportDefinitelyNotRequired),
explicitReceiverTypeHint: KtType? = null,
explicitReceiverTypeHint: KaType? = null,
): CallableWithMetadataForCompletion {
val symbolOrigin = CompletionSymbolOrigin.Scope(scopeKind)
return CallableWithMetadataForCompletion(signature, explicitReceiverTypeHint, options, symbolOrigin)
@@ -522,7 +522,7 @@ internal open class FirCallableCompletionContributor(
signature: KaCallableSignature<*>,
symbolOrigin: CompletionSymbolOrigin,
options: CallableInsertionOptions = getOptions(signature),
explicitReceiverTypeHint: KtType? = null,
explicitReceiverTypeHint: KaType? = null,
) = CallableWithMetadataForCompletion(signature, explicitReceiverTypeHint, options, symbolOrigin)
context(KaSession)
@@ -564,7 +564,7 @@ internal open class FirCallableCompletionContributor(
context(KaSession)
private fun Sequence<CallableWithMetadataForCompletion>.filterOutShadowedCallables(
expectedType: KtType?,
expectedType: KaType?,
): Sequence<CallableWithMetadataForCompletion> =
sequence {
val shadowedCallablesFilter = ShadowedCallablesFilter()
@@ -592,7 +592,7 @@ internal open class FirCallableCompletionContributor(
context(KaSession)
private fun Sequence<CallableWithMetadataForCompletion>.filterIfInsideAnnotationEntryArgument(
position: PsiElement,
expectedType: KtType?,
expectedType: KaType?,
): Sequence<CallableWithMetadataForCompletion> {
if (!position.isInsideAnnotationEntryArgumentList()) return this

View File

@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.signatures.KaCallableSignature
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.KtSymbolFromIndexProvider
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferencesInRange
import org.jetbrains.kotlin.idea.completion.*
@@ -71,7 +71,7 @@ internal abstract class FirCompletionContributorBase<C : KotlinRawPositionContex
{ name -> !name.isSpecial && prefixMatcher.prefixMatches(name.identifier) }
context(KaSession)
protected fun addSymbolToCompletion(expectedType: KtType?, symbol: KaSymbol) {
protected fun addSymbolToCompletion(expectedType: KaType?, symbol: KaSymbol) {
if (symbol !is KaNamedSymbol) return
lookupElementFactory
@@ -107,7 +107,7 @@ internal abstract class FirCompletionContributorBase<C : KotlinRawPositionContex
options: CallableInsertionOptions,
symbolOrigin: CompletionSymbolOrigin,
priority: ItemPriority? = null,
explicitReceiverTypeHint: KtType? = null,
explicitReceiverTypeHint: KaType? = null,
) {
val symbol = signature.symbol
val name = when (symbol) {

View File

@@ -7,7 +7,7 @@ import com.intellij.openapi.progress.ProgressManager
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.completion.FirCompletionSessionParameters
import org.jetbrains.kotlin.idea.completion.ItemPriority
import org.jetbrains.kotlin.idea.completion.context.FirBasicCompletionContext
@@ -120,7 +120,7 @@ internal class FirDeclarationFromUnresolvedNameContributor(
}
context(KaSession)
private fun getReceiverType(symbol: KaCallableSymbol): KtType? {
private fun getReceiverType(symbol: KaCallableSymbol): KaType? {
return symbol.receiverType ?: (symbol as? KaCallableSymbol)?.dispatchReceiverType
}

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.KaFunctionCall
import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.signatures.KaVariableSignature
import org.jetbrains.kotlin.analysis.api.symbols.KaValueParameterSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.CallParameterInfoProvider
import org.jetbrains.kotlin.idea.base.analysis.api.utils.collectCallCandidates
import org.jetbrains.kotlin.idea.completion.FirCompletionSessionParameters
@@ -86,7 +86,7 @@ internal class FirNamedArgumentCompletionContributor(basicContext: FirBasicCompl
*/
private data class NamedArgumentInfo(
val name: Name,
val indexedTypes: List<IndexedValue<KtType>>
val indexedTypes: List<IndexedValue<KaType>>
)
context(KaSession)
@@ -97,7 +97,7 @@ internal class FirNamedArgumentCompletionContributor(basicContext: FirBasicCompl
): List<NamedArgumentInfo> {
val argumentsBeforeCurrent = callElement.valueArgumentList?.arguments?.take(currentArgumentIndex) ?: return emptyList()
val nameToTypes = mutableMapOf<Name, MutableSet<IndexedValue<KtType>>>()
val nameToTypes = mutableMapOf<Name, MutableSet<IndexedValue<KaType>>>()
for (candidate in candidates) {
val indexedParameterCandidates = collectNotUsedIndexedParameterCandidates(callElement, candidate, argumentsBeforeCurrent)
indexedParameterCandidates.forEach { (index, parameter) ->

View File

@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.analysis.api.signatures.KaFunctionSignature
import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithModality
import org.jetbrains.kotlin.analysis.api.types.KaIntersectionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.idea.completion.FirCompletionSessionParameters
@@ -38,13 +38,13 @@ internal class FirSuperMemberCompletionContributor(
priority: Int
) : FirCompletionContributorBase<KotlinSuperReceiverNameReferencePositionContext>(basicContext, priority) {
private data class CallableInfo(
private val _type: KtType,
private val _type: KaType,
private val _signature: KaCallableSignature<*>,
val scopeKind: KaScopeKind
) : KaLifetimeOwner {
override val token: KaLifetimeToken
get() = _signature.token
val type: KtType get() = withValidityAssertion { _type }
val type: KaType get() = withValidityAssertion { _type }
val signature: KaCallableSignature<*> get() = withValidityAssertion { _signature }
}
@@ -71,7 +71,7 @@ internal class FirSuperMemberCompletionContributor(
context(KaSession)
private fun getSymbolsAndNamesNeedDisambiguation(
superTypes: List<KtType>,
superTypes: List<KaType>,
visibilityChecker: CompletionVisibilityChecker,
sessionParameters: FirCompletionSessionParameters,
): Pair<List<CallableInfo>, Set<Name>> {
@@ -108,7 +108,7 @@ internal class FirSuperMemberCompletionContributor(
context(KaSession)
private fun getNonExtensionsMemberSymbols(
receiverType: KtType,
receiverType: KaType,
visibilityChecker: CompletionVisibilityChecker,
sessionParameters: FirCompletionSessionParameters,
): Sequence<CallableInfo> {
@@ -222,7 +222,7 @@ internal class FirSuperMemberCompletionContributor(
context(KaSession)
private fun wrapWithDisambiguationIfNeeded(
insertionStrategy: CallableInsertionStrategy,
superType: KtType,
superType: KaType,
callableSignature: KaCallableSignature<*>,
namesNeedDisambiguation: Set<Name>,
superReceiver: KtSuperExpression

View File

@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.analysis.api.components.KaScopeContext
import org.jetbrains.kotlin.analysis.api.scopes.KaScope
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester
@@ -269,7 +269,7 @@ internal class FirVariableOrParameterNameWithTypeCompletionContributor(
context(KaSession)
private fun typeIsVisible(
type: KtType,
type: KaType,
visibilityChecker: CompletionVisibilityChecker,
availableTypeParameters: Set<KaTypeParameterSymbol> = emptySet()
): Boolean = when (type) {

View File

@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithTypeParameters
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.idea.base.analysis.api.utils.resolveToExpandedSymbol
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferencesInRange
@@ -87,14 +87,14 @@ internal class FirWhenWithSubjectConditionContributor(
}
context(KaSession)
private fun getClassSymbol(subjectType: KtType): KaNamedClassOrObjectSymbol? {
private fun getClassSymbol(subjectType: KaType): KaNamedClassOrObjectSymbol? {
val classType = subjectType as? KaClassType
return classType?.symbol as? KaNamedClassOrObjectSymbol
}
context(KaSession)
private fun addNullIfWhenExpressionCanReturnNull(context: WeighingContext, type: KtType?) {
private fun addNullIfWhenExpressionCanReturnNull(context: WeighingContext, type: KaType?) {
if (type?.canBeNull == true) {
val lookupElement = createKeywordElement(keyword = KtTokens.NULL_KEYWORD.value)
applyWeighsAndAddElementToSink(context, lookupElement, symbolWithOrigin = null)

View File

@@ -173,7 +173,7 @@ internal object CallableMetadataProvider {
}
context(KaSession)
private fun getFlattenedActualReceiverTypes(context: WeighingContext): List<List<KtType>> {
private fun getFlattenedActualReceiverTypes(context: WeighingContext): List<List<KaType>> {
val actualExplicitReceiverTypes = context.explicitReceiver?.let { receiver ->
val referencedClass = getReferencedClassInCallableReferenceExpression(receiver) ?: getQualifierClassInKDocName(receiver)
val typesFromClass = referencedClass?.let { listOfNotNull(it, it.companionObject).map { buildClassType(it) } }
@@ -191,13 +191,13 @@ internal object CallableMetadataProvider {
get() = (this as? KaNamedClassOrObjectSymbol)?.companionObject
context(KaSession)
private fun KtType.flatten(): List<KtType> = when (this) {
private fun KaType.flatten(): List<KaType> = when (this) {
is KaIntersectionType -> conjuncts.flatMap { it.flatten() }
else -> listOf(this)
}
context(KaSession)
private fun KtExpression.getTypeWithCorrectedNullability(): KtType? {
private fun KtExpression.getTypeWithCorrectedNullability(): KaType? {
val isSafeCall = parent is KtSafeQualifiedExpression
return getKtType()?.applyIf(isSafeCall) { withNullability(KaTypeNullability.NON_NULLABLE) }
}
@@ -232,21 +232,21 @@ internal object CallableMetadataProvider {
}
context(KaSession)
private fun buildClassType(symbol: KaClassLikeSymbol): KtType = buildClassType(symbol) {
private fun buildClassType(symbol: KaClassLikeSymbol): KaType = buildClassType(symbol) {
repeat(symbol.typeParameters.size) {
argument(KtStarTypeProjection(token))
}
}
context(KaSession)
private fun KtType.replaceTypeArgumentsWithStarProjections(): KtType? =
private fun KaType.replaceTypeArgumentsWithStarProjections(): KaType? =
expandedSymbol?.let { buildClassType(it) }?.withNullability(nullability)
context(KaSession)
private fun callableWeightByReceiver(
symbol: KaCallableSymbol,
flattenedActualReceiverTypes: List<List<KtType>>,
expectedReceiverType: KtType,
flattenedActualReceiverTypes: List<List<KaType>>,
expectedReceiverType: KaType,
): CallableMetadata {
var allReceiverTypesMatch = true
var bestMatchIndex: Int? = null
@@ -283,8 +283,8 @@ internal object CallableMetadataProvider {
context(KaSession)
private fun callableWeightKindByReceiverType(
symbol: KaCallableSymbol,
actualReceiverType: KtType,
expectedReceiverType: KtType,
actualReceiverType: KaType,
expectedReceiverType: KaType,
): CallableKind? = when {
actualReceiverType.isEqualTo(expectedReceiverType) -> when {
isExtensionCallOnTypeParameterReceiver(symbol) -> CallableKind.TYPE_PARAMETER_EXTENSION

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolKind
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.completion.checkers.ApplicableExtension
import org.jetbrains.kotlin.idea.completion.lookups.CallableInsertionOptions
import org.jetbrains.kotlin.idea.completion.lookups.CallableInsertionStrategy
@@ -152,7 +152,7 @@ internal class ShadowedCallablesFilter {
context(KaSession)
fun sortExtensions(
extensions: Collection<ApplicableExtension>,
receiversFromContext: List<KtType>
receiversFromContext: List<KaType>
): Collection<ApplicableExtension> {
if (extensions.isEmpty()) return emptyList()
@@ -196,7 +196,7 @@ internal class ShadowedCallablesFilter {
companion object {
context(KaSession)
fun create(type: KtType): ReceiverId? {
fun create(type: KaType): ReceiverId? {
val expandedClassSymbol = type.expandedSymbol ?: return null
val name = expandedClassSymbol.name ?: return null
@@ -303,7 +303,7 @@ private class FunctionLikeSimplifiedSignature(
override val name: Name,
override val containerFqName: FqName?,
private val requiredTypeArgumentsCount: Int,
private val valueParameterTypes: Lazy<List<KtType>>,
private val valueParameterTypes: Lazy<List<KaType>>,
private val varargValueParameterIndices: List<Int>,
private val analysisSession: KaSession,
) : SimplifiedSignature() {
@@ -324,7 +324,7 @@ private class FunctionLikeSimplifiedSignature(
areValueParameterTypesEqualTo(other)
/**
* We need to use semantic type equality instead of the default structural equality of [KtType] to check if two signatures overlap.
* We need to use semantic type equality instead of the default structural equality of [KaType] to check if two signatures overlap.
*/
private fun areValueParameterTypesEqualTo(other: FunctionLikeSimplifiedSignature): Boolean {
val types1 = other.valueParameterTypes.value

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.components.KaScopeContext
import org.jetbrains.kotlin.analysis.api.scopes.KaScope
import org.jetbrains.kotlin.analysis.api.signatures.KaCallableSignature
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.completion.FirCompletionSessionParameters
import org.jetbrains.kotlin.idea.completion.checkers.CompletionVisibilityChecker
@@ -94,7 +94,7 @@ internal fun collectStaticAndTopLevelNonExtensionsFromScopeContext(
context(KaSession)
@OptIn(KaExperimentalApi::class)
internal fun collectNonExtensionsForType(
type: KtType,
type: KaType,
visibilityChecker: CompletionVisibilityChecker,
scopeNameFilter: (Name) -> Boolean,
sessionParameters: FirCompletionSessionParameters,
@@ -128,7 +128,7 @@ private val KaSyntheticJavaPropertySymbol.getterAndUnitSetter: List<KaCallableSy
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun Sequence<KaCallableSignature<*>>.filterOutJavaGettersAndSetters(
type: KtType,
type: KaType,
visibilityChecker: CompletionVisibilityChecker,
scopeNameFilter: (Name) -> Boolean,
symbolFilter: (KaCallableSymbol) -> Boolean

View File

@@ -7,7 +7,7 @@ import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.completion.createKeywordElement
import org.jetbrains.kotlin.idea.completion.createKeywordElementWithSpace
import org.jetbrains.kotlin.idea.completion.implCommon.keywords.isInlineFunctionCall
@@ -69,7 +69,7 @@ internal object ReturnKeywordHandler : CompletionKeywordHandler<KaSession>(KtTok
context(KaSession)
private fun addAllReturnVariants(
result: MutableList<LookupElement>,
returnType: KtType,
returnType: KaType,
label: Name?,
isLikelyInPositionForReturn: Boolean = false
) {
@@ -89,7 +89,7 @@ internal object ReturnKeywordHandler : CompletionKeywordHandler<KaSession>(KtTok
}
context(KaSession)
private fun getExpressionsToReturnByType(returnType: KtType): List<ExpressionTarget> = buildList {
private fun getExpressionsToReturnByType(returnType: KaType): List<ExpressionTarget> = buildList {
if (returnType.canBeNull) {
add(ExpressionTarget("null", addToLookupElementTail = false))
}

View File

@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.signatures.KaVariableSignature
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.types.Variance
internal object CompletionShortNamesRenderer {
@@ -58,8 +58,8 @@ internal object CompletionShortNamesRenderer {
context(KaSession)
@KaExperimentalApi
internal fun KtType.renderNonErrorOrUnsubstituted(
unsubstituted: KtType,
internal fun KaType.renderNonErrorOrUnsubstituted(
unsubstituted: KaType,
renderer: KtTypeRenderer = CompletionShortNamesRenderer.rendererVerbose
): String {
val typeToRender = this.takeUnless { it is KaErrorType } ?: unsubstituted

View File

@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaClassLikeSymbol
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.completion.impl.k2.KotlinCompletionImplK2Bundle
import org.jetbrains.kotlin.idea.completion.lookups.CompletionShortNamesRenderer.renderFunctionParameters
import org.jetbrains.kotlin.idea.completion.lookups.CompletionShortNamesRenderer.renderFunctionalTypeParameters
@@ -71,7 +71,7 @@ internal object TailTextProvider {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun StringBuilder.renderReceiverType(receiverType: KtType) {
private fun StringBuilder.renderReceiverType(receiverType: KaType) {
val renderedType = receiverType.render(CompletionShortNamesRenderer.rendererVerbose, position = Variance.INVARIANT)
append(KotlinCompletionImplK2Bundle.message("presentation.tail.for.0", renderedType))
}

View File

@@ -38,7 +38,7 @@ internal class FunctionLookupElementFactory {
name: Name,
signature: KaFunctionSignature<*>,
options: CallableInsertionOptions,
expectedType: KtType? = null,
expectedType: KaType? = null,
): LookupElementBuilder {
val insertEmptyLambda = insertLambdaBraces(signature, options)
val lookupObject = FunctionCallLookupObject(
@@ -96,7 +96,7 @@ object FunctionInsertionHelper {
context(KaSession)
fun functionCanBeCalledWithoutExplicitTypeArguments(
symbol: KaFunctionSymbol,
expectedType: KtType?
expectedType: KaType?
): Boolean {
if (symbol.typeParameters.isEmpty()) return true
@@ -117,7 +117,7 @@ object FunctionInsertionHelper {
* ```
* we can't rely on the inference from `handler`, because lambda input types may not be declared explicitly.
*/
fun collectPotentiallyInferredTypes(type: KtType, onlyCollectReturnTypeOfFunctionalType: Boolean) {
fun collectPotentiallyInferredTypes(type: KaType, onlyCollectReturnTypeOfFunctionalType: Boolean) {
when (type) {
is KaTypeParameterType -> {
val typeParameterSymbol = type.symbol

View File

@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.signatures.KaFunctionSignature
import org.jetbrains.kotlin.analysis.api.signatures.KaVariableSignature
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.completion.impl.k2.ImportStrategyDetector
import org.jetbrains.kotlin.idea.completion.impl.k2.lookups.factories.NamedArgumentLookupElementFactory
import org.jetbrains.kotlin.idea.completion.impl.k2.lookups.factories.TypeLookupElementFactory
@@ -38,7 +38,7 @@ class KotlinFirLookupElementFactory {
symbol: KaNamedSymbol,
importStrategyDetector: ImportStrategyDetector,
importingStrategy: ImportStrategy? = null,
expectedType: KtType? = null,
expectedType: KaType? = null,
): LookupElement {
return when (symbol) {
is KaCallableSymbol -> createCallableLookupElement(
@@ -61,7 +61,7 @@ class KotlinFirLookupElementFactory {
name: Name,
signature: KaCallableSignature<*>,
options: CallableInsertionOptions,
expectedType: KtType? = null,
expectedType: KaType? = null,
): LookupElementBuilder {
return when (signature) {
is KaFunctionSignature<*> -> functionLookupElementFactory.createLookup(name, signature, options, expectedType)
@@ -73,14 +73,14 @@ class KotlinFirLookupElementFactory {
packagePartLookupElementFactory.createPackagePartLookupElement(packagePartFqName)
context(KaSession)
fun createNamedArgumentLookupElement(name: Name, types: List<KtType>): LookupElement =
fun createNamedArgumentLookupElement(name: Name, types: List<KaType>): LookupElement =
namedArgumentLookupElementFactory.createNamedArgumentLookup(name, types)
fun createNamedArgumentWithValueLookupElement(name: Name, value: String): LookupElement =
namedArgumentLookupElementFactory.createNamedArgumentWithValueLookup(name, value)
context(KaSession)
fun createTypeLookupElement(type: KtType): LookupElement? =
fun createTypeLookupElement(type: KaType): LookupElement? =
typeLookupElementFactory.createLookup(type)
context(KaSession)

View File

@@ -5,7 +5,7 @@ import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementBuilder
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.completion.implCommon.handlers.NamedArgumentInsertHandler
import org.jetbrains.kotlin.idea.completion.lookups.CompletionShortNamesRenderer
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.types.Variance
internal class NamedArgumentLookupElementFactory {
context(KaSession)
@OptIn(KaExperimentalApi::class)
fun createNamedArgumentLookup(name: Name, types: List<KtType>): LookupElement {
fun createNamedArgumentLookup(name: Name, types: List<KaType>): LookupElement {
val typeText = types.singleOrNull()?.render(CompletionShortNamesRenderer.rendererVerbose, position = Variance.INVARIANT) ?: "..."
val nameString = name.asString()
return LookupElementBuilder.create(NamedArgumentLookupObject(name), "$nameString =")

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaClassLikeSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaClassifierSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaTypeParameterSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeParameterType
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
import org.jetbrains.kotlin.idea.KotlinIcons
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.types.Variance
class TypeLookupElementFactory {
context(KaSession)
@OptIn(KaExperimentalApi::class)
fun createLookup(type: KtType): LookupElement? {
fun createLookup(type: KaType): LookupElement? {
val renderedType = type.render(TYPE_RENDERING_OPTIONS_SHORT_NAMES, position = Variance.INVARIANT)
val lookupObject = TypeLookupObject(type.render(TYPE_RENDERING_OPTIONS, position = Variance.INVARIANT))
@@ -68,7 +68,7 @@ class TypeLookupElementFactory {
.withTailText(tailText)
}
private fun KtType.getSymbolIfTypeParameterOrUsualClass(): KaClassifierSymbol? = when (this) {
private fun KaType.getSymbolIfTypeParameterOrUsualClass(): KaClassifierSymbol? = when (this) {
is KaTypeParameterType -> symbol
is KaUsualClassType -> symbol
else -> null

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.components.DefaultTypeClassIds
import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.base.analysis.api.utils.isPossiblySubTypeOf
import org.jetbrains.kotlin.idea.completion.KeywordLookupObject
@@ -52,7 +52,7 @@ internal object ExpectedTypeWeigher {
context(KaSession)
private fun matchesExpectedType(
symbol: KaSymbol,
expectedType: KtType?
expectedType: KaType?
) = when {
expectedType == null -> MatchesExpectedType.NON_TYPABLE
symbol is KaClassSymbol && expectedType.expandedSymbol?.let { symbol.isSubClassOf(it) } == true ->
@@ -78,7 +78,7 @@ internal object ExpectedTypeWeigher {
companion object {
context(KaSession)
fun matches(actualType: KtType, expectedType: KtType): MatchesExpectedType = when {
fun matches(actualType: KaType, expectedType: KaType): MatchesExpectedType = when {
actualType isPossiblySubTypeOf expectedType -> MATCHES
actualType.withNullability(KaTypeNullability.NON_NULLABLE) isPossiblySubTypeOf expectedType -> MATCHES_WITHOUT_NULLABILITY
else -> NOT_MATCHES

View File

@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
import org.jetbrains.kotlin.analysis.api.symbols.getSymbolOfType
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.idea.base.facet.platform.platform
import org.jetbrains.kotlin.idea.base.projectStructure.compositeAnalysis.findAnalyzerServices
@@ -42,7 +42,7 @@ internal class WeighingContext private constructor(
val languageVersionSettings: LanguageVersionSettings,
val explicitReceiver: KtElement?,
private val positionInFakeCompletionFile: PsiElement,
private val myExpectedType: KtType?,
private val myExpectedType: KaType?,
private val myImplicitReceivers: List<KaImplicitReceiver>,
val contextualSymbolsCache: ContextualSymbolsCache,
val importableFqNameClassifier: ImportableFqNameClassifier,
@@ -71,7 +71,7 @@ internal class WeighingContext private constructor(
operator fun contains(name: Name): Boolean = withValidityAssertion { name in symbolsContainingPosition }
}
val expectedType: KtType?
val expectedType: KaType?
get() = withValidityAssertion {
myExpectedType
}
@@ -98,7 +98,7 @@ internal class WeighingContext private constructor(
fun createWeighingContext(
basicContext: FirBasicCompletionContext,
receiver: KtElement?,
expectedType: KtType?,
expectedType: KaType?,
implicitReceivers: List<KaImplicitReceiver>,
positionInFakeCompletionFile: PsiElement,
symbolsToSkip: Set<KaSymbol> = emptySet(),

View File

@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.renderer.declarations.KaDeclarationRend
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KaDeclarationRendererForSource
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callables.KaCallableSignatureRenderer
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
import org.jetbrains.kotlin.lexer.KtKeywordToken
@@ -29,7 +29,7 @@ object K2StatisticsInfoProvider {
modifiersRenderer = modifiersRenderer.with { keywordsRenderer = KaKeywordsRenderer.NONE }
returnTypeFilter = object : KaCallableReturnTypeFilter {
override fun shouldRenderReturnType(analysisSession: KaSession, type: KtType, symbol: KaCallableSymbol): Boolean {
override fun shouldRenderReturnType(analysisSession: KaSession, type: KaType, symbol: KaCallableSymbol): Boolean {
return symbol !is KaFunctionSymbol
}
}

View File

@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.annotations.hasAnnotation
import org.jetbrains.kotlin.analysis.api.symbols.KaClassKind
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.highlighting.dsl.DslStyleUtils
import org.jetbrains.kotlin.idea.highlighter.HighlightingFactory
import org.jetbrains.kotlin.name.ClassId
@@ -67,7 +67,7 @@ fun KtClass.getDslStyleId(): Int? {
* A Dsl annotation is an annotation that is itself marked by [DslMarker] annotation.
*/
context(KaSession)
private fun getDslAnnotation(type: KtType): ClassId? {
private fun getDslAnnotation(type: KaType): ClassId? {
val allAnnotationsWithSuperTypes = sequence {
yieldAll(type.annotationClassIds)
val symbol = type.expandedSymbol ?: return@sequence

View File

@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSo
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedFunctionSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaValueParameterSymbol
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.injection.KotlinFunctionPatternBase
import org.jetbrains.kotlin.idea.base.injection.KotlinReceiverPattern
import org.jetbrains.kotlin.idea.base.injection.KtParameterPatternBase
@@ -34,7 +34,7 @@ internal object KotlinPatterns : StandardPatterns() {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun KtType.renderFullyQualifiedName() = render(KtTypeRendererForSource.WITH_QUALIFIED_NAMES, Variance.INVARIANT)
private fun KaType.renderFullyQualifiedName() = render(KtTypeRendererForSource.WITH_QUALIFIED_NAMES, Variance.INVARIANT)
// Methods in this class are used through reflection during pattern construction
@Suppress("unused")

View File

@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KaFunctionalTy
import org.jetbrains.kotlin.analysis.api.symbols.KaCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaReceiverParameterSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.debugger.core.getClassName
@@ -120,7 +120,7 @@ internal fun <T : PsiElement> SmartPsiElementPointer<T>?.getElementInReadAction(
@KaExperimentalApi
private val NO_RETURN_TYPE = object : KaCallableReturnTypeFilter {
override fun shouldRenderReturnType(analysisSession: KaSession, type: KtType, symbol: KaCallableSymbol): Boolean = false
override fun shouldRenderReturnType(analysisSession: KaSession, type: KaType, symbol: KaCallableSymbol): Boolean = false
}
@KaExperimentalApi

View File

@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.idea.debugger.base.util.fqnToInternalName
import org.jetbrains.kotlin.idea.debugger.base.util.internalNameToFqn
@@ -138,7 +138,7 @@ private fun KaFunctionSymbol.getJvmSignature(): String? {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun KtType.jvmName(element: PsiElement): String? {
private fun KaType.jvmName(element: PsiElement): String? {
if (this !is KaClassType) return null
val psiType = asPsiType(element, allowErrorTypes = false) ?: return null
if (symbol.isInlineClass()) {

View File

@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithModality
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.descriptors.Modality
@@ -191,7 +191,7 @@ internal class KotlinK2SearchUsagesSupport : KotlinSearchUsagesSupport {
return when (psiElement) {
is KtCallableDeclaration -> {
analyze(psiElement) {
fun resolveKtClassOrObject(ktType: KtType): KtClassOrObject? {
fun resolveKtClassOrObject(ktType: KaType): KtClassOrObject? {
return (ktType as? KaClassType)?.symbol?.psiSafe<KtClassOrObject>()
}
@@ -205,7 +205,7 @@ internal class KotlinK2SearchUsagesSupport : KotlinSearchUsagesSupport {
ReceiverTypeSearcherInfo(ktClass) { declaration ->
runReadAction {
analyze(declaration) {
fun KtType.containsClassType(clazz: KtClassOrObject?): Boolean {
fun KaType.containsClassType(clazz: KtClassOrObject?): Boolean {
if (clazz == null) return false
return this is KaClassType && (clazz.isEquivalentTo(symbol.psi) ||
typeArguments.any { arg ->
@@ -254,7 +254,7 @@ internal class KotlinK2SearchUsagesSupport : KotlinSearchUsagesSupport {
}
context(KaSession)
private fun getContainingClassType(symbol: KaCallableSymbol): KtType? {
private fun getContainingClassType(symbol: KaCallableSymbol): KaType? {
val containingSymbol = symbol.containingSymbol ?: return null
val classSymbol = containingSymbol as? KaNamedClassOrObjectSymbol ?: return null
return classSymbol.buildSelfClassType()

View File

@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithKind
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithTypeParameters
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithVisibility
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.asJava.accessorNameByPropertyName
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
import org.jetbrains.kotlin.asJava.toLightClass
@@ -234,10 +234,10 @@ private fun areSameSignatures(candidateSymbol: KaPropertySymbol, symbol: KaFunct
context(KaSession)
fun areSameSignatures(
receiverType1: KtType?,
receiverType2: KtType?,
parameterTypes1: List<KtType>,
parameterTypes2: List<KtType>,
receiverType1: KaType?,
receiverType2: KaType?,
parameterTypes1: List<KaType>,
parameterTypes2: List<KaType>,
c1: List<KaContextReceiver>,
c2: List<KaContextReceiver>,
): Boolean {
@@ -247,7 +247,7 @@ fun areSameSignatures(
}
context(KaSession)
private fun areTypesTheSame(t1: KtType?, t2: KtType?): Boolean {
private fun areTypesTheSame(t1: KaType?, t2: KaType?): Boolean {
if (t1 === t2) return true
if (t2 == null) return false
return t1?.isEqualTo(t2) == true

View File

@@ -17,7 +17,7 @@ import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory
import com.intellij.usageView.UsageInfo
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.asJava.toLightElements
import org.jetbrains.kotlin.idea.base.psi.unquoteKotlinIdentifier
@@ -121,7 +121,7 @@ class AutomaticVariableRenamer(
private fun KtCallableDeclaration.isCollectionLikeOf(classPsiElement: PsiNamedElement): Boolean {
analyze(this) {
fun KtType.isCollectionLikeOf(classPsiElement: PsiNamedElement): Boolean {
fun KaType.isCollectionLikeOf(classPsiElement: PsiNamedElement): Boolean {
if (isArrayOrPrimitiveArray || isClassTypeWithClassId(StandardClassIds.Collection) || getAllSuperTypes().any { it.isClassTypeWithClassId(StandardClassIds.Collection) }) {
val typeArgument = (this as? KaClassType)?.typeArguments?.singleOrNull()?.type ?: return false
if (typeArgument.expandedSymbol?.psi == classPsiElement) {

View File

@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.k2.refactoring.changeSignature.usages.KotlinByConventionCallUsage
import org.jetbrains.kotlin.idea.k2.refactoring.changeSignature.usages.KotlinChangeSignatureConflictingUsageInfo
@@ -140,7 +140,7 @@ class KotlinChangeSignatureConflictSearcher(
}
context(KaSession)
private fun KtPsiFactory.createContextType(text: String, context: KtElement): KtType? {
private fun KtPsiFactory.createContextType(text: String, context: KtElement): KaType? {
return createTypeCodeFragment(text, context).getContentElement()?.getKtType()
}
context(KaSession)

View File

@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KtTypeErrorTyp
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
import org.jetbrains.kotlin.analysis.api.types.KaDefinitelyNotNullType
import org.jetbrains.kotlin.analysis.api.types.KaSubstitutor
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.asJava.toLightMethods
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.types.Variance
data class KotlinTypeInfo(var text: String?, val context: KtElement) {
@OptIn(KaExperimentalApi::class)
constructor(ktType: KtType, context: KtElement): this(analyze(context) { ktType.render(errorIgnoringRenderer, Variance.INVARIANT) }, context)
constructor(ktType: KaType, context: KtElement): this(analyze(context) { ktType.render(errorIgnoringRenderer, Variance.INVARIANT) }, context)
}
@KaExperimentalApi

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.analysis.api.resolution.symbol
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.symbols.KaConstructorSymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
@@ -38,7 +38,7 @@ object ChangeParameterTypeFixFactory {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun createTypeMismatchFixes(psi: PsiElement, targetType: KtType): List<KotlinQuickFixAction<*>> {
private fun createTypeMismatchFixes(psi: PsiElement, targetType: KaType): List<KotlinQuickFixAction<*>> {
val valueArgument = psi.parent as? KtValueArgument ?: return emptyList()
val callElement = valueArgument.parentOfType<KtCallElement>() ?: return emptyList()

View File

@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.builtins.StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME
import org.jetbrains.kotlin.builtins.functions.FunctionTypeKind
import org.jetbrains.kotlin.idea.base.analysis.api.utils.analyzeInModalWindow
@@ -259,7 +259,7 @@ object ChangeSignatureFixFactory {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun getKtType(argumentExpression: KtExpression?): KtType? {
private fun getKtType(argumentExpression: KtExpression?): KaType? {
var ktType = argumentExpression?.getKtType()
val typeKind = ktType?.functionTypeKind
when (typeKind) {
@@ -368,7 +368,7 @@ object ChangeSignatureFixFactory {
@OptIn(KaExperimentalApi::class)
private fun createMismatchParameterTypeFix(
element: PsiElement,
expectedType: KtType
expectedType: KaType
): List<ParameterQuickFix> {
val valueArgument = element.getStrictParentOfType<KtValueArgument>()
if (valueArgument == null) return emptyList()

View File

@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.idea.base.analysis.api.utils.analyzeInModalWindow
@@ -288,4 +288,4 @@ internal fun KtTypeCodeFragment.getCanonicalText(forPreview: Boolean): String {
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun KtType.getPresentableText(): String = render(KtTypeRendererForSource.WITH_SHORT_NAMES, position = Variance.INVARIANT)
private fun KaType.getPresentableText(): String = render(KtTypeRendererForSource.WITH_SHORT_NAMES, position = Variance.INVARIANT)

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.annotations.KaAnnotated
import org.jetbrains.kotlin.analysis.api.annotations.KaAnnotation
import org.jetbrains.kotlin.analysis.api.renderer.base.annotations.KaRendererAnnotationsFilter
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KaDeclarationRendererForSource
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.ControlFlow
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.DuplicateInfo
@@ -36,16 +36,16 @@ data class ExtractableCodeDescriptor(
override val parameters: List<Parameter>,
override val receiverParameter: Parameter?,
override val typeParameters: List<TypeParameter>,
override val replacementMap: MultiMap<KtSimpleNameExpression, IReplacement<KtType>>,
override val controlFlow: ControlFlow<KtType>,
override val returnType: KtType,
override val replacementMap: MultiMap<KtSimpleNameExpression, IReplacement<KaType>>,
override val controlFlow: ControlFlow<KaType>,
override val returnType: KaType,
override val modifiers: List<KtKeywordToken> = emptyList(),
override val optInMarkers: List<FqName> = emptyList(),
val annotationClassIds: Set<ClassId> = emptySet()
) : IExtractableCodeDescriptor<KtType> {
) : IExtractableCodeDescriptor<KaType> {
override val name: String get() = suggestedNames.firstOrNull() ?: ""
override val duplicates: List<DuplicateInfo<KtType>> by lazy { findDuplicates() }
override val duplicates: List<DuplicateInfo<KaType>> by lazy { findDuplicates() }
private val isUnitReturn: Boolean = analyze(context) { returnType.isUnit }
@@ -76,11 +76,11 @@ data class ExtractableCodeDescriptor(
}
}
internal fun getPossibleReturnTypes(cfg: ControlFlow<KtType>): List<KtType> {
internal fun getPossibleReturnTypes(cfg: ControlFlow<KaType>): List<KaType> {
return cfg.possibleReturnTypes
}
data class ExtractableCodeDescriptorWithConflicts(
override val descriptor: ExtractableCodeDescriptor,
override val conflicts: MultiMap<PsiElement, String>
) : ExtractableCodeDescriptorWithConflictsResult(), IExtractableCodeDescriptorWithConflicts<KtType>
) : ExtractableCodeDescriptorWithConflictsResult(), IExtractableCodeDescriptorWithConflicts<KaType>

View File

@@ -1,11 +1,11 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.k2.refactoring.extractFunction
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.ExtractionGeneratorOptions
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.IExtractionGeneratorConfiguration
data class ExtractionGeneratorConfiguration(
override val descriptor: ExtractableCodeDescriptor,
override val generatorOptions: ExtractionGeneratorOptions
) : IExtractionGeneratorConfiguration<KtType>
) : IExtractionGeneratorConfiguration<KaType>

View File

@@ -1,7 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.k2.refactoring.extractFunction
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.psi.unifier.KotlinPsiRange
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.IExtractionResult
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.unmarkReferencesInside
@@ -11,6 +11,6 @@ data class ExtractionResult(
override val config: ExtractionGeneratorConfiguration,
override var declaration: KtNamedDeclaration,
override val duplicateReplacers: Map<KotlinPsiRange, () -> Unit>
) : IExtractionResult<KtType> {
) : IExtractionResult<KaType> {
override fun dispose() = unmarkReferencesInside(declaration)
}

View File

@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.analysis.api.resolution.KaErrorCallInfo
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.analyzeInModalWindow
import org.jetbrains.kotlin.idea.base.psi.unifier.toRange
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
@@ -61,7 +61,7 @@ class KotlinFirExtractFunctionHandler(
}
class InplaceExtractionHelper(private val acceptAllScopes: Boolean) : ExtractionEngineHelper(EXTRACT_FUNCTION),
AbstractInplaceExtractionHelper<KtType, ExtractionResult, ExtractableCodeDescriptorWithConflicts> {
AbstractInplaceExtractionHelper<KaType, ExtractionResult, ExtractableCodeDescriptorWithConflicts> {
override fun createRestartHandler(): AbstractExtractKotlinFunctionHandler =
KotlinFirExtractFunctionHandler(acceptAllScopes, InteractiveExtractionHelper)
@@ -69,7 +69,7 @@ class KotlinFirExtractFunctionHandler(
KotlinFirExtractFunctionHandler(acceptAllScopes, this)
override fun doRefactor(
descriptor: IExtractableCodeDescriptor<KtType>, onFinish: (ExtractionResult) -> Unit
descriptor: IExtractableCodeDescriptor<KaType>, onFinish: (ExtractionResult) -> Unit
) {
val configuration =
ExtractionGeneratorConfiguration(descriptor as ExtractableCodeDescriptor, withCollapseOption(descriptor.context.project))
@@ -113,10 +113,10 @@ class KotlinFirExtractFunctionHandler(
}
val engine = object :
IExtractionEngine<KtType, ExtractionData, ExtractionGeneratorConfiguration, ExtractionResult, ExtractableCodeDescriptor, ExtractableCodeDescriptorWithConflicts>(
IExtractionEngine<KaType, ExtractionData, ExtractionGeneratorConfiguration, ExtractionResult, ExtractableCodeDescriptor, ExtractableCodeDescriptorWithConflicts>(
helper
) {
override fun performAnalysis(extractionData: ExtractionData): AnalysisResult<KtType> {
override fun performAnalysis(extractionData: ExtractionData): AnalysisResult<KaType> {
return ExtractionDataAnalyzer(extractionData).performAnalysis()
}
}

View File

@@ -7,7 +7,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.symbols.KaAnonymousObjectSymbol
import org.jetbrains.kotlin.analysis.api.types.KaFlexibleType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.extractionEngine.isResolvableInScope
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.ControlFlow
@@ -15,42 +15,42 @@ import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.IMutable
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.IParameter
import org.jetbrains.kotlin.psi.KtElement
interface Parameter : IParameter<KtType> {
interface Parameter : IParameter<KaType> {
val originalDescriptor: PsiNamedElement
}
internal sealed class TypePredicate {
context(KaSession)
abstract fun isApplicable(ktType: KtType): Boolean
abstract fun isApplicable(ktType: KaType): Boolean
}
internal class SubTypePredicate(private val type: KtType) : TypePredicate() {
internal class SubTypePredicate(private val type: KaType) : TypePredicate() {
context(KaSession)
override fun isApplicable(ktType: KtType): Boolean = ktType.isSubTypeOf(type)
override fun isApplicable(ktType: KaType): Boolean = ktType.isSubTypeOf(type)
}
internal class SuperTypePredicate(private val type: KtType) : TypePredicate() {
internal class SuperTypePredicate(private val type: KaType) : TypePredicate() {
context(KaSession)
override fun isApplicable(ktType: KtType): Boolean = ktType.isSubTypeOf(type)
override fun isApplicable(ktType: KaType): Boolean = ktType.isSubTypeOf(type)
}
internal class ExactTypePredicate(private val type: KtType) : TypePredicate() {
internal class ExactTypePredicate(private val type: KaType) : TypePredicate() {
context(KaSession)
override fun isApplicable(ktType: KtType): Boolean = ktType.isEqualTo(type)
override fun isApplicable(ktType: KaType): Boolean = ktType.isEqualTo(type)
}
internal class AndPredicate(val predicates: Set<TypePredicate>) : TypePredicate() {
context(KaSession)
override fun isApplicable(ktType: KtType): Boolean = predicates.all { it.isApplicable(ktType) }
override fun isApplicable(ktType: KaType): Boolean = predicates.all { it.isApplicable(ktType) }
}
internal class MutableParameter(
override val argumentText: String,
override val originalDescriptor: PsiNamedElement,
override val receiverCandidate: Boolean,
private val originalType: KtType,
private val originalType: KaType,
private val scope: KtElement
) : Parameter, IMutableParameter<KtType> {
) : Parameter, IMutableParameter<KaType> {
private val typePredicates = mutableSetOf<TypePredicate>()
@@ -65,12 +65,12 @@ internal class MutableParameter(
override var mirrorVarName: String? = null
context(KaSession)
private fun allParameterTypeCandidates(): List<KtType> {
private fun allParameterTypeCandidates(): List<KaType> {
val andPredicate = AndPredicate(typePredicates)
val typeSet = if (originalType is KaFlexibleType) {
val lower = originalType.lowerBound
val upper = originalType.upperBound
LinkedHashSet<KtType>().apply {
LinkedHashSet<KaType>().apply {
if (andPredicate.isApplicable(upper)) add(upper)
if (andPredicate.isApplicable(lower)) add(lower)
}
@@ -93,7 +93,7 @@ internal class MutableParameter(
return typeSet.toList()
}
override fun getParameterTypeCandidates(): List<KtType> {
override fun getParameterTypeCandidates(): List<KaType> {
analyze(scope) {
return allParameterTypeCandidates().filter {
!(it is KaClassType && it.symbol is KaAnonymousObjectSymbol) &&
@@ -102,11 +102,11 @@ internal class MutableParameter(
}
}
override val parameterType: KtType
override val parameterType: KaType
get() = getParameterTypeCandidates().firstOrNull() ?: originalType
}
val ControlFlow<KtType>.possibleReturnTypes: List<KtType>
val ControlFlow<KaType>.possibleReturnTypes: List<KaType>
get() {
return listOf(outputValueBoxer.returnType)
}

View File

@@ -2,7 +2,7 @@
package org.jetbrains.kotlin.idea.k2.refactoring.extractFunction
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.psi.unifier.toRange
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.K2SemanticMatcher.matchRanges
import org.jetbrains.kotlin.idea.k2.refactoring.introduce.extractionEngine.ExtractionDataAnalyzer
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtStringTemplateEntryWithExpression
fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo<KtType>> {
fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo<KaType>> {
val scopeElement = getOccurrenceContainer() as? KtElement ?: return emptyList()
val originalTextRange = extractionData.originalRange.getPhysicalTextRange()
return analyze(scopeElement) {

View File

@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
import org.jetbrains.kotlin.analysis.api.signatures.KaCallableSignature
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinDeclarationNameValidator
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester.Companion.suggestNameByName
@@ -103,9 +103,9 @@ context(KaSession)
internal fun ExtractionData.inferParametersInfo(
virtualBlock: KtBlockExpression,
modifiedVariables: Set<String>,
typeDescriptor: TypeDescriptor<KtType>,
): ParametersInfo<KtType, MutableParameter> {
val info = ParametersInfo<KtType, MutableParameter>()
typeDescriptor: TypeDescriptor<KaType>,
): ParametersInfo<KaType, MutableParameter> {
val info = ParametersInfo<KaType, MutableParameter>()
val extractedDescriptorToParameter = LinkedHashMap<ParameterWithReference, MutableParameter>()
@@ -135,7 +135,7 @@ internal fun ExtractionData.inferParametersInfo(
)
val existingParameterNames = hashSetOf<String>()
val generateArguments: (KtType) -> List<KtType> =
val generateArguments: (KaType) -> List<KaType> =
{ ktType -> (ktType as? KaClassType)?.typeArguments?.mapNotNull { it.type } ?: emptyList() }
for ((namedElement, parameter) in extractedDescriptorToParameter) {
if (!parameter
@@ -196,8 +196,8 @@ internal fun ExtractionData.inferParametersInfo(
context(KaSession)
private fun ExtractionData.registerParameter(
info: ParametersInfo<KtType, MutableParameter>,
refInfo: ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KtType>,
info: ParametersInfo<KaType, MutableParameter>,
refInfo: ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KaType>,
extractedDescriptorToParameter: HashMap<ParameterWithReference, MutableParameter>,
isMemberExtension: Boolean
) {
@@ -306,7 +306,7 @@ private fun ExtractionData.registerParameter(
private fun getParameterArgumentExpression(
originalRef: KtReferenceExpression,
receiverToExtract: KaReceiverValue?,
smartCast: KtType?
smartCast: KaType?
): KtExpression? = when {
receiverToExtract is KaExplicitReceiverValue -> {
val receiverExpression = receiverToExtract.expression
@@ -354,7 +354,7 @@ private fun ExtractionData.calculateArgumentText(
context(KaSession)
private fun ExtractionData.registerQualifierReplacements(
referencedClassifierSymbol: KaClassifierSymbol,
parametersInfo: ParametersInfo<KtType, MutableParameter>,
parametersInfo: ParametersInfo<KaType, MutableParameter>,
originalDeclaration: PsiNamedElement,
originalRef: KtReferenceExpression
) {
@@ -385,7 +385,7 @@ context(KaSession)
private fun getReferencedClassifierSymbol(
thisSymbol: KaSymbol?,
originalDeclaration: PsiNamedElement,
refInfo: ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KtType>,
refInfo: ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KaType>,
partiallyAppliedSymbol: KaPartiallyAppliedSymbol<KaCallableSymbol, KaCallableSignature<KaCallableSymbol>>?
): KaClassifierSymbol? {
val referencedSymbol = (thisSymbol ?: (originalDeclaration as? KtNamedDeclaration)?.symbol
@@ -412,7 +412,7 @@ private fun createOriginalType(
originalDeclaration: PsiNamedElement,
parameterExpression: KtExpression?,
receiverToExtract: KaReceiverValue?
): KtType = (if (extractFunctionRef) {
): KaType = (if (extractFunctionRef) {
val functionSymbol = (originalDeclaration as KtNamedFunction).symbol as KaNamedFunctionSymbol
val typeString =
buildString { //todo rewrite as soon as functional type can be created by api call: https://youtrack.jetbrains.com/issue/KT-66566
@@ -441,19 +441,19 @@ private fun createOriginalType(
@OptIn(KaExperimentalApi::class)
private fun ExtractionData.getBrokenReferencesInfo(body: KtBlockExpression): List<ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KtType>> {
private fun ExtractionData.getBrokenReferencesInfo(body: KtBlockExpression): List<ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KaType>> {
val newReferences = body.collectDescendantsOfType<KtReferenceExpression> { it.resolveResult != null }
val smartCastPossibleRoots = mutableSetOf<KtExpression>()
val referencesInfo = ArrayList<ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KtType>>()
val referencesInfo = ArrayList<ResolvedReferenceInfo<PsiNamedElement, KtReferenceExpression, KaType>>()
for (newRef in newReferences) {
val originalResolveResult = newRef.resolveResult as? ResolveResult<PsiNamedElement, KtReferenceExpression> ?: continue
val originalRefExpr = originalResolveResult.originalRefExpr
val parent = newRef.parent
val smartCast: KtType?
val smartCast: KaType?
fun calculateSmartCastType(target: KtExpression): KtType? {
fun calculateSmartCastType(target: KtExpression): KaType? {
return analyze(target) {
val cast = target.smartCastInfo?.smartCastType
when {
@@ -470,7 +470,7 @@ private fun ExtractionData.getBrokenReferencesInfo(body: KtBlockExpression): Lis
}
}
val possibleTypes: Set<KtType>
val possibleTypes: Set<KaType>
// Qualified property reference: a.b
val qualifiedExpression = newRef.getQualifiedExpressionForSelector()

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.k2.refactoring.extractFunction.Parameter
import org.jetbrains.kotlin.idea.refactoring.introduce.ui.AbstractParameterTablePanel
@@ -38,7 +38,7 @@ abstract class FirExtractFunctionParameterTablePanel :
override fun toParameter() = object : Parameter by originalParameter {
override val name: String = this@ParameterInfo.name
override val parameterType: KtType = this@ParameterInfo.type
override val parameterType: KaType = this@ParameterInfo.type
}
}
@@ -57,7 +57,7 @@ abstract class FirExtractFunctionParameterTablePanel :
table: JTable, value: Any, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int
): Component {
@NlsSafe val renderType =
allowAnalysisOnEdt { analyze(context) { (value as KtType).render(position = Variance.IN_VARIANCE) } }
allowAnalysisOnEdt { analyze(context) { (value as KaType).render(position = Variance.IN_VARIANCE) } }
myLabel.text = renderType
myLabel.background = if (isSelected) table.selectionBackground else table.background
myLabel.foreground = if (isSelected) table.selectionForeground else table.foreground
@@ -83,7 +83,7 @@ abstract class FirExtractFunctionParameterTablePanel :
myEditorComponent.setOptions(*info.originalParameter.getParameterTypeCandidates().toTypedArray())
myEditorComponent.setDefaultValue(info.type)
myEditorComponent.setToString {
analyze(context) { (it as KtType).render(position = Variance.IN_VARIANCE) }
analyze(context) { (it as KaType).render(position = Variance.IN_VARIANCE) }
}
return myEditorComponent
@@ -110,7 +110,7 @@ abstract class FirExtractFunctionParameterTablePanel :
override fun setValueAt(aValue: Any?, rowIndex: Int, columnIndex: Int) {
if (columnIndex == PARAMETER_TYPE_COLUMN) {
parameterInfos[rowIndex].type = aValue as KtType
parameterInfos[rowIndex].type = aValue as KaType
updateSignature()
return
}

View File

@@ -6,7 +6,7 @@ import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.permissions.KaAllowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.permissions.allowAnalysisOnEdt
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.idea.base.analysis.api.utils.analyzeInModalWindow
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.k2.refactoring.extractFunction.ExtractableCodeDescriptor
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.psi.KtTypeCodeFragment
import org.jetbrains.kotlin.types.Variance
@OptIn(KaAllowAnalysisOnEdt::class, KaExperimentalApi::class)
internal fun render(type: KtType, context: KtElement): String {
internal fun render(type: KaType, context: KtElement): String {
return allowAnalysisOnEdt {
analyze(context) {
type.render(KtTypeRendererForSource.WITH_QUALIFIED_NAMES, Variance.IN_VARIANCE)
@@ -31,7 +31,7 @@ internal fun render(type: KtType, context: KtElement): String {
}
@OptIn(KaAllowAnalysisOnEdt::class)
internal fun getKtType(fragment: KtTypeCodeFragment): KtType? {
internal fun getKtType(fragment: KtTypeCodeFragment): KaType? {
return allowAnalysisOnEdt {
analyze(fragment) {
fragment.getContentElement()?.getKtType()

View File

@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.types.KaErrorType
import org.jetbrains.kotlin.analysis.api.types.KaFunctionType
import org.jetbrains.kotlin.analysis.api.types.KaClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.analysis.api.types.KaType
import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinDeclarationNameValidator
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester
@@ -50,7 +50,7 @@ class CodeInliner(
private val call: KtElement,
private val inlineSetter: Boolean,
codeToInline: CodeToInline
) : AbstractCodeInliner<KtElement, KtParameter, KtType, KtDeclaration>(call, codeToInline) {
) : AbstractCodeInliner<KtElement, KtParameter, KaType, KtDeclaration>(call, codeToInline) {
private val mapping: Map<KtExpression, Name>? = analyze(call) {
call.resolveToCall()?.singleFunctionCallOrNull()?.argumentMapping?.mapValues { e -> e.value.name }
}
@@ -276,7 +276,7 @@ class CodeInliner(
context(KaSession)
@OptIn(KaExperimentalApi::class)
private fun arrayOfFunctionName(elementType: KtType): String {
private fun arrayOfFunctionName(elementType: KaType): String {
return when {
elementType.isInt -> "kotlin.intArrayOf"
elementType.isLong -> "kotlin.longArrayOf"
@@ -376,7 +376,7 @@ class CodeInliner(
override fun introduceValue(
value: KtExpression,
valueType: KtType?,
valueType: KaType?,
usages: Collection<KtExpression>,
expressionToBeReplaced: KtExpression,
nameSuggestion: String?,

Some files were not shown because too many files have changed in this diff Show More