Skip to content

Commit 24bd961

Browse files
committed
refactor: simlify code
1 parent daee922 commit 24bd961

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

chapi-helper/src/main/kotlin/chapi/ast/helper/TreeViewer.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import org.antlr.v4.runtime.tree.Trees;
77
class TreeViewer {
88

99
/** Platform dependent end-of-line marker */
10-
val Eol = System.lineSeparator()
10+
val endOfLine = System.lineSeparator()
1111

1212
/** The literal indent char(s) used for pretty-printing */
13-
val Indents = " "
13+
val indents = " "
1414
private var level = 0
1515

1616
/**
@@ -19,7 +19,7 @@ class TreeViewer {
1919
*/
2020
fun toPrettyTree(t: Tree, ruleNames: List<String>): String {
2121
level = 0
22-
return process(t, ruleNames).replace("(?m)^\\s+$".toRegex(), "").replace("\\r?\\n\\r?\\n".toRegex(), Eol)
22+
return process(t, ruleNames).replace("(?m)^\\s+$".toRegex(), "").replace("\\r?\\n\\r?\\n".toRegex(), endOfLine)
2323
}
2424

2525
private fun process(t: Tree, ruleNames: List<String>): String {
@@ -29,7 +29,7 @@ class TreeViewer {
2929
level++
3030
val s: String = Utils.escapeWhitespace(Trees.getNodeText(t, ruleNames), false)
3131
sb.append("$s ")
32-
for (i in 0 until t.getChildCount()) {
32+
for (i in 0 until t.childCount) {
3333
sb.append(process(t.getChild(i), ruleNames))
3434
}
3535
level--
@@ -40,9 +40,9 @@ class TreeViewer {
4040
private fun lead(level: Int): String {
4141
val sb = StringBuilder()
4242
if (level > 0) {
43-
sb.append(Eol)
43+
sb.append(endOfLine)
4444
for (cnt in 0 until level) {
45-
sb.append(Indents)
45+
sb.append(indents)
4646
}
4747
}
4848

0 commit comments

Comments
 (0)