sbt.internal.inc.ModuleUtilities.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zinc-classpath_2.11 Show documentation
Show all versions of zinc-classpath_2.11 Show documentation
Incremental compiler of Scala
The newest version!
/* sbt -- Simple Build Tool
* Copyright 2008 Mark Harrah
*/
package sbt
package internal
package inc
object ModuleUtilities {
/**
* Reflectively loads and returns the companion object for top-level class `className` from `loader`.
* The class name should not include the `$` that scalac appends to the underlying jvm class for
* a companion object.
*/
def getObject(className: String, loader: ClassLoader): AnyRef =
{
val obj = Class.forName(className + "$", true, loader)
val singletonField = obj.getField("MODULE$")
singletonField.get(null)
}
def getCheckedObject[T](className: String, loader: ClassLoader)(implicit mf: reflect.ClassTag[T]): T =
mf.runtimeClass.cast(getObject(className, loader)).asInstanceOf[T]
def getCheckedObjects[T](classNames: Seq[String], loader: ClassLoader)(implicit mf: reflect.ClassTag[T]): Seq[(String, T)] =
classNames.map(name => (name, getCheckedObject(name, loader)))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy