本文整理汇总了Scala中scala.reflect.io.AbstractFile类的典型用法代码示例。如果您正苦于以下问题:Scala AbstractFile类的具体用法?Scala AbstractFile怎么用?Scala AbstractFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractFile类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: DependencyAnalyzer
//设置package包名称以及导入依赖的类
package com.kakao.cuesheet.deps
import java.net.{URL, URLClassLoader}
import com.kakao.mango.concurrent.KeyedSingletons
import com.kakao.mango.logging.Logging
import com.kakao.mango.reflect.Accessible
import scala.reflect.io.AbstractFile
class DependencyAnalyzer(loader: ClassLoader = getClass.getClassLoader) extends Logging {
val chain: List[ClassLoader] = DependencyAnalyzer.classLoaderChain(loader)
lazy val graph = {
// collect all nodes
val nodes = for (
loader <- chain;
url <- DependencyAnalyzer.components(loader)
) yield {
DependencyNode.resolve(url)
}
new DependencyGraph(nodes)
}
}
object DependencyAnalyzer extends KeyedSingletons[ClassLoader, DependencyAnalyzer] with Logging {
def components(loader: ClassLoader): Seq[URL] = {
loader match {
case _ if loader.getClass.getName.startsWith("sun.misc.Launcher$ExtClassLoader") =>
Nil // ignore extension class loader
case loader: URLClassLoader =>
loader.getURLs
case _ if loader.getClass.getName == "scala.tools.nsc.interpreter.AbstractFileClassLoader" =>
val root = Accessible.field(loader.getClass, "root")
Seq(root.get(loader).asInstanceOf[AbstractFile].toURL)
case _ if loader.getClass.getName == "scala.reflect.internal.util.AbstractFileClassLoader" =>
val root = Accessible.field(loader.getClass, "root")
Seq(root.get(loader).asInstanceOf[AbstractFile].toURL)
case _ if Seq(loader.getClass.getName).exists(c => c.startsWith("xsbt.") || c.startsWith("sbt.")) =>
Nil // ignore SBT's internal loader
case _ =>
throw new RuntimeException("Unknown ClassLoader Type: " + loader.getClass.getName)
}
}
override def newInstance(loader: ClassLoader): DependencyAnalyzer = {
new DependencyAnalyzer(loader)
}
def apply(): DependencyAnalyzer = apply(getClass.getClassLoader)
}
示例2: Locator
//设置package包名称以及导入依赖的类
package com.avsystem.scex
package compiler
import com.avsystem.scex.util.MacroUtils
import scala.collection.mutable
import scala.reflect.internal.util._
import scala.reflect.io.AbstractFile
import scala.tools.nsc.Global
import scala.tools.nsc.plugins.Plugin
class Locator(pos: Position) extends Traverser {
var last: Tree = _
def locateIn(root: Tree): Tree = {
this.last = EmptyTree
traverse(root)
this.last
}
override def traverse(t: Tree): Unit = {
t match {
case tt: TypeTree if tt.original != null && includes(tt.pos, tt.original.pos) =>
traverse(tt.original)
case _ =>
if (includes(t.pos, pos)) {
if (!t.pos.isTransparent) last = t
super.traverse(t)
} else t match {
case mdef: MemberDef =>
traverseTrees(mdef.mods.annotations)
case _ =>
}
}
}
private def includes(pos1: Position, pos2: Position) =
(pos1 includes pos2) && pos1.end > pos2.start
}
override protected def loadRoughPluginsList() =
loadAdditionalPlugins() ::: super.loadRoughPluginsList()
// toplevel symbol dropping is implemented based on how it's done in the Scala Presentation Compiler
// (which happens e.g. when a source file is deleted)
private val toplevelSymbolsMap = new mutable.WeakHashMap[AbstractFile, mutable.Set[Symbol]]
override def registerTopLevelSym(sym: Symbol): Unit = {
toplevelSymbolsMap.getOrElseUpdate(sym.sourceFile, new mutable.HashSet) += sym
}
def forgetSymbolsFromSource(file: AbstractFile) = {
val symbols = toplevelSymbolsMap.get(file).map(_.toSet).getOrElse(Set.empty)
symbols.foreach { s =>
//like in: scala.tools.nsc.interactive.Global.filesDeleted
s.owner.info.decls unlink s
}
toplevelSymbolsMap.remove(file)
}
}