File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
main/scala/org/apache/spark/sql/catalyst/expressions/codegen
test/scala/org/apache/spark/sql/catalyst/expressions/codegen Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change 1818package org .apache .spark .sql .catalyst .expressions .codegen
1919
2020/**
21- * An utility class that indents a block of code based on the curly braces.
22- *
21+ * An utility class that indents a block of code based on the curly braces and parentheses.
2322 * This is used to prettify generated code when in debug mode (or exceptions).
2423 *
2524 * Written by Matei Zaharia.
@@ -35,11 +34,11 @@ private class CodeFormatter {
3534 private var indentString = " "
3635
3736 private def addLine (line : String ): Unit = {
38- val indentChange = line.count(_ == '{' ) - line.count(_ == '}' )
37+ val indentChange = line.count(c => c == '{' || c == '(' ) - line.count(c => c == '}' || c == ') ' )
3938 val newIndentLevel = math.max(0 , indentLevel + indentChange)
4039 // Lines starting with '}' should be de-indented even if they contain '{' after;
4140 // in addition, lines ending with ':' are typically labels
42- val thisLineIndent = if (line.startsWith(" }" ) || line.endsWith(" :" )) {
41+ val thisLineIndent = if (line.startsWith(" }" ) || line.startsWith( " ) " ) || line. endsWith(" :" )) {
4342 " " * (indentSize * (indentLevel - 1 ))
4443 } else {
4544 indentString
Original file line number Diff line number Diff line change @@ -73,4 +73,34 @@ class CodeFormatterSuite extends SparkFunSuite {
7373 |}
7474 """ .stripMargin
7575 }
76+
77+ testCase(" if else on the same line" ) {
78+ """
79+ |class A {
80+ | if (c) {duh;} else {boo;}
81+ |}
82+ """ .stripMargin
83+ }{
84+ """
85+ |class A {
86+ | if (c) {duh;} else {boo;}
87+ |}
88+ """ .stripMargin
89+ }
90+
91+ testCase(" function calls" ) {
92+ """
93+ |foo(
94+ |a,
95+ |b,
96+ |c)
97+ """ .stripMargin
98+ }{
99+ """
100+ |foo(
101+ | a,
102+ | b,
103+ | c)
104+ """ .stripMargin
105+ }
76106}
You can’t perform that action at this time.
0 commit comments