Option to use normal indent in chained calls
#KT-18605 Fixed
This commit is contained in:
+1
@@ -42,6 +42,7 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
|
|||||||
public boolean IMPORT_NESTED_CLASSES = false;
|
public boolean IMPORT_NESTED_CLASSES = false;
|
||||||
public boolean CONTINUATION_INDENT_IN_PARAMETER_LISTS = true;
|
public boolean CONTINUATION_INDENT_IN_PARAMETER_LISTS = true;
|
||||||
public boolean CONTINUATION_INDENT_FOR_EXPRESSION_BODIES = true;
|
public boolean CONTINUATION_INDENT_FOR_EXPRESSION_BODIES = true;
|
||||||
|
public boolean CONTINUATION_INDENT_FOR_CHAINED_CALLS = true;
|
||||||
|
|
||||||
public KotlinCodeStyleSettings(CodeStyleSettings container) {
|
public KotlinCodeStyleSettings(CodeStyleSettings container) {
|
||||||
super("JetCodeStyleSettings", container);
|
super("JetCodeStyleSettings", container);
|
||||||
|
|||||||
@@ -94,10 +94,14 @@ abstract class KotlinCommonBlock(
|
|||||||
// relative to it when it starts from new line (see Indent javadoc).
|
// relative to it when it starts from new line (see Indent javadoc).
|
||||||
|
|
||||||
val operationBlock = nodeSubBlocks[operationBlockIndex]
|
val operationBlock = nodeSubBlocks[operationBlockIndex]
|
||||||
|
val indent = if (settings.kotlinSettings.CONTINUATION_INDENT_FOR_CHAINED_CALLS)
|
||||||
|
Indent.getContinuationWithoutFirstIndent()
|
||||||
|
else
|
||||||
|
Indent.getNormalIndent()
|
||||||
val operationSyntheticBlock = SyntheticKotlinBlock(
|
val operationSyntheticBlock = SyntheticKotlinBlock(
|
||||||
(operationBlock as ASTBlock).node,
|
(operationBlock as ASTBlock).node,
|
||||||
nodeSubBlocks.subList(operationBlockIndex, nodeSubBlocks.size),
|
nodeSubBlocks.subList(operationBlockIndex, nodeSubBlocks.size),
|
||||||
null, operationBlock.getIndent(), null, spacingBuilder) { createSyntheticSpacingNodeBlock(it) }
|
null, indent, null, spacingBuilder) { createSyntheticSpacingNodeBlock(it) }
|
||||||
|
|
||||||
nodeSubBlocks = ArrayList<Block>(nodeSubBlocks.subList(0, operationBlockIndex))
|
nodeSubBlocks = ArrayList<Block>(nodeSubBlocks.subList(0, operationBlockIndex))
|
||||||
nodeSubBlocks.add(operationSyntheticBlock)
|
nodeSubBlocks.add(operationSyntheticBlock)
|
||||||
@@ -382,7 +386,14 @@ private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
|||||||
|
|
||||||
strategy("Chained calls")
|
strategy("Chained calls")
|
||||||
.within(KtNodeTypes.DOT_QUALIFIED_EXPRESSION, KtNodeTypes.SAFE_ACCESS_EXPRESSION)
|
.within(KtNodeTypes.DOT_QUALIFIED_EXPRESSION, KtNodeTypes.SAFE_ACCESS_EXPRESSION)
|
||||||
.set(Indent.getContinuationWithoutFirstIndent(false)),
|
.notForType(KtTokens.DOT, KtTokens.SAFE_ACCESS)
|
||||||
|
.forElement { it.treeParent.firstChildNode != it }
|
||||||
|
.set { settings ->
|
||||||
|
if (settings.kotlinSettings.CONTINUATION_INDENT_FOR_CHAINED_CALLS)
|
||||||
|
Indent.getContinuationWithoutFirstIndent()
|
||||||
|
else
|
||||||
|
Indent.getNormalIndent()
|
||||||
|
},
|
||||||
|
|
||||||
strategy("Colon of delegation list")
|
strategy("Colon of delegation list")
|
||||||
.within(KtNodeTypes.CLASS, KtNodeTypes.OBJECT_DECLARATION)
|
.within(KtNodeTypes.CLASS, KtNodeTypes.OBJECT_DECLARATION)
|
||||||
|
|||||||
@@ -26,11 +26,13 @@ import javax.swing.JCheckBox
|
|||||||
class KotlinIndentOptionsEditor : SmartIndentOptionsEditor() {
|
class KotlinIndentOptionsEditor : SmartIndentOptionsEditor() {
|
||||||
private val useContinuationIndentInParameterList = JCheckBox("Use continuation indent in parameter lists")
|
private val useContinuationIndentInParameterList = JCheckBox("Use continuation indent in parameter lists")
|
||||||
private val useContinuationIndentForExpressionBodies = JCheckBox("Use continuation indent for expression bodies")
|
private val useContinuationIndentForExpressionBodies = JCheckBox("Use continuation indent for expression bodies")
|
||||||
|
private val useContinuationIndentForChainedCalls = JCheckBox("Use continuation indent for chained calls")
|
||||||
|
|
||||||
override fun addComponents() {
|
override fun addComponents() {
|
||||||
super.addComponents()
|
super.addComponents()
|
||||||
add(useContinuationIndentInParameterList)
|
add(useContinuationIndentInParameterList)
|
||||||
add(useContinuationIndentForExpressionBodies)
|
add(useContinuationIndentForExpressionBodies)
|
||||||
|
add(useContinuationIndentForChainedCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isModified(settings: CodeStyleSettings, options: CommonCodeStyleSettings.IndentOptions): Boolean {
|
override fun isModified(settings: CodeStyleSettings, options: CommonCodeStyleSettings.IndentOptions): Boolean {
|
||||||
@@ -40,6 +42,8 @@ class KotlinIndentOptionsEditor : SmartIndentOptionsEditor() {
|
|||||||
kotlinSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS)
|
kotlinSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS)
|
||||||
isModified = isModified || IndentOptionsEditor.isFieldModified(useContinuationIndentForExpressionBodies,
|
isModified = isModified || IndentOptionsEditor.isFieldModified(useContinuationIndentForExpressionBodies,
|
||||||
kotlinSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES)
|
kotlinSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES)
|
||||||
|
isModified = isModified || IndentOptionsEditor.isFieldModified(useContinuationIndentForChainedCalls,
|
||||||
|
kotlinSettings.CONTINUATION_INDENT_FOR_CHAINED_CALLS)
|
||||||
return isModified
|
return isModified
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +52,7 @@ class KotlinIndentOptionsEditor : SmartIndentOptionsEditor() {
|
|||||||
val kotlinSettings = settings.getCustomSettings(KotlinCodeStyleSettings::class.java)
|
val kotlinSettings = settings.getCustomSettings(KotlinCodeStyleSettings::class.java)
|
||||||
kotlinSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS = useContinuationIndentInParameterList.isSelected
|
kotlinSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS = useContinuationIndentInParameterList.isSelected
|
||||||
kotlinSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES = useContinuationIndentForExpressionBodies.isSelected
|
kotlinSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES = useContinuationIndentForExpressionBodies.isSelected
|
||||||
|
kotlinSettings.CONTINUATION_INDENT_FOR_CHAINED_CALLS = useContinuationIndentForChainedCalls.isSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun reset(settings: CodeStyleSettings, options: CommonCodeStyleSettings.IndentOptions) {
|
override fun reset(settings: CodeStyleSettings, options: CommonCodeStyleSettings.IndentOptions) {
|
||||||
@@ -55,11 +60,13 @@ class KotlinIndentOptionsEditor : SmartIndentOptionsEditor() {
|
|||||||
val kotlinSettings = settings.getCustomSettings(KotlinCodeStyleSettings::class.java)
|
val kotlinSettings = settings.getCustomSettings(KotlinCodeStyleSettings::class.java)
|
||||||
useContinuationIndentInParameterList.isSelected = kotlinSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS
|
useContinuationIndentInParameterList.isSelected = kotlinSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS
|
||||||
useContinuationIndentForExpressionBodies.isSelected = kotlinSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
|
useContinuationIndentForExpressionBodies.isSelected = kotlinSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
|
||||||
|
useContinuationIndentForChainedCalls.isSelected = kotlinSettings.CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setEnabled(enabled: Boolean) {
|
override fun setEnabled(enabled: Boolean) {
|
||||||
super.setEnabled(enabled)
|
super.setEnabled(enabled)
|
||||||
useContinuationIndentInParameterList.isEnabled = enabled
|
useContinuationIndentInParameterList.isEnabled = enabled
|
||||||
useContinuationIndentForExpressionBodies.isEnabled = enabled
|
useContinuationIndentForExpressionBodies.isEnabled = enabled
|
||||||
|
useContinuationIndentForChainedCalls.isEnabled = enabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
@@ -125,6 +125,8 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide
|
|||||||
foo: String,
|
foo: String,
|
||||||
bar: String
|
bar: String
|
||||||
) {
|
) {
|
||||||
|
foo
|
||||||
|
.length
|
||||||
}
|
}
|
||||||
|
|
||||||
fun expressionBodyMethod() =
|
fun expressionBodyMethod() =
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
class Some {
|
||||||
|
fun some(): Some? = this
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun bar(): String? =
|
||||||
|
Some()
|
||||||
|
?.some()
|
||||||
|
?.some()
|
||||||
|
?.some()!!
|
||||||
|
.toString()
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
@@ -9,3 +9,4 @@ public fun bar(): String? =
|
|||||||
?.some()!!
|
?.some()!!
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ Some()
|
|||||||
?.some()!!
|
?.some()!!
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
val x = "abc"
|
||||||
|
.length
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
val x = "abc"
|
||||||
|
.length
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
val x = "abc"
|
||||||
|
.length
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val abc = ArrayList<Int>()
|
||||||
|
.map {
|
||||||
|
it * 2
|
||||||
|
}
|
||||||
|
.filter {
|
||||||
|
it > 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test1() {
|
||||||
|
val abc = ArrayList<Int>()
|
||||||
|
.map({
|
||||||
|
it * 2
|
||||||
|
})
|
||||||
|
.filter({
|
||||||
|
it > 4
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
val abc = ArrayList<Int>()
|
||||||
|
.map {
|
||||||
|
it * 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test3() {
|
||||||
|
val abc = ArrayList<Int>().map {
|
||||||
|
it * 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testWithComments() {
|
||||||
|
val abc = ArrayList<Int>()
|
||||||
|
// .map {
|
||||||
|
// it * 2
|
||||||
|
// }
|
||||||
|
.filter {
|
||||||
|
it > 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
@@ -43,3 +43,4 @@ fun testWithComments() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
|
|||||||
@@ -42,3 +42,5 @@ fun testWithComments() {
|
|||||||
it > 4
|
it > 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SET_TRUE: CONTINUATION_INDENT_FOR_CHAINED_CALLS
|
||||||
|
|||||||
@@ -176,6 +176,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ContinuationIndentForChainedCalls.after.kt")
|
||||||
|
public void testContinuationIndentForChainedCalls() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ContinuationIndentForChainedCalls.after.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ContinuationIndentInParameterLists.after.kt")
|
@TestMetadata("ContinuationIndentInParameterLists.after.kt")
|
||||||
public void testContinuationIndentInParameterLists() throws Exception {
|
public void testContinuationIndentInParameterLists() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ContinuationIndentInParameterLists.after.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ContinuationIndentInParameterLists.after.kt");
|
||||||
@@ -1064,6 +1070,18 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
doTestInverted(fileName);
|
doTestInverted(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ConsecutiveSafeCallsIndent.after.inv.kt")
|
||||||
|
public void testConsecutiveSafeCallsIndent() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ConsecutiveSafeCallsIndent.after.inv.kt");
|
||||||
|
doTestInverted(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ContinuationIndentForChainedCalls.after.inv.kt")
|
||||||
|
public void testContinuationIndentForChainedCalls() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ContinuationIndentForChainedCalls.after.inv.kt");
|
||||||
|
doTestInverted(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ContinuationIndentForExpressionBodies.after.inv.kt")
|
@TestMetadata("ContinuationIndentForExpressionBodies.after.inv.kt")
|
||||||
public void testContinuationIndentForExpressionBodies() throws Exception {
|
public void testContinuationIndentForExpressionBodies() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ContinuationIndentForExpressionBodies.after.inv.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ContinuationIndentForExpressionBodies.after.inv.kt");
|
||||||
@@ -1130,6 +1148,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
doTestInverted(fileName);
|
doTestInverted(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FunctionLiteralsInChainCalls.after.inv.kt")
|
||||||
|
public void testFunctionLiteralsInChainCalls() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/FunctionLiteralsInChainCalls.after.inv.kt");
|
||||||
|
doTestInverted(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("FunctionalType.after.inv.kt")
|
@TestMetadata("FunctionalType.after.inv.kt")
|
||||||
public void testFunctionalType() throws Exception {
|
public void testFunctionalType() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/FunctionalType.after.inv.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/FunctionalType.after.inv.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user