From 7328f7510334a67fba508b26da02ceb343983944 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Thu, 22 Mar 2018 06:44:36 +0300 Subject: [PATCH] Don't suggest 'Redundant semicolon' before lambda extension call So #KT-23152 Fixed --- .../idea/inspections/RedundantSemicolonInspection.kt | 6 +++++- .../redundantSemicolon/beforeAnnotationAndLambda.kt | 11 +++++++++++ .../redundantSemicolon/beforeKDocAndLambda.kt | 10 ++++++++++ .../inspections/LocalInspectionTestGenerated.java | 12 ++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/beforeAnnotationAndLambda.kt create mode 100644 idea/testData/inspectionsLocal/redundantSemicolon/beforeKDocAndLambda.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt index f736eb495d0..6e33e80f8ec 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantSemicolonInspection.kt @@ -23,6 +23,7 @@ import com.intellij.psi.PsiComment import com.intellij.psi.PsiElement import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiWhiteSpace +import org.jetbrains.kotlin.kdoc.psi.api.KDoc import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.* @@ -74,7 +75,10 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns return false } - if (nextLeaf?.nextLeaf { it !is PsiWhiteSpace && it !is PsiComment }?.node?.elementType == KtTokens.LBRACE) { + if (nextLeaf?.nextLeaf { + it !is PsiWhiteSpace && it !is PsiComment && it.getStrictParentOfType() == null && + it.getStrictParentOfType() == null + }?.node?.elementType == KtTokens.LBRACE) { return false // case with statement starting with '{' and call on the previous line } diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/beforeAnnotationAndLambda.kt b/idea/testData/inspectionsLocal/redundantSemicolon/beforeAnnotationAndLambda.kt new file mode 100644 index 00000000000..eed25f7304a --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/beforeAnnotationAndLambda.kt @@ -0,0 +1,11 @@ +// PROBLEM: none +fun test() { + foo(); + @Ann("") + { i: Int -> }.doIt() +} +fun foo() {} +fun ((Int) -> Unit).doIt() {} + +@Target(AnnotationTarget.EXPRESSION) +annotation class Ann(val bar: String) \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantSemicolon/beforeKDocAndLambda.kt b/idea/testData/inspectionsLocal/redundantSemicolon/beforeKDocAndLambda.kt new file mode 100644 index 00000000000..046b06d791c --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantSemicolon/beforeKDocAndLambda.kt @@ -0,0 +1,10 @@ +// PROBLEM: none +fun test() { + foo(); + /** + * kdoc + */ + { i: Int -> }.doIt() +} +fun foo() {} +fun ((Int) -> Unit).doIt() {} diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index e82b446d5b0..d0d5a910556 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2913,12 +2913,24 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/redundantSemicolon"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); } + @TestMetadata("beforeAnnotationAndLambda.kt") + public void testBeforeAnnotationAndLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/beforeAnnotationAndLambda.kt"); + doTest(fileName); + } + @TestMetadata("beforeCommentAndLambda.kt") public void testBeforeCommentAndLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/beforeCommentAndLambda.kt"); doTest(fileName); } + @TestMetadata("beforeKDocAndLambda.kt") + public void testBeforeKDocAndLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/beforeKDocAndLambda.kt"); + doTest(fileName); + } + @TestMetadata("companionBeforeFun.kt") public void testCompanionBeforeFun() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantSemicolon/companionBeforeFun.kt");