@@ -151,10 +151,6 @@ class ExtractDependencies extends Phase {
151
151
object ExtractDependencies {
152
152
def classNameAsString (sym : Symbol )(implicit ctx : Context ): String =
153
153
sym.fullName.stripModuleClassSuffix.toString
154
-
155
- /** Return the enclosing class or the module class if it's a module. */
156
- def enclOrModuleClass (dep : Symbol )(implicit ctx : Context ): Symbol =
157
- if (dep.is(ModuleVal )) dep.moduleClass else dep.enclosingClass
158
154
}
159
155
160
156
private case class ClassDependency (from : Symbol , to : Symbol , context : DependencyContext )
@@ -230,7 +226,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
230
226
if (_responsibleForImports == null ) {
231
227
val tree = ctx.compilationUnit.tpdTree
232
228
_responsibleForImports = firstClassOrModule(tree)
233
- if (_responsibleForImports == NoSymbol )
229
+ if (! _responsibleForImports.exists )
234
230
ctx.warning(""" |No class, trait or object is defined in the compilation unit.
235
231
|The incremental compiler cannot record the dependency information in such case.
236
232
|Some errors like unused import referring to a non-existent class might not be reported.
@@ -274,24 +270,32 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
274
270
275
271
private def addUsedName (name : Name , scope : UseScope )(implicit ctx : Context ): Unit = {
276
272
val fromClass = resolveDependencySource
277
- if (fromClass ne NoSymbol ) {
273
+ if (fromClass.exists ) {
278
274
assert(fromClass.isClass)
279
275
addUsedName(fromClass, name, scope)
280
276
}
281
277
}
282
278
279
+ /** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */
280
+ private def mangledName (sym : Symbol )(implicit ctx : Context ): Name = {
281
+ def constructorName = sym.enclosingClass.fullName ++ " ;init;"
282
+
283
+ if (sym.isConstructor) constructorName
284
+ else sym.name.stripModuleClassSuffix
285
+ }
286
+
283
287
private def addMemberRefDependency (sym : Symbol )(implicit ctx : Context ): Unit =
284
288
if (! ignoreDependency(sym)) {
285
- val depClass = enclOrModuleClass (sym)
286
- // assert(depClass .isClass, s"$depClass, $sym, ${sym.isClass}" )
289
+ val enclOrModuleClass = if (sym.is( ModuleVal )) sym.moduleClass else sym.enclosingClass
290
+ // assert(enclOrModuleClass .isClass, s"$depClass, $sym") )
287
291
288
- if (depClass ne NoSymbol ) {
289
- assert(depClass .isClass)
292
+ if (enclOrModuleClass.exists ) {
293
+ assert(enclOrModuleClass .isClass)
290
294
val fromClass = resolveDependencySource
291
- if (fromClass ne NoSymbol ) {
295
+ if (fromClass.exists ) {
292
296
assert(fromClass.isClass)
293
- _dependencies += ClassDependency (fromClass, depClass , DependencyByMemberRef )
294
- addUsedName(fromClass, sym.name.stripModuleClassSuffix , UseScope .Default )
297
+ _dependencies += ClassDependency (fromClass, enclOrModuleClass , DependencyByMemberRef )
298
+ addUsedName(fromClass, mangledName( sym) , UseScope .Default )
295
299
}
296
300
}
297
301
}
@@ -308,7 +312,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
308
312
}
309
313
310
314
private def ignoreDependency (sym : Symbol )(implicit ctx : Context ) =
311
- sym.eq( NoSymbol ) ||
315
+ ! sym.exists ||
312
316
sym.isAnonymousFunction ||
313
317
sym.isAnonymousClass ||
314
318
sym.is(PackageClass )
@@ -424,7 +428,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
424
428
val traverser = new TypeDependencyTraverser {
425
429
def addDependency (symbol : Symbol ) =
426
430
if (! ignoreDependency(symbol) && symbol.is(Sealed )) {
427
- val usedName = symbol.name.stripModuleClassSuffix
431
+ val usedName = mangledName( symbol)
428
432
addUsedName(usedName, UseScope .PatMatTarget )
429
433
}
430
434
}
0 commit comments