Formatter: left brace formatting for function declaration

This commit is contained in:
Pavel V. Talanov
2014-01-17 13:12:05 +04:00
parent e0b1170dc6
commit e1dab0e1c7
13 changed files with 143 additions and 19 deletions
@@ -147,8 +147,6 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
around(TokenSet.create(PLUSPLUS, MINUSMINUS, EXCLEXCL, MINUS, PLUS, EXCL)).spaceIf(jetCommonSettings.SPACE_AROUND_UNARY_OPERATOR)
around(RANGE).spaceIf(jetSettings.SPACE_AROUND_RANGE)
beforeInside(BLOCK, FUN).spaceIf(jetCommonSettings.SPACE_BEFORE_METHOD_LBRACE)
afterInside(LPAR, VALUE_PARAMETER_LIST).spaces(0)
beforeInside(RPAR, VALUE_PARAMETER_LIST).spaces(0)
afterInside(LT, TYPE_PARAMETER_LIST).spaces(0)
@@ -233,6 +231,8 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
inPosition(parent = CATCH, right = BLOCK).customRule(leftBraceRule)
inPosition(parent = FINALLY, right = BLOCK).customRule(leftBraceRule)
inPosition(parent = FUN, right = BLOCK).customRule(leftBraceRule)
val spacesInSimpleFunction = if (jetSettings.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD) 1 else 0
inPosition(parent = FUNCTION_LITERAL,
@@ -1,4 +1,5 @@
fun main() {
fun main()
{
do
{
@@ -1,4 +1,5 @@
fun main() {
fun main()
{
for (a in b)
{
}
@@ -0,0 +1,35 @@
fun f() {
}
fun f() {
}
fun f() {
}
fun f() //eol comment
{
}
fun f() //eol comment
{
}
class A {
fun f() {
}
fun f() {
}
}
fun g() {
fun f() {
}
fun f() {
}
}
// SET_TRUE: LBRACE_ON_NEXT_LINE
@@ -0,0 +1,43 @@
fun f()
{
}
fun f()
{
}
fun f()
{
}
fun f() //eol comment
{
}
fun f() //eol comment
{
}
class A {
fun f()
{
}
fun f()
{
}
}
fun g()
{
fun f()
{
}
fun f()
{
}
}
// SET_TRUE: LBRACE_ON_NEXT_LINE
@@ -0,0 +1,41 @@
fun f() {
}
fun f()
{
}
fun f()
{
}
fun f() //eol comment
{
}
fun f() //eol comment
{
}
class A {
fun f() {
}
fun f()
{
}
}
fun g() {
fun f() {
}
fun f()
{
}
}
// SET_TRUE: LBRACE_ON_NEXT_LINE
@@ -1,3 +0,0 @@
fun test()
{
}
@@ -1,3 +0,0 @@
fun test()
{
}
@@ -1,4 +1,5 @@
fun main(args: Array<String>) {
fun main(args: Array<String>)
{
if (true)
{
false
@@ -1,4 +1,5 @@
fun main(args: Array<String>) {
fun main(args: Array<String>)
{
if (true) // tricky comment
{
}
@@ -1,4 +1,5 @@
fun f() {
fun f()
{
try
{
@@ -1,4 +1,5 @@
fun main(args: Array<String>) {
fun main(args: Array<String>)
{
while (true)
{
}
@@ -99,16 +99,16 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
doTest("idea/testData/formatter/FunctionDefParametersAlign.after.kt");
}
@TestMetadata("FunctionLineBreak.after.kt")
public void testFunctionLineBreak() throws Exception {
doTest("idea/testData/formatter/FunctionLineBreak.after.kt");
}
@TestMetadata("FunctionWithInference.after.kt")
public void testFunctionWithInference() throws Exception {
doTest("idea/testData/formatter/FunctionWithInference.after.kt");
}
@TestMetadata("FunctionWithNewLineBrace.after.kt")
public void testFunctionWithNewLineBrace() throws Exception {
doTest("idea/testData/formatter/FunctionWithNewLineBrace.after.kt");
}
@TestMetadata("FunctionalType.after.kt")
public void testFunctionalType() throws Exception {
doTest("idea/testData/formatter/FunctionalType.after.kt");
@@ -372,6 +372,11 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
doTestInverted("idea/testData/formatter/ForLineBreak.after.inv.kt");
}
@TestMetadata("FunctionLineBreak.after.inv.kt")
public void testFunctionLineBreak() throws Exception {
doTestInverted("idea/testData/formatter/FunctionLineBreak.after.inv.kt");
}
@TestMetadata("FunctionalType.after.inv.kt")
public void testFunctionalType() throws Exception {
doTestInverted("idea/testData/formatter/FunctionalType.after.inv.kt");