Formatter: cleanup code
This commit is contained in:
@@ -126,7 +126,9 @@ abstract class KotlinCommonBlock(
|
|||||||
var currentNode: ASTNode? = this
|
var currentNode: ASTNode? = this
|
||||||
while (currentNode != null) {
|
while (currentNode != null) {
|
||||||
if (currentNode.elementType in QUALIFIED_EXPRESSIONS) return true
|
if (currentNode.elementType in QUALIFIED_EXPRESSIONS) return true
|
||||||
if (currentNode.elementType != PARENTHESIZED && currentNode.psi?.safeAs<KtPostfixExpression>()?.operationToken != EXCLEXCL) return false
|
if (currentNode.elementType != PARENTHESIZED && currentNode.psi?.safeAs<KtPostfixExpression>()
|
||||||
|
?.operationToken != EXCLEXCL
|
||||||
|
) return false
|
||||||
currentNode = currentNode.treeParent
|
currentNode = currentNode.treeParent
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +151,7 @@ abstract class KotlinCommonBlock(
|
|||||||
|
|
||||||
private fun ASTBlock.processBlock(indent: Indent, wrap: Wrap?): ASTBlock {
|
private fun ASTBlock.processBlock(indent: Indent, wrap: Wrap?): ASTBlock {
|
||||||
val currentNode = requireNode()
|
val currentNode = requireNode()
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val subBlocks = subBlocks as List<ASTBlock>
|
val subBlocks = subBlocks as List<ASTBlock>
|
||||||
val elementType = currentNode.elementType
|
val elementType = currentNode.elementType
|
||||||
@@ -681,7 +684,9 @@ abstract class KotlinCommonBlock(
|
|||||||
}
|
}
|
||||||
if (nodePsi.operationToken == ELVIS && nodePsi.getStrictParentOfType<KtStringTemplateExpression>() == null) {
|
if (nodePsi.operationToken == ELVIS && nodePsi.getStrictParentOfType<KtStringTemplateExpression>() == null) {
|
||||||
return { childElement ->
|
return { childElement ->
|
||||||
if (childElement.elementType == OPERATION_REFERENCE && (childElement.psi as? KtOperationReferenceExpression)?.operationSignTokenType == ELVIS) {
|
if (childElement.elementType == OPERATION_REFERENCE && (childElement.psi as? KtOperationReferenceExpression)
|
||||||
|
?.operationSignTokenType == ELVIS
|
||||||
|
) {
|
||||||
Wrap.createWrap(settings.kotlinCustomSettings.WRAP_ELVIS_EXPRESSIONS, true)
|
Wrap.createWrap(settings.kotlinCustomSettings.WRAP_ELVIS_EXPRESSIONS, true)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -149,7 +149,8 @@ class KotlinSpacingBuilder(val commonCodeStyleSettings: CommonCodeStyleSettings,
|
|||||||
// TODO: it's a severe hack but I don't know how to implement it in other way
|
// TODO: it's a severe hack but I don't know how to implement it in other way
|
||||||
if (child1.requireNode().elementType == KtTokens.EOL_COMMENT && spacing.toString().contains("minLineFeeds=0")) {
|
if (child1.requireNode().elementType == KtTokens.EOL_COMMENT && spacing.toString().contains("minLineFeeds=0")) {
|
||||||
val isBeforeBlock =
|
val isBeforeBlock =
|
||||||
child2.requireNode().elementType == KtNodeTypes.BLOCK || child2.requireNode().firstChildNode?.elementType == KtNodeTypes.BLOCK
|
child2.requireNode().elementType == KtNodeTypes.BLOCK || child2.requireNode().firstChildNode
|
||||||
|
?.elementType == KtNodeTypes.BLOCK
|
||||||
val keepBlankLines = if (isBeforeBlock) 0 else commonCodeStyleSettings.KEEP_BLANK_LINES_IN_CODE
|
val keepBlankLines = if (isBeforeBlock) 0 else commonCodeStyleSettings.KEEP_BLANK_LINES_IN_CODE
|
||||||
return createSpacing(0, minLineFeeds = 1, keepLineBreaks = true, keepBlankLines = keepBlankLines)
|
return createSpacing(0, minLineFeeds = 1, keepLineBreaks = true, keepBlankLines = keepBlankLines)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -612,7 +612,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
|||||||
val prevSibling = rightParenthesis?.prevSibling
|
val prevSibling = rightParenthesis?.prevSibling
|
||||||
val spaces = if (kotlinCustomSettings.SPACE_BEFORE_EXTEND_COLON) 1 else 0
|
val spaces = if (kotlinCustomSettings.SPACE_BEFORE_EXTEND_COLON) 1 else 0
|
||||||
// TODO This should use DependentSpacingRule, but it doesn't set keepLineBreaks to false if max LFs is 0
|
// TODO This should use DependentSpacingRule, but it doesn't set keepLineBreaks to false if max LFs is 0
|
||||||
if ((prevSibling as? PsiWhiteSpace)?.textContains('\n') == true || kotlinCommonSettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE) {
|
if ((prevSibling as? PsiWhiteSpace)?.textContains('\n') == true || kotlinCommonSettings
|
||||||
|
.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE
|
||||||
|
) {
|
||||||
createSpacing(spaces, keepLineBreaks = false)
|
createSpacing(spaces, keepLineBreaks = false)
|
||||||
} else {
|
} else {
|
||||||
createSpacing(spaces)
|
createSpacing(spaces)
|
||||||
|
|||||||
Reference in New Issue
Block a user