From 37351c344f1c34cb5c4efaf9d9545c807a803bc5 Mon Sep 17 00:00:00 2001 From: kenji tomita Date: Tue, 12 Dec 2017 21:38:17 +0900 Subject: [PATCH] code style inspection: `to -> Pair` function used not in infix form --- .../ReplaceToWithInfixFormInspection.html | 5 ++ idea/src/META-INF/plugin.xml | 12 +++- .../ReplaceToWithInfixFormInspection.kt | 70 +++++++++++++++++++ .../replaceToWithInfixForm/.inspection | 1 + .../replaceToWithInfixForm/base.kt | 7 ++ .../replaceToWithInfixForm/base.kt.after | 7 ++ .../replaceToWithInfixForm/nonPair.kt | 9 +++ .../LocalInspectionTestGenerated.java | 21 ++++++ 8 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 idea/resources/inspectionDescriptions/ReplaceToWithInfixFormInspection.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/inspections/ReplaceToWithInfixFormInspection.kt create mode 100644 idea/testData/inspectionsLocal/replaceToWithInfixForm/.inspection create mode 100644 idea/testData/inspectionsLocal/replaceToWithInfixForm/base.kt create mode 100644 idea/testData/inspectionsLocal/replaceToWithInfixForm/base.kt.after create mode 100644 idea/testData/inspectionsLocal/replaceToWithInfixForm/nonPair.kt diff --git a/idea/resources/inspectionDescriptions/ReplaceToWithInfixFormInspection.html b/idea/resources/inspectionDescriptions/ReplaceToWithInfixFormInspection.html new file mode 100644 index 00000000000..5da45b35307 --- /dev/null +++ b/idea/resources/inspectionDescriptions/ReplaceToWithInfixFormInspection.html @@ -0,0 +1,5 @@ + + +This inspection reports to function calls replaceable with the infix form + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index d34be2d324e..9051626d0eb 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -2683,6 +2683,15 @@ language="kotlin" /> + + - - + to(b) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceToWithInfixForm/base.kt.after b/idea/testData/inspectionsLocal/replaceToWithInfixForm/base.kt.after new file mode 100644 index 00000000000..499c40d4051 --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceToWithInfixForm/base.kt.after @@ -0,0 +1,7 @@ +// WITH_RUNTIME +class A +class B + +fun foo(a: A, b: B) { + val pair = a to b +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/replaceToWithInfixForm/nonPair.kt b/idea/testData/inspectionsLocal/replaceToWithInfixForm/nonPair.kt new file mode 100644 index 00000000000..04591f42c1f --- /dev/null +++ b/idea/testData/inspectionsLocal/replaceToWithInfixForm/nonPair.kt @@ -0,0 +1,9 @@ +// PROBLEM: none +class A { + fun to(x: Int) { + } +} + +fun foo() { + A().to(1) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 7347a7c79c7..9072ec61861 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2463,6 +2463,27 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/replaceToWithInfixForm") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ReplaceToWithInfixForm extends AbstractLocalInspectionTest { + public void testAllFilesPresentInReplaceToWithInfixForm() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/replaceToWithInfixForm"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("base.kt") + public void testBase() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceToWithInfixForm/base.kt"); + doTest(fileName); + } + + @TestMetadata("nonPair.kt") + public void testNonPair() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/replaceToWithInfixForm/nonPair.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/inspectionsLocal/selfAssignment") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)