Refactoring: extract 'continuationIf' method
This commit is contained in:
@@ -525,6 +525,21 @@ fun needWrapArgumentList(psi: PsiElement): Boolean {
|
|||||||
return args?.singleOrNull()?.getArgumentExpression() !is KtObjectLiteralExpression
|
return args?.singleOrNull()?.getArgumentExpression() !is KtObjectLiteralExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun NodeIndentStrategy.PositionStrategy.continuationIf(
|
||||||
|
option: (KotlinCodeStyleSettings) -> Boolean,
|
||||||
|
indentFirst: Boolean = false
|
||||||
|
): NodeIndentStrategy {
|
||||||
|
return set { settings ->
|
||||||
|
if (option(settings.kotlinCustomSettings)) {
|
||||||
|
if (indentFirst)
|
||||||
|
Indent.getContinuationIndent()
|
||||||
|
else
|
||||||
|
Indent.getContinuationWithoutFirstIndent()
|
||||||
|
} else
|
||||||
|
Indent.getNormalIndent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
||||||
strategy("No indent for braces in blocks")
|
strategy("No indent for braces in blocks")
|
||||||
.within(KtNodeTypes.BLOCK, KtNodeTypes.CLASS_BODY, KtNodeTypes.FUNCTION_LITERAL)
|
.within(KtNodeTypes.BLOCK, KtNodeTypes.CLASS_BODY, KtNodeTypes.FUNCTION_LITERAL)
|
||||||
@@ -557,12 +572,7 @@ private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
|||||||
.forElement {
|
.forElement {
|
||||||
it.psi is KtExpression && it.psi !is KtBlockExpression
|
it.psi is KtExpression && it.psi !is KtBlockExpression
|
||||||
}
|
}
|
||||||
.set { settings ->
|
.continuationIf(KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_EXPRESSION_BODIES, indentFirst = true),
|
||||||
if (settings.kotlinCustomSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES)
|
|
||||||
Indent.getContinuationIndent()
|
|
||||||
else
|
|
||||||
Indent.getNormalIndent()
|
|
||||||
},
|
|
||||||
|
|
||||||
strategy("Property accessor expression body")
|
strategy("Property accessor expression body")
|
||||||
.within(KtNodeTypes.PROPERTY_ACCESSOR)
|
.within(KtNodeTypes.PROPERTY_ACCESSOR)
|
||||||
@@ -576,12 +586,7 @@ private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
|||||||
.forElement {
|
.forElement {
|
||||||
it.psi is KtExpression
|
it.psi is KtExpression
|
||||||
}
|
}
|
||||||
.set { settings ->
|
.continuationIf(KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_EXPRESSION_BODIES),
|
||||||
if (settings.kotlinCustomSettings.CONTINUATION_INDENT_FOR_EXPRESSION_BODIES)
|
|
||||||
Indent.getContinuationWithoutFirstIndent()
|
|
||||||
else
|
|
||||||
Indent.getNormalIndent()
|
|
||||||
},
|
|
||||||
|
|
||||||
strategy("Indent for parts")
|
strategy("Indent for parts")
|
||||||
.within(KtNodeTypes.PROPERTY, KtNodeTypes.FUN, KtNodeTypes.DESTRUCTURING_DECLARATION, KtNodeTypes.SECONDARY_CONSTRUCTOR)
|
.within(KtNodeTypes.PROPERTY, KtNodeTypes.FUN, KtNodeTypes.DESTRUCTURING_DECLARATION, KtNodeTypes.SECONDARY_CONSTRUCTOR)
|
||||||
@@ -592,12 +597,7 @@ private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
|||||||
.within(QUALIFIED_EXPRESSIONS)
|
.within(QUALIFIED_EXPRESSIONS)
|
||||||
.notForType(KtTokens.DOT, KtTokens.SAFE_ACCESS)
|
.notForType(KtTokens.DOT, KtTokens.SAFE_ACCESS)
|
||||||
.forElement { it.treeParent.firstChildNode != it }
|
.forElement { it.treeParent.firstChildNode != it }
|
||||||
.set { settings ->
|
.continuationIf(KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_CHAINED_CALLS),
|
||||||
if (settings.kotlinCustomSettings.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)
|
||||||
@@ -606,12 +606,7 @@ private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
|||||||
|
|
||||||
strategy("Delegation list")
|
strategy("Delegation list")
|
||||||
.within(KtNodeTypes.SUPER_TYPE_LIST, KtNodeTypes.INITIALIZER_LIST)
|
.within(KtNodeTypes.SUPER_TYPE_LIST, KtNodeTypes.INITIALIZER_LIST)
|
||||||
.set { settings ->
|
.continuationIf(KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_SUPERTYPE_LISTS, indentFirst = true),
|
||||||
if (settings.kotlinCustomSettings.CONTINUATION_INDENT_IN_SUPERTYPE_LISTS)
|
|
||||||
Indent.getContinuationIndent(false)
|
|
||||||
else
|
|
||||||
Indent.getNormalIndent()
|
|
||||||
},
|
|
||||||
|
|
||||||
strategy("Indices")
|
strategy("Indices")
|
||||||
.within(KtNodeTypes.INDICES)
|
.within(KtNodeTypes.INDICES)
|
||||||
@@ -655,12 +650,7 @@ private val INDENT_RULES = arrayOf<NodeIndentStrategy>(
|
|||||||
strategy("Parameter list")
|
strategy("Parameter list")
|
||||||
.within(KtNodeTypes.VALUE_PARAMETER_LIST)
|
.within(KtNodeTypes.VALUE_PARAMETER_LIST)
|
||||||
.forElement { it.elementType == KtNodeTypes.VALUE_PARAMETER && it.psi.prevSibling != null }
|
.forElement { it.elementType == KtNodeTypes.VALUE_PARAMETER && it.psi.prevSibling != null }
|
||||||
.set { settings ->
|
.continuationIf(KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_PARAMETER_LISTS, indentFirst = true),
|
||||||
if (settings.kotlinCustomSettings.CONTINUATION_INDENT_IN_PARAMETER_LISTS)
|
|
||||||
Indent.getContinuationIndent()
|
|
||||||
else
|
|
||||||
Indent.getNormalIndent()
|
|
||||||
},
|
|
||||||
|
|
||||||
strategy("Where clause")
|
strategy("Where clause")
|
||||||
.within(KtNodeTypes.CLASS, KtNodeTypes.FUN, KtNodeTypes.PROPERTY)
|
.within(KtNodeTypes.CLASS, KtNodeTypes.FUN, KtNodeTypes.PROPERTY)
|
||||||
|
|||||||
Reference in New Issue
Block a user