@@ -69,7 +69,7 @@ class ExtractDependencies extends Phase {
69
69
extractDeps.traverse(unit.tpdTree)
70
70
71
71
if (dumpInc) {
72
- val names = extractDeps.usedNames.map(_.toString) .toArray[Object ]
72
+ val names = extractDeps.usedNames.map { case (clazz, names) => s " $clazz : $names " } .toArray[Object ]
73
73
val deps = extractDeps.dependencies.map(_.toString).toArray[Object ]
74
74
Arrays .sort(names)
75
75
Arrays .sort(deps)
@@ -82,20 +82,12 @@ class ExtractDependencies extends Phase {
82
82
}
83
83
84
84
if (ctx.sbtCallback != null ) {
85
- extractDeps.usedNames.foreach{
86
- case (rawClassName, usedNames) =>
87
- val className = rawClassName
88
- usedNames.defaultNames.foreach { rawUsedName =>
89
- val useName = rawUsedName.toString
90
- val useScopes =
91
- usedNames.scopedNames.get(rawUsedName) match {
92
- case None => EnumSet .of(UseScope .Default )
93
- case Some (existingScopes) =>
94
- existingScopes.add(UseScope .Default )
95
- existingScopes
96
- }
97
-
98
- ctx.sbtCallback.usedName(className, useName, useScopes)
85
+ extractDeps.usedNames.foreach {
86
+ case (clazz, usedNames) =>
87
+ val className = clazz
88
+ usedNames.names.foreach {
89
+ case (usedName, scopes) =>
90
+ ctx.sbtCallback.usedName(className, usedName.toString, scopes)
99
91
}
100
92
}
101
93
@@ -184,29 +176,25 @@ object ExtractDependencies {
184
176
185
177
private case class ClassDependency (from : Symbol , to : Symbol , context : DependencyContext )
186
178
187
- private final class NameUsedInClass {
188
- // Default names and other scopes are separated for performance reasons
189
- val defaultNames : mutable.Set [Name ] = new mutable.HashSet [Name ]
190
- val scopedNames : mutable.Map [Name , EnumSet [UseScope ]] = new mutable.HashMap [Name , EnumSet [UseScope ]].withDefault(_ => EnumSet .noneOf(classOf [UseScope ]))
179
+ private final class UsedNamesInClass {
180
+ private val _names = new mutable.HashMap [Name , EnumSet [UseScope ]]
181
+ def names : collection.Map [Name , EnumSet [UseScope ]] = _names
182
+
183
+ def update (name : Name , scope : UseScope ): Unit = {
184
+ val scopes = _names.getOrElseUpdate(name, EnumSet .noneOf(classOf [UseScope ]))
185
+ scopes.add(scope)
186
+ }
191
187
192
- // We have to leave with commas on ends
193
188
override def toString (): String = {
194
- val builder = new StringBuilder (" : " )
195
- defaultNames.foreach { name =>
196
- builder.append(name.toString.trim)
197
- val otherScopes = scopedNames.get(name)
198
- scopedNames.get(name) match {
199
- case None =>
200
- case Some (otherScopes) =>
201
- // Pickling tests fail when this is turned in an anonymous class
202
- class Consumer extends java.util.function.Consumer [UseScope ]() {
203
- override def accept (scope : UseScope ): Unit =
204
- builder.append(scope.name()).append(" , " )
205
- }
206
- builder.append(" in [" )
207
- otherScopes.forEach(new Consumer )
208
- builder.append(" ]" )
209
- }
189
+ val builder = new StringBuilder
190
+ names.foreach { case (name, scopes) =>
191
+ builder.append(name.mangledString)
192
+ builder.append(" in [" )
193
+ scopes.forEach(new java.util.function.Consumer [UseScope ]() { // TODO: Adapt to SAM type when #2732 is fixed
194
+ override def accept (scope : UseScope ): Unit =
195
+ builder.append(scope.toString)
196
+ })
197
+ builder.append(" ]" )
210
198
builder.append(" , " )
211
199
}
212
200
builder.toString()
@@ -225,13 +213,13 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
225
213
import tpd ._
226
214
import ExtractDependencies ._
227
215
228
- private [this ] val _usedNames = new mutable.HashMap [String , NameUsedInClass ]
216
+ private [this ] val _usedNames = new mutable.HashMap [String , UsedNamesInClass ]
229
217
private [this ] val _dependencies = new mutable.HashSet [ClassDependency ]
230
218
231
219
/** The names used in this class, this does not include names which are only
232
220
* defined and not referenced.
233
221
*/
234
- def usedNames : collection.Map [String , NameUsedInClass ] = _usedNames
222
+ def usedNames : collection.Map [String , UsedNamesInClass ] = _usedNames
235
223
236
224
/** The set of class dependencies from this compilation unit.
237
225
*/
@@ -241,10 +229,8 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
241
229
val enclosingName =
242
230
if (enclosingSym == defn.RootClass ) classNameAsString(responsibleForImports)
243
231
else classNameAsString(enclosingSym)
244
- val nameUsed = _usedNames.getOrElseUpdate(enclosingName, new NameUsedInClass )
245
- nameUsed.defaultNames += name
246
- // TODO: Set correct scope
247
- nameUsed.scopedNames(name).add(UseScope .Default )
232
+ val nameUsed = _usedNames.getOrElseUpdate(enclosingName, new UsedNamesInClass )
233
+ nameUsed.update(name, UseScope .Default )
248
234
}
249
235
250
236
private def addDependency (sym : Symbol )(implicit ctx : Context ): Unit =
@@ -284,10 +270,10 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
284
270
override protected def addDependency (symbol : Symbol )(implicit ctx : Context ): Unit = {
285
271
if (! ignoreDependency(symbol) && symbol.is(Sealed )) {
286
272
val encName = nonLocalEnclosingClass(ctx.owner).fullName.stripModuleClassSuffix.toString
287
- val nameUsed = _usedNames.getOrElseUpdate(encName, new NameUsedInClass )
273
+ val nameUsed = _usedNames.getOrElseUpdate(encName, new UsedNamesInClass )
288
274
289
- nameUsed.defaultNames += symbol.name
290
- nameUsed.scopedNames (symbol.name).add( UseScope .PatMatTarget )
275
+ nameUsed.update( symbol.name, UseScope . Default )
276
+ nameUsed.update (symbol.name, UseScope .PatMatTarget )
291
277
}
292
278
}
293
279
}
0 commit comments