1
- package dotty .tools .dotc
1
+ package dotty .tools .dotc . core . tasty
2
2
3
3
import dotty .tools .dotc .ast .tpd
4
+ import dotty .tools .dotc .ast .tpd .TreeOps
5
+ import dotty .tools .dotc .Driver
4
6
import dotty .tools .dotc .core .Comments .CommentsContext
5
7
import dotty .tools .dotc .core .Contexts .Context
6
8
import dotty .tools .dotc .core .Decorators .PreNamedString
7
9
import dotty .tools .dotc .core .Mode
8
10
import dotty .tools .dotc .core .Names .Name
9
- import dotty .tools .dotc .core .tasty .DottyUnpickler
10
11
import dotty .tools .dotc .interfaces .Diagnostic .ERROR
11
12
import dotty .tools .dotc .reporting .TestReporter
12
13
@@ -17,18 +18,13 @@ import java.nio.file.{FileSystems, FileVisitOption, FileVisitResult, FileVisitor
17
18
import java .nio .file .attribute .BasicFileAttributes
18
19
import java .util .EnumSet
19
20
21
+ import scala .collection .JavaConverters .asScalaIteratorConverter
20
22
import scala .concurrent .duration .{Duration , DurationInt }
21
23
22
24
import org .junit .Test
23
25
import org .junit .Assert .{assertEquals , assertFalse , fail }
24
26
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 {
32
28
33
29
val compileOptions = TestConfiguration .defaultOptions and " -Ykeep-comments" and " -Yemit-tasty"
34
30
val unpickleOptions = TestConfiguration .defaultOptions
@@ -68,7 +64,7 @@ class CommentPicklingTest extends ParallelTesting {
68
64
compileAndCheckComment(sources, " buzz" .toTermName, Some (" /** foo */" ))
69
65
}
70
66
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 = {
72
68
compileAndUnpickle(sources) { (trees, ctx) =>
73
69
findTreeNamed(treeName)(trees, ctx) match {
74
70
case Some (md : tpd.MemberDef ) =>
@@ -82,20 +78,19 @@ class CommentPicklingTest extends ParallelTesting {
82
78
}
83
79
}
84
80
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 ] = {
86
82
val acc = new tpd.TreeAccumulator [Option [tpd.NameTree ]] {
87
83
override def apply (x : Option [tpd.NameTree ], tree : tpd.Tree )(implicit ctx : Context ): Option [tpd.NameTree ] = {
88
84
x.orElse(tree match {
89
85
case md : tpd.NameTree if md.name == name => Some (md)
90
- case md : tpd.NameTree => foldOver(None , md)
91
86
case other => foldOver(None , other)
92
87
})
93
88
}
94
89
}
95
90
acc(None , trees)(ctx)
96
91
}
97
92
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 ) = {
99
94
inTempDirectory { tmp =>
100
95
val sourceFiles = sources.zipWithIndex.map {
101
96
case (src, id) =>
@@ -124,7 +119,7 @@ class CommentPicklingTest extends ParallelTesting {
124
119
125
120
private class UnpicklingDriver extends Driver {
126
121
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 = {
128
123
implicit val (_, ctx : Context ) = setup(args, initCtx)
129
124
ctx.initialize()
130
125
val trees = paths.flatMap { p =>
@@ -146,33 +141,11 @@ class CommentPicklingTest extends ParallelTesting {
146
141
}
147
142
}
148
143
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)
153
146
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()
176
149
}
177
150
178
151
}
0 commit comments