From c7193e5a3844cf5b876044536ffe039dc6658c77 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Tue, 9 Jul 2024 18:43:28 +0300 Subject: [PATCH] [Kotlin] fix AA deprecations KTIJ-28464 GitOrigin-RevId: c34b4455c5ef3a10f6cbb1a1c668a75243933e16 --- .../GenerateEqualsAndHashCodeUtils.kt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/intentions/GenerateEqualsAndHashCodeUtils.kt b/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/intentions/GenerateEqualsAndHashCodeUtils.kt index 6d8ea73d7ced..ba2877677bcd 100644 --- a/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/intentions/GenerateEqualsAndHashCodeUtils.kt +++ b/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/intentions/GenerateEqualsAndHashCodeUtils.kt @@ -45,7 +45,7 @@ fun matchesHashCodeMethodSignature(function: KaNamedFunctionSymbol): Boolean { if (function.typeParameters.isNotEmpty()) return false if (function.valueParameters.isNotEmpty()) return false val returnType = function.returnType - return returnType.isInt && !returnType.isMarkedNullable + return returnType.isIntType && !returnType.isMarkedNullable } fun generateEqualsHeaderAndBodyTexts(targetClass: KtClass): Pair { @@ -58,7 +58,7 @@ fun generateEqualsHeaderAndBodyTexts(targetClass: KtClass): Pair } var bodyText = "" analyze(targetClass) { - val classSymbol = targetClass.getClassOrObjectSymbol() ?: return@analyze + val classSymbol = targetClass.classSymbol ?: return@analyze val equalsMethod = findEqualsMethodForClass(classSymbol) as? KaNamedFunctionSymbol ?: return@analyze val superContainingEqualsMethod = equalsMethod.containingDeclaration ?: return@analyze @@ -100,7 +100,7 @@ fun generateEqualsHeaderAndBodyTexts(targetClass: KtClass): Pair bodyText = buildString { append("if (this === $parameterName) return true\n") append("if ($isNotInstanceCondition) return false\n") - if (superContainingEqualsMethod != builtinTypes.ANY.expandedSymbol) { + if (superContainingEqualsMethod != builtinTypes.any.expandedSymbol) { append("if (!super.equals($parameterName)) return false\n") } @@ -172,7 +172,8 @@ fun generateHashCodeHeaderAndBodyTexts(targetClass: KtClass): Pair ref + type.semanticallyEquals(builtinTypes.byte) || type.semanticallyEquals(builtinTypes.short) + || type.semanticallyEquals(builtinTypes.int) -> ref type.isArrayOrPrimitiveArray -> { val canUseArrayContentFunctions = targetClass.canUseArrayContentFunctions() @@ -194,7 +195,7 @@ fun generateHashCodeHeaderAndBodyTexts(targetClass: KtClass): Pair "super.hashCode()" + superContainingHashCodeMethod != builtinTypes.any.expandedSymbol -> "super.hashCode()" propertyIterator.hasNext() -> propertyIterator.next().genVariableHashCode(false) else -> generateClassLiteral(targetClass) + ".hashCode()" } @@ -239,7 +240,7 @@ private fun findEqualsMethodForClass(classSymbol: KaClassSymbol): KaCallableSymb context(KaSession) private fun findMethod( classSymbol: KaClassSymbol, methodName: Name, condition: (KaCallableSymbol) -> Boolean -): KaCallableSymbol? = classSymbol.memberScope.getCallableSymbols(methodName).filter(condition).singleOrNull() +): KaCallableSymbol? = classSymbol.memberScope.callables(methodName).filter(condition).singleOrNull() context(KaSession) private fun findHashCodeMethodForClass(classSymbol: KaClassSymbol): KaCallableSymbol? = @@ -247,8 +248,6 @@ private fun findHashCodeMethodForClass(classSymbol: KaClassSymbol): KaCallableSy (callableSymbol as? KaNamedFunctionSymbol)?.let { matchesHashCodeMethodSignature(it) } == true } - - /** * A function to generate the "not equals" comparison between the class of `this` and the class of the parameter. */ @@ -280,7 +279,7 @@ private fun getPropertiesToUseInGeneratedMember(classOrObject: KtClassOrObject): buildList { classOrObject.primaryConstructorParameters.filterTo(this) { it.hasValOrVar() } classOrObject.declarations.asSequence().filterIsInstance().filterTo(this) { - it.getVariableSymbol() is KaPropertySymbol + it.symbol is KaPropertySymbol } }.filter { it.name?.quoteIfNeeded().isIdentifier()