From 63ee72392884bbbf222feecb1132894526a7799a Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Thu, 23 Jan 2020 00:24:55 +0700 Subject: [PATCH] TrailingCommaPostFormatProcessor: improve `findInvalidCommas` Add case for line break between argument and comma #KT-34744 --- .../TrailingCommaPostFormatProcessor.kt | 16 +- .../inspections/TrailingCommaInspection.kt | 12 +- .../kotlin/idea/quickfix/ReformatQuickFix.kt | 10 +- .../inspectionData/expected.xml | 468 ++++++++++++++++++ .../inspectionData/expected.xml | 432 ++++++++++++++++ .../inspectionData/expected.xml | 468 ++++++++++++++++++ .../inspectionData/expected.xml | 432 ++++++++++++++++ .../trailingComma/changeCommaPosition5.kt | 9 + .../changeCommaPosition5.kt.after | 9 + .../LocalInspectionTestGenerated.java | 16 +- 10 files changed, 1848 insertions(+), 24 deletions(-) create mode 100644 idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt create mode 100644 idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt.after diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt index d12b9ddd05b..3420bbf0977 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/TrailingCommaPostFormatProcessor.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Comp import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Companion.trailingCommaAllowedInModule import org.jetbrains.kotlin.idea.formatter.TrailingCommaPostFormatProcessor.Companion.trailingCommaOrLastElement import org.jetbrains.kotlin.idea.project.languageVersionSettings +import org.jetbrains.kotlin.idea.util.isLineBreak import org.jetbrains.kotlin.idea.util.isMultiline import org.jetbrains.kotlin.idea.util.module import org.jetbrains.kotlin.idea.util.needTrailingComma @@ -39,12 +40,15 @@ class TrailingCommaPostFormatProcessor : PostFormatProcessor { TrailingCommaPostFormatVisitor(settings).processText(source, rangeToReformat) companion object { - fun findInvalidCommas(commaOwner: KtElement): List = commaOwner.firstChild?.siblings(withItself = false)?.mapNotNull { - if (it.isComma && it.leafIgnoringWhitespace(false) != it.leafIgnoringWhitespaceAndComments(false)) - it - else - null - }?.toList().orEmpty() + fun findInvalidCommas(commaOwner: KtElement): List = commaOwner.firstChild + ?.siblings(withItself = false) + ?.mapNotNull { element -> + if (!element.isComma) return@mapNotNull null + element.takeIf { + it.prevLeaf(true)?.isLineBreak() == true || + it.leafIgnoringWhitespace(false) != it.leafIgnoringWhitespaceAndComments(false) + } + }?.toList().orEmpty() fun needComma( commaOwner: KtElement, diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt index 2f5e41c3a94..ecccd2b4b50 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/TrailingCommaInspection.kt @@ -103,7 +103,7 @@ class TrailingCommaInspection( fixMessage: String, highlightType: ProblemHighlightType = ProblemHighlightType.GENERIC_ERROR_OR_WARNING, ) { - val commaOwner = commaOrElement.parent + val commaOwner = commaOrElement.parent as KtElement // case for KtFunctionLiteral, where PsiWhiteSpace after KtTypeParameterList isn't included in this list val problemOwner = commaOwner.parent holder.registerProblem( @@ -111,7 +111,7 @@ class TrailingCommaInspection( message, highlightType, commaOrElement.textRangeOfCommaOrSymbolAfter.shiftLeft(problemOwner.startOffset), - ReformatQuickFix(fixMessage, commaOwner), + ReformatQuickFix(fixMessage, commaOwner, createFormatterTextRange(commaOwner)), ) } @@ -126,10 +126,16 @@ class TrailingCommaInspection( "Missing line break", highlightType, TextRange.from(elementForTextRange.startOffset, 1).shiftLeft(problemElement.startOffset), - ReformatQuickFix("Add line break", commaOwner), + ReformatQuickFix("Add line break", commaOwner, createFormatterTextRange(commaOwner)), ) } + private fun createFormatterTextRange(commaOwner: KtElement): TextRange { + val startElement = TrailingCommaPostFormatProcessor.elementBeforeFirstElement(commaOwner) ?: commaOwner + val endElement = TrailingCommaPostFormatProcessor.elementAfterLastElement(commaOwner) ?: commaOwner + return TextRange.create(startElement.startOffset, endElement.endOffset) + } + private val PsiElement.textRangeOfCommaOrSymbolAfter: TextRange get() { val textRange = textRange diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt index 3eceed10805..99ba2686a6c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReformatQuickFix.kt @@ -8,11 +8,12 @@ package org.jetbrains.kotlin.idea.quickfix import com.intellij.codeInspection.LocalQuickFix import com.intellij.codeInspection.ProblemDescriptor import com.intellij.openapi.project.Project +import com.intellij.openapi.util.TextRange import com.intellij.psi.PsiElement import com.intellij.psi.codeStyle.CodeStyleManager import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer -class ReformatQuickFix(private val description: String, element: PsiElement? = null) : LocalQuickFix { +class ReformatQuickFix(private val description: String, element: PsiElement? = null, val textRange: TextRange? = null) : LocalQuickFix { private val elementPoint = element?.createSmartPointer() override fun getName(): String = description @@ -21,7 +22,12 @@ class ReformatQuickFix(private val description: String, element: PsiElement? = n override fun applyFix(project: Project, descriptor: ProblemDescriptor) { (elementPoint?.element ?: descriptor.psiElement)?.let { - CodeStyleManager.getInstance(project).reformat(it) + val codeStyleManager = CodeStyleManager.getInstance(project) + if (textRange != null) { + codeStyleManager.reformatRange(it, textRange.startOffset, textRange.endOffset) + } else { + codeStyleManager.reformat(it) + } } } } diff --git a/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml index 06f33db6376..d0e604f533a 100644 --- a/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml +++ b/idea/testData/inspections/trailingCommaOffWithCodeStyle/inspectionData/expected.xml @@ -815,6 +815,18 @@ 33 1 + + ArgumentList.kt + 208 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 207 @@ -899,6 +911,18 @@ 25 1 + + ArgumentList.kt + 214 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 213 @@ -1631,6 +1655,18 @@ 18 1 + + ParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 46 @@ -1655,6 +1691,18 @@ 18 1 + + ParameterList.kt + 108 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 108 @@ -1691,6 +1739,18 @@ 18 1 + + ParameterList.kt + 145 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 145 @@ -1739,6 +1799,18 @@ 18 1 + + ParameterList.kt + 194 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 194 @@ -1763,6 +1835,18 @@ 18 1 + + ParameterList.kt + 217 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 217 @@ -1787,6 +1871,18 @@ 18 1 + + ParameterList.kt + 232 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 232 @@ -1811,6 +1907,18 @@ 21 1 + + ParameterList.kt + 255 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 255 @@ -1823,6 +1931,18 @@ 8 1 + + ParameterList.kt + 260 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 260 @@ -1871,6 +1991,18 @@ 17 1 + + ParameterList.kt + 338 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 17 + 1 + ParameterList.kt 337 @@ -1907,6 +2039,18 @@ 14 1 + + ParameterList.kt + 357 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 357 @@ -1931,6 +2075,18 @@ 14 1 + + ParameterList.kt + 380 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 380 @@ -1955,6 +2111,18 @@ 14 1 + + ParameterList.kt + 395 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 395 @@ -1967,6 +2135,18 @@ 5 1 + + ParameterList.kt + 399 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 410 @@ -1991,6 +2171,18 @@ 20 1 + + ParameterList.kt + 418 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 418 @@ -2051,6 +2243,18 @@ 8 1 + + ParameterList.kt + 454 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 454 @@ -3239,6 +3443,18 @@ 38 1 + + LambdaParameterList.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 33 @@ -3263,6 +3479,18 @@ 14 1 + + LambdaParameterList.kt + 64 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 64 @@ -3287,6 +3515,18 @@ 13 1 + + LambdaParameterList.kt + 87 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 87 @@ -3311,6 +3551,18 @@ 17 1 + + LambdaParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 115 @@ -3323,6 +3575,18 @@ 8 1 + + LambdaParameterList.kt + 122 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 122 @@ -3347,6 +3611,18 @@ 9 1 + + LambdaParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 160 @@ -3395,6 +3671,18 @@ 8 1 + + LambdaParameterList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 182 @@ -3443,6 +3731,18 @@ 14 1 + + TypeParameterList.kt + 23 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 23 @@ -3467,6 +3767,18 @@ 14 1 + + TypeParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 46 @@ -3491,6 +3803,18 @@ 14 1 + + TypeParameterList.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 61 @@ -3515,6 +3839,18 @@ 17 1 + + TypeParameterList.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 84 @@ -3527,6 +3863,18 @@ 8 1 + + TypeParameterList.kt + 89 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 89 @@ -3575,6 +3923,18 @@ 14 1 + + TypeParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 115 @@ -3599,6 +3959,18 @@ 14 1 + + TypeParameterList.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 138 @@ -3623,6 +3995,18 @@ 14 1 + + TypeParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 153 @@ -3635,6 +4019,18 @@ 5 1 + + TypeParameterList.kt + 157 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 168 @@ -3659,6 +4055,18 @@ 20 1 + + TypeParameterList.kt + 176 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 176 @@ -3695,6 +4103,18 @@ 9 1 + + TypeParameterList.kt + 202 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 207 @@ -3743,6 +4163,18 @@ 8 1 + + TypeParameterList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 223 @@ -3755,6 +4187,18 @@ 8 1 + + TypeParameterList.kt + 235 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 240 @@ -3971,6 +4415,18 @@ 56 1 + + TypeArgumentList.kt + 41 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + TypeArgumentList.kt 40 @@ -4631,6 +5087,18 @@ 42 1 + + IndicesAccess.kt + 75 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + IndicesAccess.kt 74 diff --git a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml index 6fd774dbbd0..33b6007179d 100644 --- a/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml +++ b/idea/testData/inspections/trailingCommaOffWithoutCodeStyle/inspectionData/expected.xml @@ -275,6 +275,18 @@ 33 1 + + ArgumentList.kt + 208 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 207 @@ -311,6 +323,18 @@ 15 1 + + ArgumentList.kt + 214 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 213 @@ -803,6 +827,18 @@ 18 1 + + ParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 46 @@ -827,6 +863,18 @@ 18 1 + + ParameterList.kt + 108 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 108 @@ -863,6 +911,18 @@ 18 1 + + ParameterList.kt + 145 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 145 @@ -899,6 +959,18 @@ 18 1 + + ParameterList.kt + 194 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 194 @@ -923,6 +995,18 @@ 18 1 + + ParameterList.kt + 217 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 217 @@ -947,6 +1031,18 @@ 18 1 + + ParameterList.kt + 232 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 232 @@ -971,6 +1067,18 @@ 21 1 + + ParameterList.kt + 255 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 255 @@ -983,6 +1091,18 @@ 8 1 + + ParameterList.kt + 260 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 260 @@ -1031,6 +1151,18 @@ 17 1 + + ParameterList.kt + 338 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 17 + 1 + ParameterList.kt 337 @@ -1067,6 +1199,18 @@ 14 1 + + ParameterList.kt + 357 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 357 @@ -1091,6 +1235,18 @@ 14 1 + + ParameterList.kt + 380 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 380 @@ -1115,6 +1271,18 @@ 14 1 + + ParameterList.kt + 395 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 395 @@ -1127,6 +1295,18 @@ 5 1 + + ParameterList.kt + 399 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 410 @@ -1151,6 +1331,18 @@ 20 1 + + ParameterList.kt + 418 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 418 @@ -1199,6 +1391,18 @@ 8 1 + + ParameterList.kt + 454 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 454 @@ -1535,6 +1739,18 @@ 38 1 + + LambdaParameterList.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 33 @@ -1559,6 +1775,18 @@ 14 1 + + LambdaParameterList.kt + 64 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 64 @@ -1583,6 +1811,18 @@ 13 1 + + LambdaParameterList.kt + 87 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 87 @@ -1607,6 +1847,18 @@ 17 1 + + LambdaParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 115 @@ -1619,6 +1871,18 @@ 8 1 + + LambdaParameterList.kt + 122 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 122 @@ -1679,6 +1943,18 @@ 8 1 + + LambdaParameterList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 182 @@ -1703,6 +1979,18 @@ 14 1 + + TypeParameterList.kt + 23 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 23 @@ -1727,6 +2015,18 @@ 14 1 + + TypeParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 46 @@ -1751,6 +2051,18 @@ 14 1 + + TypeParameterList.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 61 @@ -1775,6 +2087,18 @@ 17 1 + + TypeParameterList.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 84 @@ -1787,6 +2111,18 @@ 8 1 + + TypeParameterList.kt + 89 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 89 @@ -1823,6 +2159,18 @@ 14 1 + + TypeParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 115 @@ -1847,6 +2195,18 @@ 14 1 + + TypeParameterList.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 138 @@ -1871,6 +2231,18 @@ 14 1 + + TypeParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 153 @@ -1883,6 +2255,18 @@ 5 1 + + TypeParameterList.kt + 157 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 168 @@ -1907,6 +2291,18 @@ 20 1 + + TypeParameterList.kt + 176 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 176 @@ -1967,6 +2363,18 @@ 8 1 + + TypeParameterList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 223 @@ -2123,6 +2531,18 @@ 56 1 + + TypeArgumentList.kt + 41 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + TypeArgumentList.kt 40 @@ -2423,6 +2843,18 @@ 42 1 + + IndicesAccess.kt + 75 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + IndicesAccess.kt 74 diff --git a/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml index 99c5e37c18f..95a5233a257 100644 --- a/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml +++ b/idea/testData/inspections/trailingCommaOnWithCodeStyle/inspectionData/expected.xml @@ -1223,6 +1223,18 @@ 33 1 + + ArgumentList.kt + 208 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 207 @@ -1331,6 +1343,18 @@ 25 1 + + ArgumentList.kt + 214 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 213 @@ -2327,6 +2351,18 @@ 18 1 + + ParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 46 @@ -2363,6 +2399,18 @@ 18 1 + + ParameterList.kt + 108 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 108 @@ -2399,6 +2447,18 @@ 18 1 + + ParameterList.kt + 145 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 145 @@ -2471,6 +2531,18 @@ 18 1 + + ParameterList.kt + 194 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 194 @@ -2507,6 +2579,18 @@ 18 1 + + ParameterList.kt + 217 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 217 @@ -2543,6 +2627,18 @@ 18 1 + + ParameterList.kt + 232 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 232 @@ -2579,6 +2675,18 @@ 21 1 + + ParameterList.kt + 255 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 255 @@ -2591,6 +2699,18 @@ 8 1 + + ParameterList.kt + 260 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 260 @@ -2711,6 +2831,18 @@ 17 1 + + ParameterList.kt + 338 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 17 + 1 + ParameterList.kt 337 @@ -2759,6 +2891,18 @@ 14 1 + + ParameterList.kt + 357 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 357 @@ -2795,6 +2939,18 @@ 14 1 + + ParameterList.kt + 380 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 380 @@ -2831,6 +2987,18 @@ 14 1 + + ParameterList.kt + 395 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 395 @@ -2843,6 +3011,18 @@ 5 1 + + ParameterList.kt + 399 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 407 @@ -2879,6 +3059,18 @@ 20 1 + + ParameterList.kt + 418 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 418 @@ -2987,6 +3179,18 @@ 8 1 + + ParameterList.kt + 454 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 454 @@ -4751,6 +4955,18 @@ 38 1 + + LambdaParameterList.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 33 @@ -4787,6 +5003,18 @@ 14 1 + + LambdaParameterList.kt + 64 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 64 @@ -4823,6 +5051,18 @@ 13 1 + + LambdaParameterList.kt + 87 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 87 @@ -4859,6 +5099,18 @@ 17 1 + + LambdaParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 115 @@ -4871,6 +5123,18 @@ 8 1 + + LambdaParameterList.kt + 122 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 122 @@ -4919,6 +5183,18 @@ 10 1 + + LambdaParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 153 @@ -4991,6 +5267,18 @@ 8 1 + + LambdaParameterList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 182 @@ -5075,6 +5363,18 @@ 14 1 + + TypeParameterList.kt + 23 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 23 @@ -5111,6 +5411,18 @@ 14 1 + + TypeParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 46 @@ -5147,6 +5459,18 @@ 14 1 + + TypeParameterList.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 61 @@ -5183,6 +5507,18 @@ 17 1 + + TypeParameterList.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 84 @@ -5195,6 +5531,18 @@ 8 1 + + TypeParameterList.kt + 89 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 89 @@ -5279,6 +5627,18 @@ 14 1 + + TypeParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 115 @@ -5315,6 +5675,18 @@ 14 1 + + TypeParameterList.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 138 @@ -5351,6 +5723,18 @@ 14 1 + + TypeParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 153 @@ -5363,6 +5747,18 @@ 5 1 + + TypeParameterList.kt + 157 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 165 @@ -5399,6 +5795,18 @@ 20 1 + + TypeParameterList.kt + 176 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 176 @@ -5471,6 +5879,18 @@ 10 1 + + TypeParameterList.kt + 202 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 202 @@ -5543,6 +5963,18 @@ 8 1 + + TypeParameterList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 223 @@ -5579,6 +6011,18 @@ 10 1 + + TypeParameterList.kt + 235 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 235 @@ -5903,6 +6347,18 @@ 56 1 + + TypeArgumentList.kt + 41 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + TypeArgumentList.kt 40 @@ -6839,6 +7295,18 @@ 42 1 + + IndicesAccess.kt + 75 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + IndicesAccess.kt 74 diff --git a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml index 6fd774dbbd0..33b6007179d 100644 --- a/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml +++ b/idea/testData/inspections/trailingCommaOnWithoutCodeStyle/inspectionData/expected.xml @@ -275,6 +275,18 @@ 33 1 + + ArgumentList.kt + 208 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 207 @@ -311,6 +323,18 @@ 15 1 + + ArgumentList.kt + 214 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ArgumentList.kt 213 @@ -803,6 +827,18 @@ 18 1 + + ParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 46 @@ -827,6 +863,18 @@ 18 1 + + ParameterList.kt + 108 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 108 @@ -863,6 +911,18 @@ 18 1 + + ParameterList.kt + 145 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 8 + 1 + ParameterList.kt 145 @@ -899,6 +959,18 @@ 18 1 + + ParameterList.kt + 194 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 194 @@ -923,6 +995,18 @@ 18 1 + + ParameterList.kt + 217 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 217 @@ -947,6 +1031,18 @@ 18 1 + + ParameterList.kt + 232 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 232 @@ -971,6 +1067,18 @@ 21 1 + + ParameterList.kt + 255 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 255 @@ -983,6 +1091,18 @@ 8 1 + + ParameterList.kt + 260 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 260 @@ -1031,6 +1151,18 @@ 17 1 + + ParameterList.kt + 338 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 17 + 1 + ParameterList.kt 337 @@ -1067,6 +1199,18 @@ 14 1 + + ParameterList.kt + 357 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 357 @@ -1091,6 +1235,18 @@ 14 1 + + ParameterList.kt + 380 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 380 @@ -1115,6 +1271,18 @@ 14 1 + + ParameterList.kt + 395 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 395 @@ -1127,6 +1295,18 @@ 5 1 + + ParameterList.kt + 399 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 410 @@ -1151,6 +1331,18 @@ 20 1 + + ParameterList.kt + 418 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 418 @@ -1199,6 +1391,18 @@ 8 1 + + ParameterList.kt + 454 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + ParameterList.kt 454 @@ -1535,6 +1739,18 @@ 38 1 + + LambdaParameterList.kt + 33 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 33 @@ -1559,6 +1775,18 @@ 14 1 + + LambdaParameterList.kt + 64 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 64 @@ -1583,6 +1811,18 @@ 13 1 + + LambdaParameterList.kt + 87 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 87 @@ -1607,6 +1847,18 @@ 17 1 + + LambdaParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 115 @@ -1619,6 +1871,18 @@ 8 1 + + LambdaParameterList.kt + 122 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 122 @@ -1679,6 +1943,18 @@ 8 1 + + LambdaParameterList.kt + 182 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + LambdaParameterList.kt 182 @@ -1703,6 +1979,18 @@ 14 1 + + TypeParameterList.kt + 23 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 23 @@ -1727,6 +2015,18 @@ 14 1 + + TypeParameterList.kt + 46 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 46 @@ -1751,6 +2051,18 @@ 14 1 + + TypeParameterList.kt + 61 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 61 @@ -1775,6 +2087,18 @@ 17 1 + + TypeParameterList.kt + 84 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 84 @@ -1787,6 +2111,18 @@ 8 1 + + TypeParameterList.kt + 89 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 89 @@ -1823,6 +2159,18 @@ 14 1 + + TypeParameterList.kt + 115 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 115 @@ -1847,6 +2195,18 @@ 14 1 + + TypeParameterList.kt + 138 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 138 @@ -1871,6 +2231,18 @@ 14 1 + + TypeParameterList.kt + 153 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 153 @@ -1883,6 +2255,18 @@ 5 1 + + TypeParameterList.kt + 157 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 168 @@ -1907,6 +2291,18 @@ 20 1 + + TypeParameterList.kt + 176 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 176 @@ -1967,6 +2363,18 @@ 8 1 + + TypeParameterList.kt + 223 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 4 + 1 + TypeParameterList.kt 223 @@ -2123,6 +2531,18 @@ 56 1 + + TypeArgumentList.kt + 41 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + TypeArgumentList.kt 40 @@ -2423,6 +2843,18 @@ 42 1 + + IndicesAccess.kt + 75 + testProject + light_idea_test_case + + Trailing comma recommendations + Comma loses the advantages in this position + , + 12 + 1 + IndicesAccess.kt 74 diff --git a/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt new file mode 100644 index 00000000000..6d531b803b2 --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt @@ -0,0 +1,9 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Fix comma position + +val x = { + x: Comparable>, + y: String + ,-> + val a = 42 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt.after b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt.after new file mode 100644 index 00000000000..bbf896eb1dd --- /dev/null +++ b/idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt.after @@ -0,0 +1,9 @@ +// COMPILER_ARGUMENTS: -XXLanguage:+TrailingCommas +// FIX: Fix comma position + +val x = { + x: Comparable>, + y: String, + -> + val a = 42 +} \ 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 0a4ada100b6..97d1abf5f89 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -12320,19 +12320,9 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/trailingComma/changeCommaPosition4.kt"); } - @TestMetadata("missingLineBreak.kt") - public void testMissingLineBreak() throws Exception { - runTest("idea/testData/inspectionsLocal/trailingComma/missingLineBreak.kt"); - } - - @TestMetadata("missingLineBreak2.kt") - public void testMissingLineBreak2() throws Exception { - runTest("idea/testData/inspectionsLocal/trailingComma/missingLineBreak2.kt"); - } - - @TestMetadata("missingLineBreak3.kt") - public void testMissingLineBreak3() throws Exception { - runTest("idea/testData/inspectionsLocal/trailingComma/missingLineBreak3.kt"); + @TestMetadata("changeCommaPosition5.kt") + public void testChangeCommaPosition5() throws Exception { + runTest("idea/testData/inspectionsLocal/trailingComma/changeCommaPosition5.kt"); } @TestMetadata("missingLineBreak.kt")