@@ -13,6 +13,8 @@ package dotty.tools
1313 */
1414
1515object GenerateFunctionConverters {
16+ import scala .tools .nsc ._
17+
1618 case class Artifact (name : String , content : String )
1719
1820 val copyright =
@@ -33,7 +35,6 @@ object GenerateFunctionConverters {
3335
3436 val packaging = " package scala.jdk"
3537
36- import scala .tools .nsc ._
3738 val settings = new Settings (msg => sys.error(msg))
3839 def us (cl : ClassLoader ): List [String ] = cl match {
3940 case ucl : java.net.URLClassLoader => ucl.getURLs.map(u => new java.io.File (u.toURI).getAbsolutePath).toList ::: us(ucl.getParent)
@@ -44,6 +45,7 @@ object GenerateFunctionConverters {
4445 val run = new compiler.Run
4546
4647 import compiler ._ , definitions ._
48+
4749 locally {
4850 // make sure `java.lang.Double` prints as `java.lang.Double`, not just `Double` (which resolves to `scala.Double`)
4951 val f = classOf [scala.reflect.internal.Definitions # DefinitionsClass ].getDeclaredField(" UnqualifiedOwners" )
@@ -65,43 +67,50 @@ object GenerateFunctionConverters {
6567 }
6668
6769 implicit class IndentMe (v : Vector [String ]) {
70+ /** Adds indentation to every line in the vector. */
6871 def indent : Vector [String ] = v.map(" " + _)
6972 }
7073
71- implicit class FlattenMe (v : Vector [Vector [String ]]) {
72- def mkVec ( join : String = " " ) : Vector [ String ] = {
73- val vb = Vector .newBuilder [String ]
74+ implicit class WriteToBuilder (v : Vector [Vector [String ]]) {
75+ /** Writes the vector into a builder, with `join` inserted between each group. */
76+ def writeTo ( builder : collection.mutable. Builder [ String , Vector [String ]], join : String = " " ) = {
7477 var first = true
75- v.foreach{ vi =>
76- if (! first) vb += join
78+ for ( vi <- v) {
79+ if (! first) builder += join
7780 first = false
78- vb ++= vi
81+ builder ++= vi
7982 }
83+ }
84+ }
85+
86+ implicit class FlattenMe (v : Vector [Vector [String ]]) {
87+ /** Joins the given `Vector[Vector[String]]`, with `join` inserted in between. */
88+ def mkVec (join : String = " " ): Vector [String ] = {
89+ val vb = Vector .newBuilder[String ]
90+ v.writeTo(vb)
8091 vb.result()
8192 }
8293 }
8394
8495 implicit class DoubleFlattenMe (v : Vector [Vector [Vector [String ]]]) {
96+ /** Like `mkVec`, but done twice, with `join` inserted twice between outer blocks. */
8597 def mkVecVec (join : String = " " ): Vector [String ] = {
8698 val vb = Vector .newBuilder[String ]
8799 var first = true
88- v.foreach{ vi =>
100+ for ( vi <- v) {
89101 if (! first) { vb += join; vb += join }
90102 first = false
91- var ifirst = true
92- vi.foreach{ vj =>
93- if (! ifirst) vb += join
94- ifirst = false
95- vb ++= vj
96- }
103+ vi.writeTo(vb, join)
97104 }
98105 vb.result()
99106 }
100107 }
101108
102- implicit class SplitMyLinesAndStuff (s : String ) {
109+ implicit class StringExtensions (s : String ) {
103110 // work around scala/bug#11125
111+ /** Splits the string into a `Vector` of lines. */
104112 def toVec = Predef .augmentString(s).lines.toVector
113+ /** Is the string a blank line? */
105114 def nonBlank = s.trim.length > 0
106115 }
107116
0 commit comments