diff --git a/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/after.kt.template b/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/after.kt.template
deleted file mode 100644
index 5c6b1e7d565..00000000000
--- a/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/after.kt.template
+++ /dev/null
@@ -1,6 +0,0 @@
-fun foo() {
- val a = arrayOf("a", "b", "c")
- val b = arrayOf("a", "b", "c")
- if (Arrays.equals(a, b)) {
- }
-}
\ No newline at end of file
diff --git a/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/before.kt.template b/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/before.kt.template
deleted file mode 100644
index 827c44c386d..00000000000
--- a/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/before.kt.template
+++ /dev/null
@@ -1,6 +0,0 @@
-fun foo() {
- val a = arrayOf("a", "b", "c")
- val b = arrayOf("a", "b", "c")
- if (a == b) {
- }
-}
\ No newline at end of file
diff --git a/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/description.html b/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/description.html
deleted file mode 100644
index ae679a64594..00000000000
--- a/idea/resources/intentionDescriptions/ReplaceArrayEqualityOpWithArraysEqualsIntention/description.html
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-This intention replace '==' or '!=' operator for arrays with 'Arrays.equals'
-
-
\ No newline at end of file
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index f756c18ce67..537aa326d1d 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -1357,11 +1357,6 @@
Kotlin
-
- org.jetbrains.kotlin.idea.intentions.ReplaceArrayEqualityOpWithArraysEqualsIntention
- Kotlin
-
-
org.jetbrains.kotlin.idea.intentions.ConvertCamelCaseTestFunctionToSpacedIntention
Kotlin
@@ -2058,7 +2053,7 @@
language="kotlin"
/>
- () {
+ override fun applyTo(element: PsiElement, project: Project, editor: Editor?) {
+ val expression = element as? KtBinaryExpression ?: return
+ val right = expression.right ?: return
+ val left = expression.left ?: return
+ val factory = KtPsiFactory(project)
+ val template = buildString {
+ if (expression.operationToken == KtTokens.EXCLEQ) append("!")
+ append("$0.contentEquals($1)")
+ }
+ expression.replace(factory.createExpressionByPattern(template, left, right))
+ }
+
+ override fun isApplicable(element: KtBinaryExpression): Boolean {
+ val operationToken = element.operationToken
+ when (operationToken) {
+ KtTokens.EQEQ, KtTokens.EXCLEQ -> {}
+ else -> return false
+ }
+ val right = element.right
+ val left = element.left
+ if (right == null || left == null) return false
+ val context = element.analyze()
+ val rightResolvedCall = right.getResolvedCall(context)
+ val leftResolvedCall = left.getResolvedCall(context)
+ return rightResolvedCall?.resolvedToArrayType() == true && leftResolvedCall?.resolvedToArrayType() == true
+ }
+
+ override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession) =
+ object : KtVisitorVoid() {
+ override fun visitBinaryExpression(expression: KtBinaryExpression) {
+ super.visitBinaryExpression(expression)
+ visitTargetElement(expression, holder, isOnTheFly)
+ }
+ }
+
+ override fun inspectionText(element: KtBinaryExpression) = "Dangerous array comparison"
+
+ override val defaultFixText: String
+ get() = "Replace with 'contentEquals'"
+
+ override fun fixText(element: KtBinaryExpression): String = when (element.operationToken) {
+ KtTokens.EQEQ -> "Replace '==' with 'contentEquals'"
+ KtTokens.EXCLEQ -> "Replace '!=' with 'contentEquals'"
+ else -> ""
+ }
+}
diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceArrayEqualityOpWithArraysEqualsIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceArrayEqualityOpWithArraysEqualsIntention.kt
deleted file mode 100644
index bb2c68f46c7..00000000000
--- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceArrayEqualityOpWithArraysEqualsIntention.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2010-2016 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.kotlin.idea.intentions
-
-import com.intellij.openapi.editor.Editor
-import org.jetbrains.kotlin.idea.caches.resolve.analyze
-import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
-import org.jetbrains.kotlin.lexer.KtTokens
-import org.jetbrains.kotlin.psi.KtBinaryExpression
-import org.jetbrains.kotlin.psi.KtPsiFactory
-import org.jetbrains.kotlin.psi.createExpressionByPattern
-import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
-
-class ReplaceArrayEqualityOpWithArraysEqualsInspection :
- IntentionBasedInspection(ReplaceArrayEqualityOpWithArraysEqualsIntention::class)
-
-class ReplaceArrayEqualityOpWithArraysEqualsIntention : SelfTargetingOffsetIndependentIntention(
- KtBinaryExpression::class.java,
- "Replace '==' with 'contentEquals'"
-) {
-
- override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
- val project = element.project
- val right = element.right ?: return
- val left = element.left ?: return
- val factory = KtPsiFactory(project)
- val template = buildString {
- if (element.operationToken == KtTokens.EXCLEQ) append("!")
- append("$0.contentEquals($1)")
- }
- val expression = factory.createExpressionByPattern(template, left, right)
- element.replace(expression)
- }
-
- override fun isApplicableTo(element: KtBinaryExpression): Boolean {
- val operationToken = element.operationToken
- if (operationToken != KtTokens.EQEQ && operationToken != KtTokens.EXCLEQ) return false
- if (operationToken == KtTokens.EXCLEQ) text = "Replace '!=' with 'contentEquals'"
- val right = element.right ?: return false
- val left = element.left ?: return false
- val rightResolvedCall = right.getResolvedCall(right.analyze()) ?: return false
-
- if (!rightResolvedCall.resolvedToArrayType()) return false
- val leftResolvedCall = left.getResolvedCall(left.analyze()) ?: return false
- return leftResolvedCall.resolvedToArrayType()
- }
-}
\ No newline at end of file
diff --git a/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/expected.xml b/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/expected.xml
index 5a16ebbe2d2..97b5f55e324 100644
--- a/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/expected.xml
+++ b/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/expected.xml
@@ -5,7 +5,7 @@
light_idea_test_case
Replace '==' with 'Arrays.equals'
- Replace '==' with 'contentEquals'
+ Dangerous array comparison
test.kt
@@ -13,6 +13,6 @@
light_idea_test_case
Replace '!=' with 'Arrays.equals'
- Replace '!=' with 'contentEquals'
+ Dangerous array comparison
\ No newline at end of file
diff --git a/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/inspections.test b/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/inspections.test
index 85307db6048..1cc21b9fe7f 100644
--- a/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/inspections.test
+++ b/idea/testData/inspections/replaceArrayEqualityOpWithArraysEquals/inspectionData/inspections.test
@@ -1 +1 @@
-// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.ReplaceArrayEqualityOpWithArraysEqualsInspection
\ No newline at end of file
+// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.ReplaceArrayEqualityOpWithArraysEqualsInspection
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/.inspection b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/.inspection
new file mode 100644
index 00000000000..303f92744dd
--- /dev/null
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/.inspection
@@ -0,0 +1 @@
+org.jetbrains.kotlin.idea.inspections.ReplaceArrayEqualityOpWithArraysEqualsInspection
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt
similarity index 81%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt
index 3031f48cd2c..80bccb66dd7 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt
@@ -1,4 +1,4 @@
-// IS_APPLICABLE: false
+// PROBLEM: none
fun foo() {
val a = arrayOf("a", "b", "c")
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt
similarity index 71%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt
index 62ad7d293b1..6fd0142be0e 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt
@@ -1,5 +1,5 @@
// WITH_RUNTIME
-// INTENTION_TEXT: Replace '==' with 'contentEquals'
+// FIX: Replace '==' with 'contentEquals'
fun foo() {
val a = arrayOf("a", "b", "c")
val b = arrayOf("a", "b", "c")
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt.after b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt.after
similarity index 71%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt.after
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt.after
index 336db699b6c..65b2b42fdd0 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt.after
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt.after
@@ -1,5 +1,5 @@
// WITH_RUNTIME
-// INTENTION_TEXT: Replace '==' with 'contentEquals'
+// FIX: Replace '==' with 'contentEquals'
fun foo() {
val a = arrayOf("a", "b", "c")
val b = arrayOf("a", "b", "c")
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt
similarity index 71%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt
index 3f58434033d..892b713657f 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt
@@ -1,5 +1,5 @@
// WITH_RUNTIME
-// INTENTION_TEXT: Replace '!=' with 'contentEquals'
+// FIX: Replace '!=' with 'contentEquals'
fun foo() {
val a = arrayOf("a", "b", "c")
val b = arrayOf("a", "b", "c")
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt.after b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt.after
similarity index 72%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt.after
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt.after
index 0b53d65dbec..dcad9625b3b 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt.after
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt.after
@@ -1,5 +1,5 @@
// WITH_RUNTIME
-// INTENTION_TEXT: Replace '!=' with 'contentEquals'
+// FIX: Replace '!=' with 'contentEquals'
fun foo() {
val a = arrayOf("a", "b", "c")
val b = arrayOf("a", "b", "c")
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt
similarity index 72%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt
index 6556b587a6a..905cb61ecb1 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt
@@ -1,5 +1,5 @@
// WITH_RUNTIME
-// INTENTION_TEXT: Replace '==' with 'contentEquals'
+// FIX: Replace '==' with 'contentEquals'
fun foo() {
val a = charArrayOf('a', 'b', 'c')
val b = charArrayOf('a', 'b', 'c')
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt.after b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt.after
similarity index 73%
rename from idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt.after
rename to idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt.after
index 8471bf494e8..f81794060e1 100644
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt.after
+++ b/idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt.after
@@ -1,5 +1,5 @@
// WITH_RUNTIME
-// INTENTION_TEXT: Replace '==' with 'contentEquals'
+// FIX: Replace '==' with 'contentEquals'
fun foo() {
val a = charArrayOf('a', 'b', 'c')
val b = charArrayOf('a', 'b', 'c')
diff --git a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/.intention b/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/.intention
deleted file mode 100644
index 3fb35aed18c..00000000000
--- a/idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/.intention
+++ /dev/null
@@ -1 +0,0 @@
-org.jetbrains.kotlin.idea.intentions.ReplaceArrayEqualityOpWithArraysEqualsIntention
diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
index 600e9a32f6d..1301bce8b75 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
@@ -2379,6 +2379,39 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
+ @TestMetadata("idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals")
+ @TestDataPath("$PROJECT_ROOT")
+ @RunWith(JUnit3RunnerWithInners.class)
+ public static class ReplaceArrayEqualityOpWithArraysEquals extends AbstractLocalInspectionTest {
+ public void testAllFilesPresentInReplaceArrayEqualityOpWithArraysEquals() throws Exception {
+ KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
+ }
+
+ @TestMetadata("arrayAndOtherTypeEQEQ.kt")
+ public void testArrayAndOtherTypeEQEQ() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt");
+ doTest(fileName);
+ }
+
+ @TestMetadata("arrayEQEQ.kt")
+ public void testArrayEQEQ() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt");
+ doTest(fileName);
+ }
+
+ @TestMetadata("arrayEXCLEQ.kt")
+ public void testArrayEXCLEQ() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt");
+ doTest(fileName);
+ }
+
+ @TestMetadata("primitiveArrayEQEQ.kt")
+ public void testPrimitiveArrayEQEQ() throws Exception {
+ String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt");
+ doTest(fileName);
+ }
+ }
+
@TestMetadata("idea/testData/inspectionsLocal/replaceArrayOfWithLiteral")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
index 6be7e9b11f5..3f6384a47de 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java
@@ -13899,39 +13899,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
}
}
- @TestMetadata("idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals")
- @TestDataPath("$PROJECT_ROOT")
- @RunWith(JUnit3RunnerWithInners.class)
- public static class ReplaceArrayEqualityOpWithArraysEquals extends AbstractIntentionTest {
- public void testAllFilesPresentInReplaceArrayEqualityOpWithArraysEquals() throws Exception {
- KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
- }
-
- @TestMetadata("arrayAndOtherTypeEQEQ.kt")
- public void testArrayAndOtherTypeEQEQ() throws Exception {
- String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayAndOtherTypeEQEQ.kt");
- doTest(fileName);
- }
-
- @TestMetadata("arrayEQEQ.kt")
- public void testArrayEQEQ() throws Exception {
- String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEQEQ.kt");
- doTest(fileName);
- }
-
- @TestMetadata("arrayEXCLEQ.kt")
- public void testArrayEXCLEQ() throws Exception {
- String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/arrayEXCLEQ.kt");
- doTest(fileName);
- }
-
- @TestMetadata("primitiveArrayEQEQ.kt")
- public void testPrimitiveArrayEQEQ() throws Exception {
- String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/replaceArrayEqualityOpWithArraysEquals/primitiveArrayEQEQ.kt");
- doTest(fileName);
- }
- }
-
@TestMetadata("idea/testData/intentions/replaceExplicitFunctionLiteralParamWithIt")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)