From 58e5dc7d415e1118b279b2b9c85dff83e56069dd Mon Sep 17 00:00:00 2001 From: "Victoria.Petrakovich" Date: Wed, 16 Oct 2024 16:58:31 +0200 Subject: [PATCH] [kotlin] Move excluded Java methods to the K2 implementation of NotPropertiesService KTIJ-31157 Temporarily exclude `isEmpty` from properties that UsePropertyAccessSyntaxInspection processes (cherry picked from commit 9fda5d9408ea0b2aee4498cf8614426a1dfe7b8c) IJ-CR-146866 GitOrigin-RevId: 5d290703ee25edf4e3f18824f05b212a95559759 --- .../kotlin/idea/core/NotPropertiesService.kt | 3 --- .../UsePropertyAccessSyntaxInspection.kt | 13 +++++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/kotlin/base/code-insight/src/org/jetbrains/kotlin/idea/core/NotPropertiesService.kt b/plugins/kotlin/base/code-insight/src/org/jetbrains/kotlin/idea/core/NotPropertiesService.kt index c210b929eed2..7367f0e082ba 100644 --- a/plugins/kotlin/base/code-insight/src/org/jetbrains/kotlin/idea/core/NotPropertiesService.kt +++ b/plugins/kotlin/base/code-insight/src/org/jetbrains/kotlin/idea/core/NotPropertiesService.kt @@ -28,9 +28,6 @@ interface NotPropertiesService { for (byteBufferMethod in listOf("getChar", "getDouble", "getFloat", "getInt", "getLong", "getShort")) { add("java.nio.ByteBuffer.$byteBufferMethod") } - - add("java.util.AbstractCollection.isEmpty") // KTIJ-31157 - add("java.util.AbstractMap.isEmpty") // KTIJ-31157 } fun getNotProperties(element: PsiElement): Set { diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt index 484545d27c20..b8c36ac24b9d 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt @@ -646,7 +646,10 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns ) KotlinBundle.message("use.of.setter.method.instead.of.property.access.syntax") else KotlinBundle.message("use.of.getter.method.instead.of.property.access.syntax") - val propertiesNotToReplace = NotPropertiesService.DEFAULT.map(::FqNameUnsafe).toMutableSet() + val propertiesNotToReplace = + (NotPropertiesService.DEFAULT.map(::FqNameUnsafe) + + FqNameUnsafe("java.util.AbstractCollection.isEmpty") // KTIJ-31157 + + FqNameUnsafe("java.util.AbstractMap.isEmpty")).toMutableSet() // KTIJ-31157 // Serialized setting @Suppress("MemberVisibilityCanBePrivate") @@ -692,7 +695,13 @@ class NotPropertiesServiceImpl(private val project: Project) : NotPropertiesServ override fun getNotProperties(element: PsiElement): Set { val profile = InspectionProjectProfileManager.getInstance(project).currentProfile val tool = profile.getUnwrappedTool(USE_PROPERTY_ACCESS_INSPECTION, element) - return (tool?.propertiesNotToReplace ?: NotPropertiesService.DEFAULT.map(::FqNameUnsafe)).toSet() + var propertiesNotToReplace = tool?.propertiesNotToReplace + if (propertiesNotToReplace == null) { + propertiesNotToReplace = NotPropertiesService.DEFAULT.map(::FqNameUnsafe).toMutableSet() + propertiesNotToReplace.add(FqNameUnsafe("java.util.AbstractCollection.isEmpty")) // KTIJ-31157 + propertiesNotToReplace.add(FqNameUnsafe("java.util.AbstractMap.isEmpty")) // KTIJ-31157 + } + return propertiesNotToReplace } companion object {