mirror of https://github.com/sbt/sbt.git
Factor out class file lookup out of Analyzer class.
Move logic related to class file lookup to separate class that can be reused outside of Analyzer class.
This commit is contained in:
parent
aec466cb4d
commit
7d4cf7b8ab
|
|
@ -6,7 +6,6 @@ package xsbt
|
|||
import scala.tools.nsc.{io, plugins, symtab, Global, Phase}
|
||||
import io.{AbstractFile, PlainFile, ZipArchive}
|
||||
import plugins.{Plugin, PluginComponent}
|
||||
import symtab.Flags
|
||||
import scala.collection.mutable.{HashMap, HashSet, Map, Set}
|
||||
|
||||
import java.io.File
|
||||
|
|
@ -17,7 +16,7 @@ object Analyzer
|
|||
{
|
||||
def name = "xsbt-analyzer"
|
||||
}
|
||||
final class Analyzer(val global: CallbackGlobal) extends Compat
|
||||
final class Analyzer(val global: CallbackGlobal) extends LocateClassFile
|
||||
{
|
||||
import global._
|
||||
|
||||
|
|
@ -81,37 +80,5 @@ final class Analyzer(val global: CallbackGlobal) extends Compat
|
|||
}
|
||||
}
|
||||
|
||||
private[this] final val classSeparator = '.'
|
||||
private[this] def classFile(sym: Symbol): Option[(AbstractFile, String, Boolean)] =
|
||||
// package can never have a corresponding class file; this test does not
|
||||
// catch package objects (that do not have this flag set)
|
||||
if (sym hasFlag scala.tools.nsc.symtab.Flags.PACKAGE) None else
|
||||
{
|
||||
import scala.tools.nsc.symtab.Flags
|
||||
val name = flatname(sym, classSeparator) + moduleSuffix(sym)
|
||||
findClass(name).map { case (file,inOut) => (file, name,inOut) } orElse {
|
||||
if(isTopLevelModule(sym))
|
||||
{
|
||||
val linked = sym.companionClass
|
||||
if(linked == NoSymbol)
|
||||
None
|
||||
else
|
||||
classFile(linked)
|
||||
}
|
||||
else
|
||||
None
|
||||
}
|
||||
}
|
||||
private def flatname(s: Symbol, separator: Char) =
|
||||
atPhase(currentRun.flattenPhase.next) { s fullName separator }
|
||||
|
||||
private def isTopLevelModule(sym: Symbol): Boolean =
|
||||
atPhase (currentRun.picklerPhase.next) {
|
||||
sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass
|
||||
}
|
||||
private def className(s: Symbol, sep: Char, dollarRequired: Boolean): String =
|
||||
flatname(s, sep) + (if(dollarRequired) "$" else "")
|
||||
private def fileForClass(outputDirectory: File, s: Symbol, separatorRequired: Boolean): File =
|
||||
new File(outputDirectory, className(s, File.separatorChar, separatorRequired) + ".class")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2008, 2009 Mark Harrah
|
||||
*/
|
||||
package xsbt
|
||||
|
||||
import scala.tools.nsc.symtab.Flags
|
||||
import scala.tools.nsc.io.AbstractFile
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Contains utility methods for looking up class files corresponding to Symbols.
|
||||
*/
|
||||
abstract class LocateClassFile extends Compat
|
||||
{
|
||||
val global: CallbackGlobal
|
||||
import global._
|
||||
|
||||
private[this] final val classSeparator = '.'
|
||||
protected def classFile(sym: Symbol): Option[(AbstractFile, String, Boolean)] =
|
||||
// package can never have a corresponding class file; this test does not
|
||||
// catch package objects (that do not have this flag set)
|
||||
if (sym hasFlag scala.tools.nsc.symtab.Flags.PACKAGE) None else
|
||||
{
|
||||
import scala.tools.nsc.symtab.Flags
|
||||
val name = flatname(sym, classSeparator) + moduleSuffix(sym)
|
||||
findClass(name).map { case (file,inOut) => (file, name,inOut) } orElse {
|
||||
if(isTopLevelModule(sym))
|
||||
{
|
||||
val linked = sym.companionClass
|
||||
if(linked == NoSymbol)
|
||||
None
|
||||
else
|
||||
classFile(linked)
|
||||
}
|
||||
else
|
||||
None
|
||||
}
|
||||
}
|
||||
private def flatname(s: Symbol, separator: Char) =
|
||||
atPhase(currentRun.flattenPhase.next) { s fullName separator }
|
||||
|
||||
protected def isTopLevelModule(sym: Symbol): Boolean =
|
||||
atPhase (currentRun.picklerPhase.next) {
|
||||
sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass
|
||||
}
|
||||
protected def className(s: Symbol, sep: Char, dollarRequired: Boolean): String =
|
||||
flatname(s, sep) + (if(dollarRequired) "$" else "")
|
||||
protected def fileForClass(outputDirectory: File, s: Symbol, separatorRequired: Boolean): File =
|
||||
new File(outputDirectory, className(s, File.separatorChar, separatorRequired) + ".class")
|
||||
}
|
||||
Loading…
Reference in New Issue