@@ -31,15 +31,22 @@ object WrappedSnippet:
31
31
val ps = new PrintStream (baos)
32
32
ps.println(s " package ${packageName.getOrElse(" snippets" )}" )
33
33
imports.foreach(i => ps.println(s " import $i" ))
34
- classInfos.zipWithIndex.foreach { (info, i) =>
34
+ val notEmptyClassInfos = if classInfos.isEmpty then Seq (SnippetCompilerData .ClassInfo (None , Nil , None )) else classInfos
35
+ notEmptyClassInfos.zipWithIndex.foreach { (info, i) =>
35
36
ps.printlnWithIndent(2 * i, s " trait Snippet $i${info.generics.getOrElse(" " )} { ${info.tpe.fold(" " )(cn => s " self: $cn => " )}" )
36
37
info.names.foreach{ name =>
37
38
ps.printlnWithIndent(2 * i + 2 , s " val $name = self " )
38
39
}
39
40
}
40
- str.split('\n ' ).foreach(ps.printlnWithIndent(classInfos.size * 2 , _))
41
- (0 to classInfos.size - 1 ).reverse.foreach( i => ps.printlnWithIndent(i * 2 , " }" ))
42
- WrappedSnippet (baos.toString, lineOffset, columnOffset, classInfos.size + classInfos.flatMap(_.names).size, classInfos.size * 2 + 2 )
41
+ str.split('\n ' ).foreach(ps.printlnWithIndent(notEmptyClassInfos.size * 2 , _))
42
+ (0 to notEmptyClassInfos.size - 1 ).reverse.foreach( i => ps.printlnWithIndent(i * 2 , " }" ))
43
+ WrappedSnippet (
44
+ baos.toString,
45
+ lineOffset,
46
+ columnOffset,
47
+ notEmptyClassInfos.size + notEmptyClassInfos.flatMap(_.names).size + packageName.size,
48
+ notEmptyClassInfos.size * 2 + 2
49
+ )
43
50
44
51
extension (ps : PrintStream ) private def printlnWithIndent (indent : Int , str : String ) =
45
52
ps.println((" " * indent) + str)
0 commit comments