Bad indentation after annotation in incomplete declaration (KT-22322)

Same behavior is for any modifier in incomplete declaration.

 #KT-22322 Fixed
This commit is contained in:
Nikolay Krasko
2018-09-14 14:52:46 +03:00
parent 94531f992d
commit 782aa94513
7 changed files with 53 additions and 1 deletions
@@ -94,6 +94,16 @@ abstract class KotlinCommonBlock(
fun isLeaf(): Boolean = node.firstChildNode == null
fun isIncomplete(): Boolean {
if (isIncompleteInSuper()) {
return true
}
// An incomplete declaration is the reason when modifier list can become a class body child, otherwise
// it's going to be a declaration child.
return node.elementType == MODIFIER_LIST && node.treeParent?.elementType == CLASS_BODY
}
fun buildChildren(): List<Block> {
if (mySubBlocks != null) {
return mySubBlocks!!
@@ -451,6 +461,11 @@ abstract class KotlinCommonBlock(
return blockList.asSequence()
}
if (this.node.elementType == CLASS_BODY && node.elementType == MODIFIER_LIST) {
// Some unfinished declaration
println()
}
return sequenceOf(buildSubBlock(node, childrenAlignmentStrategy, wrappingStrategy))
}
@@ -50,7 +50,7 @@ class KotlinBlock(
override fun getAlignment(): Alignment? = alignment
override fun isIncompleteInSuper(): Boolean = this@KotlinBlock.isIncomplete
override fun isIncompleteInSuper(): Boolean = super@KotlinBlock.isIncomplete()
override fun getSuperChildAttributes(newChildIndex: Int): ChildAttributes = super@KotlinBlock.getChildAttributes(newChildIndex)
@@ -96,6 +96,8 @@ class KotlinBlock(
override fun isLeaf(): Boolean = kotlinDelegationBlock.isLeaf()
override fun getTextRange() = kotlinDelegationBlock.getTextRange()
override fun isIncomplete(): Boolean = kotlinDelegationBlock.isIncomplete()
}
object KotlinSpacingBuilderUtilImpl : KotlinSpacingBuilderUtil {
@@ -0,0 +1,6 @@
class Foo {
companion object {
@JvmStatic
<caret>
}
}
@@ -0,0 +1,5 @@
class Foo {
companion object {
@JvmStatic<caret>
}
}
@@ -0,0 +1,4 @@
object A {
private
<caret>
}
@@ -0,0 +1,3 @@
object A {
private<caret>
}
@@ -61,6 +61,11 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
runTest("idea/testData/indentationOnNewline/Annotation.after.kt");
}
@TestMetadata("AnnotationInDeclaration.after.kt")
public void testAnnotationInDeclaration() throws Exception {
runTest("idea/testData/indentationOnNewline/AnnotationInDeclaration.after.kt");
}
@TestMetadata("ArgumentListNormalIndent.after.kt")
public void testArgumentListNormalIndent() throws Exception {
runTest("idea/testData/indentationOnNewline/ArgumentListNormalIndent.after.kt");
@@ -231,6 +236,18 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
runTest("idea/testData/indentationOnNewline/KT20783.after.kt");
}
@TestMetadata("LambdaInCallWithAllightMultilineParameters.after.kt")
public void testLambdaInCallWithAllightMultilineParameters() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/LambdaInCallWithAllightMultilineParameters.after.kt");
doNewlineTest(fileName);
}
@TestMetadata("ModifierListInUnfinishedDeclaration.after.kt")
public void testModifierListInUnfinishedDeclaration() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/ModifierListInUnfinishedDeclaration.after.kt");
doNewlineTest(fileName);
}
@TestMetadata("MultideclarationAfterEq.after.kt")
public void testMultideclarationAfterEq() throws Exception {
runTest("idea/testData/indentationOnNewline/MultideclarationAfterEq.after.kt");