1- package dotty .tools .dotc
1+ package dotty .tools .dotc . core . tasty
22
33import dotty .tools .dotc .ast .tpd
4+ import dotty .tools .dotc .ast .tpd .TreeOps
5+ import dotty .tools .dotc .Driver
46import dotty .tools .dotc .core .Comments .CommentsContext
57import dotty .tools .dotc .core .Contexts .Context
68import dotty .tools .dotc .core .Decorators .PreNamedString
79import dotty .tools .dotc .core .Mode
810import dotty .tools .dotc .core .Names .Name
9- import dotty .tools .dotc .core .tasty .DottyUnpickler
1011import dotty .tools .dotc .interfaces .Diagnostic .ERROR
1112import dotty .tools .dotc .reporting .TestReporter
1213
@@ -17,18 +18,13 @@ import java.nio.file.{FileSystems, FileVisitOption, FileVisitResult, FileVisitor
1718import java .nio .file .attribute .BasicFileAttributes
1819import java .util .EnumSet
1920
21+ import scala .collection .JavaConverters .asScalaIteratorConverter
2022import scala .concurrent .duration .{Duration , DurationInt }
2123
2224import org .junit .Test
2325import org .junit .Assert .{assertEquals , assertFalse , fail }
2426
25- class CommentPicklingTest extends ParallelTesting {
26-
27- override def isInteractive : Boolean = false
28- override def testFilter : Option [String ] = None
29- override def maxDuration : Duration = 30 .seconds
30- override def numberOfSlaves : Int = 5
31- override def safeMode : Boolean = false
27+ class CommentPicklingTest {
3228
3329 val compileOptions = TestConfiguration .defaultOptions and " -Ykeep-comments" and " -Yemit-tasty"
3430 val unpickleOptions = TestConfiguration .defaultOptions
@@ -68,7 +64,7 @@ class CommentPicklingTest extends ParallelTesting {
6864 compileAndCheckComment(sources, " buzz" .toTermName, Some (" /** foo */" ))
6965 }
7066
71- private def compileAndCheckComment (sources : Seq [String ], treeName : Name , expectedComment : Option [String ]): Unit = {
67+ private def compileAndCheckComment (sources : List [String ], treeName : Name , expectedComment : Option [String ]): Unit = {
7268 compileAndUnpickle(sources) { (trees, ctx) =>
7369 findTreeNamed(treeName)(trees, ctx) match {
7470 case Some (md : tpd.MemberDef ) =>
@@ -82,20 +78,19 @@ class CommentPicklingTest extends ParallelTesting {
8278 }
8379 }
8480
85- private def findTreeNamed (name : Name )(trees : Seq [tpd.Tree ], ctx : Context ): Option [tpd.NameTree ] = {
81+ private def findTreeNamed (name : Name )(trees : List [tpd.Tree ], ctx : Context ): Option [tpd.NameTree ] = {
8682 val acc = new tpd.TreeAccumulator [Option [tpd.NameTree ]] {
8783 override def apply (x : Option [tpd.NameTree ], tree : tpd.Tree )(implicit ctx : Context ): Option [tpd.NameTree ] = {
8884 x.orElse(tree match {
8985 case md : tpd.NameTree if md.name == name => Some (md)
90- case md : tpd.NameTree => foldOver(None , md)
9186 case other => foldOver(None , other)
9287 })
9388 }
9489 }
9590 acc(None , trees)(ctx)
9691 }
9792
98- private def compileAndUnpickle [T ](sources : Seq [String ])(fn : (Seq [tpd.Tree ], Context ) => T ) = {
93+ private def compileAndUnpickle [T ](sources : List [String ])(fn : (List [tpd.Tree ], Context ) => T ) = {
9994 inTempDirectory { tmp =>
10095 val sourceFiles = sources.zipWithIndex.map {
10196 case (src, id) =>
@@ -124,7 +119,7 @@ class CommentPicklingTest extends ParallelTesting {
124119
125120 private class UnpicklingDriver extends Driver {
126121 override def initCtx = super .initCtx.addMode(Mode .ReadComments )
127- def unpickle [T ](args : Array [String ], paths : Seq [Path ])(fn : (Seq [tpd.Tree ], Context ) => T ): T = {
122+ def unpickle [T ](args : Array [String ], paths : List [Path ])(fn : (List [tpd.Tree ], Context ) => T ): T = {
128123 implicit val (_, ctx : Context ) = setup(args, initCtx)
129124 ctx.initialize()
130125 val trees = paths.flatMap { p =>
@@ -146,33 +141,11 @@ class CommentPicklingTest extends ParallelTesting {
146141 }
147142 }
148143
149- private def getAll (base : Path ,
150- pattern : String ,
151- maxDepth : Int = Int .MaxValue ): Seq [Path ] = {
152- val out = collection.mutable.ListBuffer .empty[Path ]
144+ private def getAll (base : Path , pattern : String ): List [Path ] = {
145+ val paths = Files .walk(base)
153146 val matcher = FileSystems .getDefault.getPathMatcher(pattern)
154- val visitor = new FileVisitor [Path ] {
155- override def preVisitDirectory (directory : Path , attributes : BasicFileAttributes ): FileVisitResult = {
156- if (matcher.matches(directory)) out += directory
157- FileVisitResult .CONTINUE
158- }
159-
160- override def postVisitDirectory (directory : Path , exception : IOException ): FileVisitResult =
161- FileVisitResult .CONTINUE
162-
163- override def visitFile (file : Path , attributes : BasicFileAttributes ): FileVisitResult = {
164- if (matcher.matches(file)) out += file
165- FileVisitResult .CONTINUE
166- }
167-
168- override def visitFileFailed (file : Path , exception : IOException ): FileVisitResult =
169- FileVisitResult .CONTINUE
170- }
171- Files .walkFileTree(base,
172- EnumSet .of(FileVisitOption .FOLLOW_LINKS ),
173- maxDepth,
174- visitor)
175- out
147+ try paths.filter(matcher.matches).iterator().asScala.toList
148+ finally paths.close()
176149 }
177150
178151}
0 commit comments