Formatter: Spacing before after semicolon in enum classes
This commit is contained in:
committed by
Alexey Sedunov
parent
98b3919824
commit
40f2a983cc
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.idea.core.formatter.JetCodeStyleSettings
|
||||
import org.jetbrains.kotlin.idea.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
|
||||
val MODIFIERS_LIST_ENTRIES = TokenSet.orSet(TokenSet.create(ANNOTATION_ENTRY, ANNOTATION), MODIFIER_KEYWORDS)
|
||||
|
||||
@@ -62,6 +63,13 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
inPosition(left = ENUM_ENTRY, right = ENUM_ENTRY).emptyLinesIfLineBreakInLeft(
|
||||
emptyLines = 0, numSpacesOtherwise = 1, numberOfLineFeedsOtherwise = 0)
|
||||
|
||||
inPosition(parent = CLASS_BODY, left = SEMICOLON).customRule { parent, left, right ->
|
||||
val klass = parent.node.treeParent.psi as? KtClass ?: return@customRule null
|
||||
if (klass.isEnum() && right.node.elementType in DECLARATIONS) {
|
||||
Spacing.createSpacing(0, 0, 2, settings.KEEP_LINE_BREAKS, settings.KEEP_BLANK_LINES_IN_DECLARATIONS)
|
||||
} else null
|
||||
}
|
||||
|
||||
val parameterWithDocCommentRule = {
|
||||
parent: ASTBlock, left: ASTBlock, right: ASTBlock ->
|
||||
if (right.getNode().getFirstChildNode().getElementType() == KtTokens.DOC_COMMENT) {
|
||||
@@ -99,6 +107,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
// ENUM_ENTRY - ENUM_ENTRY is exception
|
||||
between(ENUM_ENTRY, DECLARATIONS).blankLines(1)
|
||||
|
||||
between(ENUM_ENTRY, SEMICOLON).spaces(0)
|
||||
|
||||
beforeInside(FUN, TokenSet.create(BODY, CLASS_BODY)).lineBreakInCode()
|
||||
beforeInside(CLASS, TokenSet.create(BODY, CLASS_BODY)).lineBreakInCode()
|
||||
beforeInside(OBJECT_DECLARATION, TokenSet.create(BODY, CLASS_BODY)).lineBreakInCode()
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
enum class E1 {
|
||||
A,
|
||||
B;
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
enum class E2 {
|
||||
A,
|
||||
B;
|
||||
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
enum class E3 {
|
||||
A,
|
||||
B;
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
enum class E4 {
|
||||
A,
|
||||
B
|
||||
;
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
enum class E1 {
|
||||
A,
|
||||
B; fun foo() {}
|
||||
}
|
||||
|
||||
enum class E2 {
|
||||
A,
|
||||
B;
|
||||
|
||||
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
enum class E3 {
|
||||
A,
|
||||
B;
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
enum class E4 {
|
||||
A,
|
||||
B
|
||||
;
|
||||
fun foo() {}
|
||||
}
|
||||
@@ -33,6 +33,12 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Formatter extends AbstractJetFormatterTest {
|
||||
@TestMetadata("AfterSemiColonInEnumClass.after.kt")
|
||||
public void testAfterSemiColonInEnumClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/AfterSemiColonInEnumClass.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInFormatter() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user