Setup spacing rules for anonymous initializers
This commit is contained in:
@@ -46,7 +46,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
val jetCommonSettings = settings.getCommonSettings(JetLanguage.INSTANCE)!!
|
||||
|
||||
return rules(settings) {
|
||||
val DECLARATIONS = TokenSet.create(PROPERTY, FUN, CLASS, OBJECT_DECLARATION, ENUM_ENTRY, SECONDARY_CONSTRUCTOR)
|
||||
val DECLARATIONS =
|
||||
TokenSet.create(PROPERTY, FUN, CLASS, OBJECT_DECLARATION, ENUM_ENTRY, SECONDARY_CONSTRUCTOR, ANONYMOUS_INITIALIZER)
|
||||
|
||||
custom {
|
||||
inPosition(left = CLASS, right = CLASS).emptyLinesIfLineBreakInLeft(1)
|
||||
@@ -92,6 +93,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
|
||||
between(OBJECT_DECLARATION, DECLARATIONS).blankLines(1)
|
||||
between(SECONDARY_CONSTRUCTOR, DECLARATIONS).blankLines(1)
|
||||
between(ANONYMOUS_INITIALIZER, DECLARATIONS).blankLines(1)
|
||||
|
||||
// ENUM_ENTRY - ENUM_ENTRY is exception
|
||||
between(ENUM_ENTRY, DECLARATIONS).blankLines(1)
|
||||
@@ -260,6 +262,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
||||
|
||||
inPosition(parent = FUN, right = BLOCK).customRule(leftBraceRule())
|
||||
inPosition(parent = SECONDARY_CONSTRUCTOR, right = BLOCK).customRule(leftBraceRule())
|
||||
inPosition(parent = ANONYMOUS_INITIALIZER, right = BLOCK).customRule(leftBraceRule())
|
||||
inPosition(parent = PROPERTY_ACCESSOR, right = BLOCK).customRule(leftBraceRule())
|
||||
|
||||
inPosition(right = CLASS_BODY).customRule(leftBraceRule(blockType = CLASS_BODY))
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
annotation class Ann
|
||||
class A {
|
||||
{
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
fun foo1() {
|
||||
|
||||
}
|
||||
|
||||
val x: Int = 1
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
fun foo2() {
|
||||
|
||||
}
|
||||
|
||||
Ann init {
|
||||
}
|
||||
|
||||
Ann init {
|
||||
}
|
||||
|
||||
|
||||
fun foo3() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* abcde */init {
|
||||
|
||||
}
|
||||
|
||||
fun foo4() {
|
||||
|
||||
}
|
||||
|
||||
val a3 = foo4() // el
|
||||
|
||||
/* abc */ init {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
annotation class Ann
|
||||
class A {
|
||||
{}{}{}
|
||||
fun foo1() {
|
||||
|
||||
}
|
||||
val x: Int = 1
|
||||
init{}
|
||||
fun foo2() {
|
||||
|
||||
}
|
||||
Ann init {}
|
||||
Ann init {}
|
||||
|
||||
|
||||
fun foo3() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
{}
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* abcde */init {
|
||||
|
||||
}
|
||||
|
||||
fun foo4() {
|
||||
|
||||
}
|
||||
|
||||
val a3 = foo4() // el
|
||||
/* abc */ init {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
annotation class Ann
|
||||
class A {
|
||||
{
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
init {
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
/* abcde */init {
|
||||
|
||||
}
|
||||
|
||||
/* abc */ init // eol-comment
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
// SET_TRUE: LBRACE_ON_NEXT_LINE
|
||||
@@ -0,0 +1,35 @@
|
||||
annotation class Ann
|
||||
class A
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
init
|
||||
{
|
||||
}
|
||||
|
||||
init
|
||||
{
|
||||
}
|
||||
|
||||
init
|
||||
{
|
||||
}
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
/* abcde */init
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* abc */ init // eol-comment
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
// SET_TRUE: LBRACE_ON_NEXT_LINE
|
||||
@@ -0,0 +1,22 @@
|
||||
annotation class Ann
|
||||
class A {
|
||||
{}{}
|
||||
|
||||
init{}
|
||||
|
||||
init {}
|
||||
|
||||
init {}
|
||||
|
||||
{}
|
||||
|
||||
/* abcde */init {
|
||||
|
||||
}
|
||||
|
||||
/* abc */ init // eol-comment
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
// SET_TRUE: LBRACE_ON_NEXT_LINE
|
||||
@@ -46,6 +46,18 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnonymousInitializers.after.kt")
|
||||
public void testAnonymousInitializers() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/AnonymousInitializers.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AnonymousInitializersLineBreak.after.kt")
|
||||
public void testAnonymousInitializersLineBreak() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/AnonymousInitializersLineBreak.after.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ArrayAccess.after.kt")
|
||||
public void testArrayAccess() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/ArrayAccess.after.kt");
|
||||
@@ -705,6 +717,12 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/formatter"), Pattern.compile("^([^\\.]+)\\.after\\.inv\\.kt.*$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AnonymousInitializersLineBreak.after.inv.kt")
|
||||
public void testAnonymousInitializersLineBreak() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/AnonymousInitializersLineBreak.after.inv.kt");
|
||||
doTestInverted(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("BinaryExpressions.after.inv.kt")
|
||||
public void testBinaryExpressions() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/BinaryExpressions.after.inv.kt");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class Test {
|
||||
var str: String
|
||||
|
||||
{
|
||||
str = "Ola"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Test {
|
||||
companion object {
|
||||
var str: String
|
||||
|
||||
{
|
||||
str = "Ola"
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@ class C(a: Int) {
|
||||
{
|
||||
abc = a * 2
|
||||
}
|
||||
|
||||
var abc = 0
|
||||
}
|
||||
Reference in New Issue
Block a user