Trailing comma: cleanup code after review
#KT-34744
This commit is contained in:
@@ -588,7 +588,8 @@ abstract class KotlinCommonBlock(
|
||||
when {
|
||||
elementType === VALUE_ARGUMENT_LIST -> {
|
||||
val wrapSetting = commonSettings.CALL_PARAMETERS_WRAP
|
||||
if (!node.trailingCommaIsAllowed && (wrapSetting == CommonCodeStyleSettings.WRAP_AS_NEEDED || wrapSetting == CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM) &&
|
||||
if (!node.trailingCommaIsAllowed &&
|
||||
(wrapSetting == CommonCodeStyleSettings.WRAP_AS_NEEDED || wrapSetting == CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM) &&
|
||||
!needWrapArgumentList(nodePsi)
|
||||
) {
|
||||
return ::noWrapping
|
||||
@@ -752,12 +753,10 @@ abstract class KotlinCommonBlock(
|
||||
fun(childElement: ASTNode): Wrap? = trailingCommaWrappingStrategyWithMultiLineCheck(leftAnchor, rightAnchor)(childElement)
|
||||
|
||||
private val ASTNode.trailingCommaIsAllowed: Boolean
|
||||
get() = if (settings.kotlinCustomSettings.ALLOW_TRAILING_COMMA ||
|
||||
lastChildNode?.let { getSiblingWithoutWhitespaceAndComments(it) }?.elementType === COMMA
|
||||
)
|
||||
psi?.let(PsiElement::isMultiline) == true
|
||||
else
|
||||
false
|
||||
get() = (settings.kotlinCustomSettings.ALLOW_TRAILING_COMMA ||
|
||||
lastChildNode?.let { getSiblingWithoutWhitespaceAndComments(it) }?.elementType === COMMA) &&
|
||||
psi?.let(PsiElement::isMultiline) == true
|
||||
|
||||
|
||||
private fun ASTNode.notDelimiterSiblingNodeInSequence(
|
||||
forward: Boolean,
|
||||
|
||||
@@ -76,11 +76,12 @@ fun <T : PsiElement> T.needTrailingComma(
|
||||
additionalCheck: () -> Boolean = { true },
|
||||
globalStartOffset: T.() -> Int? = PsiElement::startOffset,
|
||||
globalEndOffset: T.() -> Int? = PsiElement::endOffset
|
||||
) = (trailingComma() != null || settings.kotlinCustomSettings.ALLOW_TRAILING_COMMA) && additionalCheck() && run(fun(): Boolean {
|
||||
): Boolean {
|
||||
if (trailingComma() == null && !settings.kotlinCustomSettings.ALLOW_TRAILING_COMMA || !additionalCheck()) return false
|
||||
val startOffset = globalStartOffset() ?: return false
|
||||
val endOffset = globalEndOffset() ?: return false
|
||||
return containsLineBreakInThis(startOffset, endOffset)
|
||||
})
|
||||
}
|
||||
|
||||
fun PsiElement.containsLineBreakInThis(globalStartOffset: Int, globalEndOffset: Int): Boolean {
|
||||
val textRange = TextRange.create(globalStartOffset, globalEndOffset).shiftLeft(startOffset)
|
||||
|
||||
Reference in New Issue
Block a user