Skip to content

Commit

Permalink
Compute moduleClass of responsibleOfImports once
Browse files Browse the repository at this point in the history
Addresses feedback from @romanowski on not repeating this computation
every time a top level import is processed by `Dependency`.
  • Loading branch information
jvican committed Feb 17, 2017
1 parent 3f09fd5 commit dbba375
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
}

private class DependencyProcessor(unit: CompilationUnit) {
private def firstClassOrModuleDef(tree: Tree): Option[Tree] = {
private def firstClassOrModuleClass(tree: Tree): Option[Symbol] = {
tree foreach {
case t @ ((_: ClassDef) | (_: ModuleDef)) => return Some(t)
case _ => ()
case classOrModule @ ((_: ClassDef) | (_: ModuleDef)) =>
val sym = classOrModule.symbol
return Some(if (sym.isModule) sym.moduleClass else sym)
case _ => ()
}
None
}

private val sourceFile = unit.source.file.file
private val responsibleOfImports = firstClassOrModuleDef(unit.body)
private val responsibleOfImports = firstClassOrModuleClass(unit.body)
private var orphanImportsReported = false

/*
Expand All @@ -81,9 +83,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
if (!orphanImportsReported) {
responsibleOfImports match {
case Some(classOrModuleDef) =>
val sym = classOrModuleDef.symbol
val firstClassSymbol = if (sym.isModule) sym.moduleClass else sym
memberRef(ClassDependency(firstClassSymbol, dep))
memberRef(ClassDependency(classOrModuleDef, dep))
case None =>
reporter.warning(unit.position(0), Feedback.OrphanTopLevelImports)
orphanImportsReported = true
Expand Down

0 comments on commit dbba375

Please sign in to comment.