Ident elvis with normal ident in Kotlin code style (KT-25008)
#KT-25008 Fixed
This commit is contained in:
+1
@@ -53,6 +53,7 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
|
|||||||
public boolean CONTINUATION_INDENT_FOR_CHAINED_CALLS = true;
|
public boolean CONTINUATION_INDENT_FOR_CHAINED_CALLS = true;
|
||||||
public boolean CONTINUATION_INDENT_IN_SUPERTYPE_LISTS = true;
|
public boolean CONTINUATION_INDENT_IN_SUPERTYPE_LISTS = true;
|
||||||
public boolean CONTINUATION_INDENT_IN_IF_CONDITIONS = true;
|
public boolean CONTINUATION_INDENT_IN_IF_CONDITIONS = true;
|
||||||
|
public boolean CONTINUATION_INDENT_IN_ELVIS = true;
|
||||||
public int BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES = 0;
|
public int BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES = 0;
|
||||||
public int WRAP_EXPRESSION_BODY_FUNCTIONS = 0;
|
public int WRAP_EXPRESSION_BODY_FUNCTIONS = 0;
|
||||||
public int WRAP_ELVIS_EXPRESSIONS = 1;
|
public int WRAP_ELVIS_EXPRESSIONS = 1;
|
||||||
|
|||||||
@@ -193,9 +193,15 @@ abstract class KotlinCommonBlock(
|
|||||||
private fun splitSubBlocksOnElvis(nodeSubBlocks: List<ASTBlock>): List<ASTBlock> {
|
private fun splitSubBlocksOnElvis(nodeSubBlocks: List<ASTBlock>): List<ASTBlock> {
|
||||||
val elvisIndex = nodeSubBlocks.indexOfBlockWithType(ELVIS_SET)
|
val elvisIndex = nodeSubBlocks.indexOfBlockWithType(ELVIS_SET)
|
||||||
if (elvisIndex >= 0) {
|
if (elvisIndex >= 0) {
|
||||||
|
val indent = if (settings.kotlinCustomSettings.CONTINUATION_INDENT_IN_ELVIS) {
|
||||||
|
Indent.getContinuationIndent()
|
||||||
|
} else {
|
||||||
|
Indent.getNormalIndent()
|
||||||
|
}
|
||||||
|
|
||||||
return nodeSubBlocks.splitAtIndex(
|
return nodeSubBlocks.splitAtIndex(
|
||||||
elvisIndex,
|
elvisIndex,
|
||||||
Indent.getContinuationIndent(),
|
indent,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class KotlinStyleGuideCodeStyle : PredefinedCodeStyle("Kotlin style guide", Kotl
|
|||||||
CONTINUATION_INDENT_FOR_CHAINED_CALLS = false
|
CONTINUATION_INDENT_FOR_CHAINED_CALLS = false
|
||||||
CONTINUATION_INDENT_IN_SUPERTYPE_LISTS = false
|
CONTINUATION_INDENT_IN_SUPERTYPE_LISTS = false
|
||||||
CONTINUATION_INDENT_IN_IF_CONDITIONS = false
|
CONTINUATION_INDENT_IN_IF_CONDITIONS = false
|
||||||
|
CONTINUATION_INDENT_IN_ELVIS = false
|
||||||
WRAP_EXPRESSION_BODY_FUNCTIONS = CodeStyleSettings.WRAP_AS_NEEDED
|
WRAP_EXPRESSION_BODY_FUNCTIONS = CodeStyleSettings.WRAP_AS_NEEDED
|
||||||
IF_RPAREN_ON_NEW_LINE = true
|
IF_RPAREN_ON_NEW_LINE = true
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -339,6 +339,11 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide
|
|||||||
CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON
|
CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
showCustomOption(
|
||||||
|
KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ELVIS,
|
||||||
|
title = "Use continuation indent",
|
||||||
|
groupName = "Elvis expressions"
|
||||||
|
)
|
||||||
@Suppress("InvalidBundleOrProperty")
|
@Suppress("InvalidBundleOrProperty")
|
||||||
showCustomOption(
|
showCustomOption(
|
||||||
KotlinCodeStyleSettings::IF_RPAREN_ON_NEW_LINE,
|
KotlinCodeStyleSettings::IF_RPAREN_ON_NEW_LINE,
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun test(some: Any?, error: Int) {
|
||||||
|
val test = some
|
||||||
|
?: error
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET_FALSE: CONTINUATION_INDENT_IN_ELVIS
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun test(some: Any?, error: Int) {
|
||||||
|
val test = some
|
||||||
|
?: error
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET_FALSE: CONTINUATION_INDENT_IN_ELVIS
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun test(some: Any?, error: Int) {
|
||||||
|
val test = some
|
||||||
|
?: error
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET_FALSE: CONTINUATION_INDENT_IN_ELVIS
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fun foo() {
|
||||||
|
val topLevelDeclaration =
|
||||||
|
DescriptorUtils.getParentOfType(referencedDescriptor, PropertyDescriptor::class.java, false) as DeclarationDescriptor?
|
||||||
|
?: DescriptorUtils.getParentOfType(
|
||||||
|
referencedDescriptor,
|
||||||
|
TypeAliasConstructorDescriptor::class.java,
|
||||||
|
false
|
||||||
|
)?.typeAliasDescriptor
|
||||||
|
?: DescriptorUtils.getParentOfType(referencedDescriptor, FunctionDescriptor::class.java, false)
|
||||||
|
?: return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SET_FALSE: CONTINUATION_INDENT_IN_ARGUMENT_LISTS
|
||||||
|
// SET_FALSE: CONTINUATION_INDENT_FOR_EXPRESSION_BODIES
|
||||||
@@ -216,6 +216,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
runTest("idea/testData/formatter/Elvis.after.kt");
|
runTest("idea/testData/formatter/Elvis.after.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ElvisContinuationIndentOptions.after.kt")
|
||||||
|
public void testElvisContinuationIndentOptions() throws Exception {
|
||||||
|
runTest("idea/testData/formatter/ElvisContinuationIndentOptions.after.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ElvisIndent.after.kt")
|
@TestMetadata("ElvisIndent.after.kt")
|
||||||
public void testElvisIndent() throws Exception {
|
public void testElvisIndent() throws Exception {
|
||||||
runTest("idea/testData/formatter/ElvisIndent.after.kt");
|
runTest("idea/testData/formatter/ElvisIndent.after.kt");
|
||||||
@@ -1136,6 +1141,16 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
runTest("idea/testData/formatter/Elvis.after.inv.kt");
|
runTest("idea/testData/formatter/Elvis.after.inv.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ElvisContinuationIndentOptions.after.inv.kt")
|
||||||
|
public void testElvisContinuationIndentOptions() throws Exception {
|
||||||
|
runTest("idea/testData/formatter/ElvisContinuationIndentOptions.after.inv.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ElvisIndent.after.inv.kt")
|
||||||
|
public void testElvisIndent() throws Exception {
|
||||||
|
runTest("idea/testData/formatter/ElvisIndent.after.inv.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("EmptyBlocks.after.inv.kt")
|
@TestMetadata("EmptyBlocks.after.inv.kt")
|
||||||
public void testEmptyBlocks() throws Exception {
|
public void testEmptyBlocks() throws Exception {
|
||||||
runTest("idea/testData/formatter/EmptyBlocks.after.inv.kt");
|
runTest("idea/testData/formatter/EmptyBlocks.after.inv.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user