Indent default parameter values

#KT-22508 Fixed
This commit is contained in:
Dmitry Jemerov
2018-02-04 22:17:20 +01:00
parent 5bb195df9b
commit 3aaad0c21d
5 changed files with 63 additions and 1 deletions
@@ -790,7 +790,12 @@ private val INDENT_RULES = arrayOf(
KtTokens.TYPE_ALIAS_KEYWORD, KtTokens.EOL_COMMENT, KtNodeTypes.MODIFIER_LIST, KtTokens.BLOCK_COMMENT,
KtTokens.DOC_COMMENT
)
.set(Indent.getContinuationIndent())
.set(Indent.getContinuationIndent()),
strategy("Default parameter values")
.within(KtNodeTypes.VALUE_PARAMETER)
.forElement { node -> node.psi != null && node.psi == (node.psi.parent as? KtParameter)?.defaultValue }
.continuationIf(KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_EXPRESSION_BODIES, indentFirst = true)
)
@@ -0,0 +1,12 @@
fun foo(
x: Int =
42
) {
}
class C(
val x: Int =
42
)
// SET_TRUE: CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
@@ -0,0 +1,12 @@
fun foo(
x: Int =
42
) {
}
class C(
val x: Int =
42
)
// SET_TRUE: CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
@@ -0,0 +1,12 @@
fun foo(
x: Int =
42
) {
}
class C(
val x: Int =
42
)
// SET_TRUE: CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
@@ -1184,6 +1184,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
doTest(fileName);
}
@TestMetadata("DefaultParameterValues.after.kt")
public void testDefaultParameterValues() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/parameterList/DefaultParameterValues.after.kt");
doTest(fileName);
}
@TestMetadata("KT19727.after.kt")
public void testKT19727() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/parameterList/KT19727.after.kt");
@@ -1544,5 +1550,20 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
doTestInverted(fileName);
}
}
@TestMetadata("idea/testData/formatter/parameterList")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ParameterList extends AbstractFormatterTest {
public void testAllFilesPresentInParameterList() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/formatter/parameterList"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), TargetBackend.ANY, true);
}
@TestMetadata("DefaultParameterValues.after.inv.kt")
public void testDefaultParameterValues() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/parameterList/DefaultParameterValues.after.inv.kt");
doTestInverted(fileName);
}
}
}
}