From da39d45cb119a545dbb875d564e79c97f8cc9221 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 8 Nov 2018 13:59:53 +0300 Subject: [PATCH] Add more "non properties" for atomic classes #KT-25953 Fixed --- .../UsePropertyAccessSyntaxIntention.kt | 19 +++++++++++-------- .../suppressedByAtomicIntegerList.kt | 10 ++++++++++ .../suppressedByAtomicLongList.kt | 9 +++++++++ .../intentions/IntentionTestGenerated.java | 10 ++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicIntegerList.kt create mode 100644 idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicLongList.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt index f2dd490dba7..33d16910923 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/UsePropertyAccessSyntaxIntention.kt @@ -90,17 +90,20 @@ class NotPropertiesServiceImpl(private val project: Project) : NotPropertiesServ companion object { - val default = listOf( + private val atomicMethods = listOf( + "getAndIncrement", "getAndDecrement", "getAcquire", "getOpaque", "getPlain" + ) + + private val atomicClasses = listOf("AtomicInteger", "AtomicLong") + + val default: List = listOf( "java.net.Socket.getInputStream", "java.net.Socket.getOutputStream", "java.net.URLConnection.getInputStream", - "java.net.URLConnection.getOutputStream", - "java.util.concurrent.atomic.AtomicInteger.getAndIncrement", - "java.util.concurrent.atomic.AtomicInteger.getAndDecrement", - "java.util.concurrent.atomic.AtomicLong.getAndIncrement", - "java.util.concurrent.atomic.AtomicLong.getAndDecrement" - ) - + "java.net.URLConnection.getOutputStream" + ) + atomicClasses.flatMap { klass -> + atomicMethods.map { method -> "java.util.concurrent.atomic.$klass.$method" } + } val USE_PROPERTY_ACCESS_INSPECTION: Key = Key.create("UsePropertyAccessSyntax") } diff --git a/idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicIntegerList.kt b/idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicIntegerList.kt new file mode 100644 index 00000000000..a1deb429401 --- /dev/null +++ b/idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicIntegerList.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME +// WITH_JDK +// IS_APPLICABLE: false +// DISABLE-ERRORS +import java.util.concurrent.atomic.AtomicInteger + +fun main() { + val i = AtomicInteger() + val plain = i.getPlain() +} \ No newline at end of file diff --git a/idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicLongList.kt b/idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicLongList.kt new file mode 100644 index 00000000000..6c112a4ec00 --- /dev/null +++ b/idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicLongList.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +// WITH_JDK +// IS_APPLICABLE: false +import java.util.concurrent.atomic.AtomicLong + +fun main() { + val l = AtomicLong() + val x = l.getAndIncrement() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 98c03653002..c394ea451f6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -16261,6 +16261,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest { runTest("idea/testData/intentions/usePropertyAccessSyntax/superCall.kt"); } + @TestMetadata("suppressedByAtomicIntegerList.kt") + public void testSuppressedByAtomicIntegerList() throws Exception { + runTest("idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicIntegerList.kt"); + } + + @TestMetadata("suppressedByAtomicLongList.kt") + public void testSuppressedByAtomicLongList() throws Exception { + runTest("idea/testData/intentions/usePropertyAccessSyntax/suppressedByAtomicLongList.kt"); + } + @TestMetadata("suppressedByNotPropertyList.kt") public void testSuppressedByNotPropertyList() throws Exception { runTest("idea/testData/intentions/usePropertyAccessSyntax/suppressedByNotPropertyList.kt");