mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] k2: ignore abstract functions when detecting non-paired equals/hashcode (KTIJ-25777)
GitOrigin-RevId: be864df114f27af71204eafd383c149e1f582f79
This commit is contained in:
committed by
intellij-monorepo-bot
parent
93b19392f4
commit
78b56a913a
+3
-2
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.idea.base.facet.platform.platform
|
||||
import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.base.psi.classIdIfNonLocal
|
||||
@@ -55,6 +56,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
|
||||
private fun KtAnalysisSession.matchesEqualsMethodSignature(function: KtFunctionSymbol): Boolean {
|
||||
if (function.modality == Modality.ABSTRACT) return false
|
||||
if (function.name != EQUALS) return false
|
||||
if (function.typeParameters.isNotEmpty()) return false
|
||||
val param = function.valueParameters.singleOrNull() ?: return false
|
||||
@@ -66,6 +68,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
|
||||
private fun KtAnalysisSession.matchesHashCodeMethodSignature(function: KtFunctionSymbol): Boolean {
|
||||
if (function.modality == Modality.ABSTRACT) return false
|
||||
if (function.name != HASH_CODE) return false
|
||||
if (function.typeParameters.isNotEmpty()) return false
|
||||
if (function.valueParameters.isNotEmpty()) return false
|
||||
@@ -341,12 +344,10 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
|
||||
Pair(
|
||||
classOrObjectMemberDeclarations.singleOrNull {
|
||||
val function = it.getSymbol() as? KtFunctionSymbol ?: return@singleOrNull false
|
||||
if (function.name != EQUALS) return@singleOrNull false
|
||||
matchesEqualsMethodSignature(function)
|
||||
} as? KtNamedFunction,
|
||||
classOrObjectMemberDeclarations.singleOrNull {
|
||||
val function = it.getSymbol() as? KtFunctionSymbol ?: return@singleOrNull false
|
||||
if (function.name != HASH_CODE) return@singleOrNull false
|
||||
matchesHashCodeMethodSignature(function)
|
||||
} as? KtNamedFunction,
|
||||
)
|
||||
|
||||
+5
@@ -1671,6 +1671,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInExpectClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equalsInInterface.kt")
|
||||
public void testEqualsInInterface() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equalsWithKotlinAnyParam.kt")
|
||||
public void testEqualsWithKotlinAnyParam() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/equalsOrHashCode/equalsWithKotlinAnyParam.kt");
|
||||
|
||||
+5
@@ -5238,6 +5238,11 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
|
||||
runTest("testData/inspectionsLocal/equalsOrHashCode/equalsInExpectClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equalsInInterface.kt")
|
||||
public void testEqualsInInterface() throws Exception {
|
||||
runTest("testData/inspectionsLocal/equalsOrHashCode/equalsInInterface.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equalsWithKotlinAnyParam.kt")
|
||||
public void testEqualsWithKotlinAnyParam() throws Exception {
|
||||
runTest("testData/inspectionsLocal/equalsOrHashCode/equalsWithKotlinAnyParam.kt");
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// PROBLEM: none
|
||||
interface <caret>I {
|
||||
override fun equals(other: Any?): Boolean
|
||||
}
|
||||
Reference in New Issue
Block a user