mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[kotlin] Migrate to isSubtypeOf(ClassId) where possible
^KT-69950 GitOrigin-RevId: 24cc91addf54f1e6b95f23ae876ef692300bd708
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2416622236
commit
d0f2bf2e00
@@ -18,7 +18,6 @@ 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.KaType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KaUsualClassType
|
||||
import org.jetbrains.kotlin.idea.base.codeInsight.ShortenReferencesFacility
|
||||
import org.jetbrains.kotlin.idea.base.psi.imports.addImport
|
||||
import org.jetbrains.kotlin.idea.base.utils.fqname.isImported
|
||||
@@ -199,14 +198,8 @@ internal class ForbiddenInSuspectContextMethodInspection : LocalInspectionTool()
|
||||
add(ReplaceInvokeLaterWithWithContextQuickFix(callExpression))
|
||||
|
||||
val implicitReceiverTypesAtPosition = collectImplicitReceiverTypes(callExpression)
|
||||
val coroutineScopeClass = ClassId.topLevel(FqName(COROUTINE_SCOPE))
|
||||
val hasCoroutineScope = implicitReceiverTypesAtPosition.any { type ->
|
||||
type is KaUsualClassType &&
|
||||
(
|
||||
type.classId == coroutineScopeClass ||
|
||||
type.allSupertypes.any { superType -> superType is KaUsualClassType && superType.classId == coroutineScopeClass }
|
||||
)
|
||||
}
|
||||
val coroutineScopeClassId = ClassId.topLevel(FqName(COROUTINE_SCOPE))
|
||||
val hasCoroutineScope = implicitReceiverTypesAtPosition.any { it.isSubtypeOf(coroutineScopeClassId) }
|
||||
if (hasCoroutineScope) {
|
||||
add(ReplaceInvokeLaterWithLaunchQuickFix(callExpression))
|
||||
}
|
||||
|
||||
@@ -638,7 +638,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
addInstruction(PushValueInstruction(DfTypes.typedObject(PsiTypes.charType(), Nullability.UNKNOWN), anchor))
|
||||
}
|
||||
|
||||
kotlinType.isSubTypeOf(StandardClassIds.List) -> {
|
||||
kotlinType?.isSubtypeOf(StandardClassIds.List) == true -> {
|
||||
if (indexType.canBeNull()) {
|
||||
addInstruction(UnwrapDerivedVariableInstruction(SpecialField.UNBOX))
|
||||
}
|
||||
@@ -673,11 +673,6 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
addCall(parent as KtExpression, 3)
|
||||
}
|
||||
|
||||
context(KaSession)
|
||||
private fun KaType?.isSubTypeOf(wantedType: ClassId) =
|
||||
this is KaClassType && classId == wantedType ||
|
||||
this != null && allSupertypes.any { type -> type is KaClassType && type.classId == wantedType }
|
||||
|
||||
context(KaSession)
|
||||
private fun processMathExpression(expr: KtBinaryExpression, mathOp: LongRangeBinOp) {
|
||||
val left = expr.left
|
||||
@@ -1142,7 +1137,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
val dfVar = KtVariableDescriptor.createFromSimpleName(factory, receiver)
|
||||
if (dfVar != null) {
|
||||
val sf = when {
|
||||
kotlinType.isSubTypeOf(StandardClassIds.Collection) -> SpecialField.COLLECTION_SIZE
|
||||
kotlinType.isSubtypeOf(StandardClassIds.Collection) -> SpecialField.COLLECTION_SIZE
|
||||
kotlinType.isArrayOrPrimitiveArray -> SpecialField.ARRAY_LENGTH
|
||||
else -> null
|
||||
}
|
||||
@@ -1220,8 +1215,8 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
return when {
|
||||
type.isEnum() -> SpecialField.ENUM_ORDINAL
|
||||
type.isArrayOrPrimitiveArray -> SpecialField.ARRAY_LENGTH
|
||||
type.isSubTypeOf(StandardClassIds.Collection) ||
|
||||
type.isSubTypeOf(StandardClassIds.Map) -> SpecialField.COLLECTION_SIZE
|
||||
type.isSubtypeOf(StandardClassIds.Collection) ||
|
||||
type.isSubtypeOf(StandardClassIds.Map) -> SpecialField.COLLECTION_SIZE
|
||||
|
||||
type.isStringType -> SpecialField.STRING_LENGTH
|
||||
else -> null
|
||||
@@ -1413,7 +1408,7 @@ class KtControlFlowBuilder(val factory: DfaValueFactory, val context: KtExpressi
|
||||
context(KaSession)
|
||||
private fun pushJavaClassField(receiver: KtExpression, selector: KtExpression?, expr: KtQualifiedExpression): Boolean {
|
||||
if (selector == null || !selector.textMatches("java")) return false
|
||||
if (!receiver.getKotlinType().isSubTypeOf(StandardClassIds.KClass)) return false
|
||||
if (receiver.getKotlinType()?.isSubtypeOf(StandardClassIds.KClass) != true) return false
|
||||
val kotlinType = expr.getKotlinType() ?: return false
|
||||
val classType = TypeConstraint.fromDfType(kotlinType.toDfType())
|
||||
if (!classType.isExact(CommonClassNames.JAVA_LANG_CLASS)) return false
|
||||
|
||||
@@ -12,6 +12,11 @@ import org.jetbrains.kotlin.analysis.api.scopes.KaScope
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbolVisibility
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities.Private
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities.Protected
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities.Public
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -55,10 +60,7 @@ private class ImplementReadResolveQuickFix : LocalQuickFix {
|
||||
}
|
||||
|
||||
private fun KtObjectDeclaration.doesImplementSerializable(): Boolean = analyze(this) {
|
||||
true == (this@doesImplementSerializable.symbol as? KaClassSymbol)
|
||||
?.let(::buildClassType)
|
||||
?.allSupertypes
|
||||
?.any { it.isClassType(ClassId.fromString(JAVA_IO_SERIALIZABLE_CLASS_ID)) }
|
||||
buildClassType(symbol).isSubtypeOf(ClassId.fromString(JAVA_IO_SERIALIZABLE_CLASS_ID))
|
||||
}
|
||||
|
||||
private fun KtObjectDeclaration.doesImplementReadResolve(): Boolean = analyze(this) {
|
||||
|
||||
Reference in New Issue
Block a user