From 1875d129ea1f5ed13975bb74f76a1f0fc613a656 Mon Sep 17 00:00:00 2001 From: kenji tomita Date: Tue, 22 Aug 2017 08:38:54 +0900 Subject: [PATCH] Inspection to get rid of unnecessary ticks in references #KT-18124 Fixed --- .../RemoveRedundantBackticks.html | 5 ++ idea/src/META-INF/plugin.xml | 11 ++- .../RemoveRedundantBackticksInspection.kt | 70 +++++++++++++++++++ .../removeRedundantBackticks/.inspection | 1 + .../functionArgument.kt | 3 + .../functionArgument.kt.after | 3 + .../removeRedundantBackticks/functionCall.kt | 4 ++ .../functionCall.kt.after | 4 ++ .../identifierContainingSpaces.kt | 4 ++ .../removeRedundantBackticks/keyword.kt | 7 ++ .../removeRedundantBackticks/property.kt | 4 ++ .../property.kt.after | 4 ++ .../LocalInspectionTestGenerated.java | 38 ++++++++++ 13 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 idea/resources/inspectionDescriptions/RemoveRedundantBackticks.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantBackticksInspection.kt create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/.inspection create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/functionArgument.kt create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/functionArgument.kt.after create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt.after create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/identifierContainingSpaces.kt create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/keyword.kt create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt create mode 100644 idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt.after diff --git a/idea/resources/inspectionDescriptions/RemoveRedundantBackticks.html b/idea/resources/inspectionDescriptions/RemoveRedundantBackticks.html new file mode 100644 index 00000000000..f322397fa06 --- /dev/null +++ b/idea/resources/inspectionDescriptions/RemoveRedundantBackticks.html @@ -0,0 +1,5 @@ + + +This inspection reports the redundant backticks in references + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 24499046fdb..2a8d2c3e9cb 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -2497,8 +2497,15 @@ enabledByDefault="true" cleanupTool="true" level="WEAK WARNING" - language="kotlin" - /> + language="kotlin"/> + + `a`: Int) { +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/functionArgument.kt.after b/idea/testData/inspectionsLocal/removeRedundantBackticks/functionArgument.kt.after new file mode 100644 index 00000000000..ba304535b55 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/functionArgument.kt.after @@ -0,0 +1,3 @@ +// WITH_RUNTIME +fun foo(a: Int) { +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt b/idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt new file mode 100644 index 00000000000..6cfe15c85cd --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun foo() { + `print`("I don't want to use ticks in Kotlin anymore") +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt.after b/idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt.after new file mode 100644 index 00000000000..f335140c3b9 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun foo() { + print("I don't want to use ticks in Kotlin anymore") +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/identifierContainingSpaces.kt b/idea/testData/inspectionsLocal/removeRedundantBackticks/identifierContainingSpaces.kt new file mode 100644 index 00000000000..a9930079a77 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/identifierContainingSpaces.kt @@ -0,0 +1,4 @@ +// PROBLEM: none +fun foo() { + val ` two words ` = "two words" +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/keyword.kt b/idea/testData/inspectionsLocal/removeRedundantBackticks/keyword.kt new file mode 100644 index 00000000000..981975f5c35 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/keyword.kt @@ -0,0 +1,7 @@ +// PROBLEM: none +fun foo() { + `is`("bar") +} + +fun `is`(x: String) { +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt b/idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt new file mode 100644 index 00000000000..052d82ffb91 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun foo() { + val `a` = 1 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt.after b/idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt.after new file mode 100644 index 00000000000..af779ebb806 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun foo() { + val a = 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 ac101485079..b7e9fea5c22 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2949,6 +2949,44 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { @TestMetadata("sameVisibility3.kt") public void testSameVisibility3() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSetter/sameVisibility3.kt"); + } + } + + @TestMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveRedundantBackticks extends AbstractLocalInspectionTest { + public void testAllFilesPresentInRemoveRedundantBackticks() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/removeRedundantBackticks"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("functionArgument.kt") + public void testFunctionArgument() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks/functionArgument.kt"); + doTest(fileName); + } + + @TestMetadata("functionCall.kt") + public void testFunctionCall() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks/functionCall.kt"); + doTest(fileName); + } + + @TestMetadata("identifierContainingSpaces.kt") + public void testIdentifierContainingSpaces() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks/identifierContainingSpaces.kt"); + doTest(fileName); + } + + @TestMetadata("keyword.kt") + public void testKeyword() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks/keyword.kt"); + doTest(fileName); + } + + @TestMetadata("property.kt") + public void testProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks/property.kt"); doTest(fileName); } }