Skip to content

Commit 78787be

Browse files
committed
wip
1 parent 5af772f commit 78787be

File tree

1 file changed

+17
-90
lines changed

1 file changed

+17
-90
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 17 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -313,102 +313,39 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
313313

314314
}
315315

316-
def printTrees(trees: List[Tree], sep: String): Buffer = {
317-
def printSeparated(list: List[Tree]): Unit = list match {
318-
case Nil =>
319-
case x :: Nil => printTree(x)
320-
case x :: xs =>
321-
printTree(x)
322-
this += sep
323-
printSeparated(xs)
316+
def printTrees(trees: List[Tree], sep: String): Buffer = printSeparated(trees, sep, printTree)
317+
def printCases(cases: List[CaseDef], sep: String): Buffer = printSeparated(cases, sep, printCase)
318+
def printPatterns(patterns: List[Pattern], sep: String): Buffer = printSeparated(patterns, sep, printPattern)
319+
def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = printSeparated(typesTrees, sep, printTypeTree)
320+
def printTypesOrBounds(types: List[TypeOrBounds], sep: String): Buffer = printSeparated(types, sep, printTypeOrBound)
321+
322+
def printTargsDefs(targs: List[TypeDef]): Unit = {
323+
if (!targs.isEmpty) {
324+
this += "["
325+
printSeparated(targs, ", ", printTargDef)
326+
this += "]"
324327
}
325-
printSeparated(trees)
326-
this
327328
}
328329

329330
def printImportSelectors(selectors: List[ImportSelector]): Buffer = {
330-
def printSeparated(list: List[ImportSelector]): Unit = list match {
331-
case Nil =>
332-
case x :: Nil => printImportSelector(x)
333-
case x :: xs =>
334-
printImportSelector(x)
335-
this += ", "
336-
printSeparated(xs)
337-
}
338331
this += "{"
339-
printSeparated(selectors)
332+
printSeparated(selectors, ", ", printImportSelector)
340333
this += "}"
341334
}
342335

343-
def printCases(cases: List[CaseDef], sep: String): Buffer = {
344-
def printSeparated(list: List[CaseDef]): Unit = list match {
336+
def printSeparated[U](typesTrees: List[U], sep: String, print: U => Unit): Buffer = {
337+
def printSeparated(list: List[U]): Unit = list match {
345338
case Nil =>
346-
case x :: Nil => printCase(x)
339+
case x :: Nil => print(x)
347340
case x :: xs =>
348-
printCase(x)
349-
this += sep
350-
printSeparated(xs)
351-
}
352-
printSeparated(cases)
353-
this
354-
}
355-
356-
def printPatterns(cases: List[Pattern], sep: String): Buffer = {
357-
def printSeparated(list: List[Pattern]): Unit = list match {
358-
case Nil =>
359-
case x :: Nil => printPattern(x)
360-
case x :: xs =>
361-
printPattern(x)
362-
this += sep
363-
printSeparated(xs)
364-
}
365-
printSeparated(cases)
366-
this
367-
}
368-
369-
def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = {
370-
def printSeparated(list: List[TypeTree]): Unit = list match {
371-
case Nil =>
372-
case x :: Nil => printTypeTree(x)
373-
case x :: xs =>
374-
printTypeTree(x)
341+
print(x)
375342
this += sep
376343
printSeparated(xs)
377344
}
378345
printSeparated(typesTrees)
379346
this
380347
}
381348

382-
def printTypesOrBounds(types: List[TypeOrBounds], sep: String): Buffer = {
383-
def printSeparated(list: List[TypeOrBounds]): Unit = list match {
384-
case Nil =>
385-
case x :: Nil => printTypeOrBound(x)
386-
case x :: xs =>
387-
printTypeOrBound(x)
388-
this += sep
389-
printSeparated(xs)
390-
}
391-
printSeparated(types)
392-
this
393-
}
394-
395-
def printTargsDefs(targs: List[TypeDef]): Unit = {
396-
if (!targs.isEmpty) {
397-
def printSeparated(list: List[TypeDef]): Unit = list match {
398-
case Nil =>
399-
case x :: Nil => printTargDef(x)
400-
case x :: xs =>
401-
printTargDef(x)
402-
this += ", "
403-
printSeparated(xs)
404-
}
405-
406-
this += "["
407-
printSeparated(targs)
408-
this += "]"
409-
}
410-
}
411-
412349
def printTargDef(arg: TypeDef): Buffer = {
413350
val TypeDef(name, rhs) = arg
414351
this += name
@@ -434,17 +371,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
434371

435372
def printArgsDefs(args: List[ValDef]): Unit = {
436373
this += "("
437-
438-
def printSeparated(list: List[ValDef]): Unit = list match {
439-
case Nil =>
440-
case x :: Nil => printArgDef(x)
441-
case x :: xs =>
442-
printArgDef(x)
443-
this += ", "
444-
printSeparated(xs)
445-
}
446-
447-
printSeparated(args)
374+
printSeparated(args, ", ", printArgDef)
448375
this += ")"
449376
}
450377

0 commit comments

Comments
 (0)