Formatter: force keyword to be on exactly next line if the corresponding option is set
This commit is contained in:
@@ -67,11 +67,12 @@ class KotlinSpacingBuilder(val codeStyleSettings: CodeStyleSettings) {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun lineBreakIfLineBreakInParent(numSpacesOtherwise: Int) {
|
fun lineBreakIfLineBreakInParent(numSpacesOtherwise: Int, allowBlankLines: Boolean = true) {
|
||||||
newRule {
|
newRule {
|
||||||
p, l, r ->
|
p, l, r ->
|
||||||
Spacing.createDependentLFSpacing(numSpacesOtherwise, numSpacesOtherwise, p.getTextRange(),
|
Spacing.createDependentLFSpacing(numSpacesOtherwise, numSpacesOtherwise, p.getTextRange(),
|
||||||
codeStyleSettings.KEEP_LINE_BREAKS, codeStyleSettings.KEEP_BLANK_LINES_IN_CODE)
|
codeStyleSettings.KEEP_LINE_BREAKS,
|
||||||
|
if (allowBlankLines) codeStyleSettings.KEEP_BLANK_LINES_IN_CODE else 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +192,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
|||||||
fun CustomSpacingBuilder.ruleForKeywordOnNewLine(shouldBeOnNewLine: Boolean, keyword: IElementType, parent: IElementType) {
|
fun CustomSpacingBuilder.ruleForKeywordOnNewLine(shouldBeOnNewLine: Boolean, keyword: IElementType, parent: IElementType) {
|
||||||
if (shouldBeOnNewLine) {
|
if (shouldBeOnNewLine) {
|
||||||
inPosition(parent = parent, right = keyword)
|
inPosition(parent = parent, right = keyword)
|
||||||
.lineBreakIfLineBreakInParent(numSpacesOtherwise = 1)
|
.lineBreakIfLineBreakInParent(numSpacesOtherwise = 1, allowBlankLines = false)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
inPosition(parent = parent, right = keyword).customRule {
|
inPosition(parent = parent, right = keyword).customRule {
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ fun f() {
|
|||||||
} catch (e: E) {
|
} catch (e: E) {
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (e: E) {
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SET_TRUE: CATCH_ON_NEW_LINE
|
// SET_TRUE: CATCH_ON_NEW_LINE
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ fun f() {
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
}
|
||||||
|
catch (e: E) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SET_TRUE: CATCH_ON_NEW_LINE
|
// SET_TRUE: CATCH_ON_NEW_LINE
|
||||||
|
|||||||
@@ -10,6 +10,15 @@ fun f() {
|
|||||||
} catch (e: E) {
|
} catch (e: E) {
|
||||||
} finally {
|
} finally {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (e: E) {
|
||||||
|
}
|
||||||
|
|
||||||
|
finally {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SET_TRUE: CATCH_ON_NEW_LINE
|
// SET_TRUE: CATCH_ON_NEW_LINE
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ fun f() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
} else if (true) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
} else if (true) {
|
} else if (true) {
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ fun f() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
}
|
||||||
|
else if (true) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
}
|
}
|
||||||
else if (true) {
|
else if (true) {
|
||||||
|
|||||||
@@ -12,6 +12,15 @@ fun f() {
|
|||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (true) {
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
|
||||||
if (a) 3 else 4
|
if (a) 3 else 4
|
||||||
|
|
||||||
if (a) 5
|
if (a) 5
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ fun f() {
|
|||||||
|
|
||||||
} while (true)
|
} while (true)
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
} while (true)
|
||||||
|
|
||||||
do a += 1 while (true)
|
do a += 1 while (true)
|
||||||
|
|
||||||
do a += 1
|
do a += 1
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ fun f() {
|
|||||||
}
|
}
|
||||||
while (true)
|
while (true)
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
}
|
||||||
|
while (true)
|
||||||
|
|
||||||
do a += 1 while (true)
|
do a += 1 while (true)
|
||||||
|
|
||||||
do a += 1
|
do a += 1
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ fun f() {
|
|||||||
}
|
}
|
||||||
while (true)
|
while (true)
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
|
||||||
do a += 1 while (true)
|
do a += 1 while (true)
|
||||||
|
|
||||||
do a += 1
|
do a += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user