Formatter: support trailing comma in type arguments
#KT-34744
This commit is contained in:
@@ -619,6 +619,10 @@ abstract class KotlinCommonBlock(
|
||||
trailingCommaWrappingStrategyWithMultiLineCheck(LT, GT)(childElement)
|
||||
}
|
||||
|
||||
elementType === TYPE_ARGUMENT_LIST -> return { childElement ->
|
||||
trailingCommaWrappingStrategyWithMultiLineCheck(LT, GT)(childElement)
|
||||
}
|
||||
|
||||
elementType === SUPER_TYPE_LIST -> {
|
||||
val wrap = Wrap.createWrap(commonSettings.EXTENDS_LIST_WRAP, false)
|
||||
return { childElement -> if (childElement.psi is KtSuperTypeListEntry) wrap else null }
|
||||
|
||||
@@ -50,6 +50,10 @@ private class TrailingCommaVisitor(val settings: CodeStyleSettings) : KtTreeVisi
|
||||
super.visitTypeParameterList(list)
|
||||
}
|
||||
|
||||
override fun visitTypeArgumentList(typeArgumentList: KtTypeArgumentList) = processCommaOwnerIfInRange(typeArgumentList) {
|
||||
super.visitTypeArgumentList(typeArgumentList)
|
||||
}
|
||||
|
||||
private fun processCommaOwnerIfInRange(element: KtElement, preHook: () -> Unit = {}) {
|
||||
if (myPostProcessor.isElementPartlyInRange(element)) {
|
||||
preHook()
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
// SET_TRUE: ALLOW_TRAILING_COMMA
|
||||
|
||||
fun foo() {
|
||||
testtest<
|
||||
foofoo,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo,
|
||||
foofoo, bar>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo, bar
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, bar
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo,
|
||||
bar
|
||||
>()
|
||||
|
||||
testtest<foofoo
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo>()
|
||||
|
||||
testtest<
|
||||
foofoo
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo>>>()
|
||||
|
||||
testtest<
|
||||
foofoo, fososos, testtest<testtest<foofoo>>,
|
||||
>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<
|
||||
foofoo,
|
||||
>>, testsa>()
|
||||
|
||||
testtest<foofoo, *, testtest<testtest<
|
||||
foofoo,
|
||||
>>, testsa>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo,
|
||||
bar /*
|
||||
*/, /* */ foo
|
||||
>()
|
||||
|
||||
testtest</*
|
||||
*/foofoo, foofoo, foofoo, /*
|
||||
|
||||
*/
|
||||
foofoo, bar>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, bar/*
|
||||
*/>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, bar // awdawda
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, /*
|
||||
|
||||
*/
|
||||
bar
|
||||
>()
|
||||
|
||||
testtest<foofoo // fd
|
||||
>()
|
||||
|
||||
testtest< /**/
|
||||
foofoo
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,/**/
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo/*
|
||||
*/, /* */ bar
|
||||
>()
|
||||
|
||||
testtest<foofoo // fd
|
||||
>()
|
||||
|
||||
testtest< /**/
|
||||
foofoo
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,/**/
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, fososos,/*
|
||||
*/
|
||||
testtest<testtest<foofoo>>,
|
||||
>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<
|
||||
foofoo,
|
||||
>>, /**/testsa>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<
|
||||
foofoo,
|
||||
>>/* */, /**/testsa>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<
|
||||
foofoo,
|
||||
>>/*
|
||||
*/, testsa>()
|
||||
|
||||
testtest<foofoo, seee, testtest<testtest<
|
||||
foofoo,
|
||||
>>, /**/testsa>()
|
||||
|
||||
testtest<foofoo, seee, testtest<testtest<
|
||||
foofoo,
|
||||
>>, /*
|
||||
*/testsa>()
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
// SET_TRUE: ALLOW_TRAILING_COMMA
|
||||
|
||||
fun foo() {
|
||||
testtest<
|
||||
foofoo,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo,
|
||||
foofoo, bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo, bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo, bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo,
|
||||
bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo>>>()
|
||||
|
||||
testtest<
|
||||
foofoo, fososos, testtest<testtest<foofoo>>,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, *,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo,
|
||||
bar, /*
|
||||
*/ /* */
|
||||
foo,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
/*
|
||||
*/
|
||||
foofoo, foofoo, foofoo, /*
|
||||
|
||||
*/
|
||||
foofoo, bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo,
|
||||
bar,/*
|
||||
*/
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo, bar, // awdawda
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo, /*
|
||||
|
||||
*/
|
||||
bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, // fd
|
||||
>()
|
||||
|
||||
testtest<
|
||||
/**/
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,/**/
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo,
|
||||
foofoo,/*
|
||||
*/ /* */
|
||||
bar,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, // fd
|
||||
>()
|
||||
|
||||
testtest<
|
||||
/**/
|
||||
foofoo,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,/**/
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, fososos,/*
|
||||
*/
|
||||
testtest<testtest<foofoo>>,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>, /**/
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,/* */ /**/
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,/*
|
||||
*/
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, seee,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>, /**/
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo, seee,
|
||||
testtest<
|
||||
testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>, /*
|
||||
*/
|
||||
testsa,
|
||||
>()
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// SET_TRUE: ALLOW_TRAILING_COMMA
|
||||
|
||||
fun foo() {
|
||||
testtest<foofoo,
|
||||
testtest<testtest<
|
||||
foofoo,
|
||||
>,
|
||||
>,
|
||||
testsa,
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo,
|
||||
foofoo, bar>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo, bar
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, bar
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo,
|
||||
bar
|
||||
>()
|
||||
|
||||
testtest<foofoo
|
||||
>()
|
||||
|
||||
testtest<
|
||||
foofoo>()
|
||||
|
||||
testtest<
|
||||
foofoo
|
||||
>()
|
||||
|
||||
testtest<foofoo,>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo>>>()
|
||||
|
||||
testtest<foofoo, fososos, testtest<testtest<foofoo>>,>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo,>>, testsa>()
|
||||
|
||||
testtest<foofoo, *, testtest<testtest<foofoo,>>, testsa>()
|
||||
|
||||
testtest<
|
||||
foofoo, foofoo, foofoo, foofoo,
|
||||
bar /*
|
||||
*/, /* */ foo
|
||||
>()
|
||||
|
||||
testtest</*
|
||||
*/foofoo, foofoo, foofoo, /*
|
||||
|
||||
*/
|
||||
foofoo, bar>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, bar/*
|
||||
*/>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, bar // awdawda
|
||||
>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo, /*
|
||||
|
||||
*/
|
||||
bar
|
||||
>()
|
||||
|
||||
testtest<foofoo // fd
|
||||
>()
|
||||
|
||||
testtest< /**/
|
||||
foofoo
|
||||
>()
|
||||
|
||||
testtest<foofoo,/**/>()
|
||||
|
||||
testtest<foofoo, foofoo, foofoo, foofoo/*
|
||||
*/ , /* */ bar
|
||||
>()
|
||||
|
||||
testtest<foofoo // fd
|
||||
>()
|
||||
|
||||
testtest< /**/
|
||||
foofoo
|
||||
>()
|
||||
|
||||
testtest<foofoo,/**/>()
|
||||
|
||||
testtest<foofoo, fososos,/*
|
||||
*/ testtest<testtest<foofoo>>,>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo,>>, /**/testsa>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo,>>/* */ , /**/testsa>()
|
||||
|
||||
testtest<foofoo, testtest<testtest<foofoo,>>/*
|
||||
*/ ,testsa>()
|
||||
|
||||
testtest<foofoo, seee, testtest<testtest<foofoo,>>, /**/testsa>()
|
||||
|
||||
testtest<foofoo, seee, testtest<testtest<foofoo,>>, /*
|
||||
*/testsa>()
|
||||
}
|
||||
@@ -1182,6 +1182,24 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/formatter/trailingComma/typeArguments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class TypeArguments extends AbstractFormatterTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInTypeArguments() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/formatter/trailingComma/typeArguments"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("TypeArgumentList.after.kt")
|
||||
public void testTypeArgumentList() throws Exception {
|
||||
runTest("idea/testData/formatter/trailingComma/typeArguments/TypeArgumentList.after.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/formatter/trailingComma/typeParameters")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@@ -1662,6 +1680,24 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/formatter/trailingComma/typeArguments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class TypeArguments extends AbstractFormatterTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTestInverted, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInTypeArguments() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/formatter/trailingComma/typeArguments"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("TypeArgumentList.after.inv.kt")
|
||||
public void testTypeArgumentList() throws Exception {
|
||||
runTest("idea/testData/formatter/trailingComma/typeArguments/TypeArgumentList.after.inv.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/formatter/trailingComma/typeParameters")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user