object ClassUtil extends Logging
This contains utility methods for scanning Classes or Files on the classpath.
Originally we used the classpath scanning functionality in the Spring Framework and then later switched to the Reflections library (https://code.google.com/p/reflections/) to avoid the dependency on Spring. At some point we ran into issues with the Reflections library not properly detecting classes so I ended up writing this as a replacement.
- Source
- ClassUtil.scala
- Alphabetic
- By Inheritance
- ClassUtil
- Logging
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def canCreateInstanceOf(cls: Class[_]): Boolean
Can an instance of this class be created using a zero-args constructor?
- def canCreateInstanceOfOrIsObject(cls: Class[_]): Boolean
Can an instance of this class be created using a zero-args constructor?
- def classExists(cls: String, classLoader: ClassLoader): Boolean
Check if a class exists.
- def classExists(cls: String): Boolean
Check if a class exists.
- def classForName(cls: String, classLoader: ClassLoader): Class[_]
- def classForName(cls: String): Class[_]
- def classpathContentLength(file: File, classLoader: ClassLoader): Long
Lookup the legnth for a resource on the classpath
- def classpathContentLength(file: File): Long
Lookup the legnth for a resource on the classpath
- def classpathContentLength(file: String, classLoader: ClassLoader): Long
Lookup the legnth for a resource on the classpath
- def classpathContentLength(file: String): Long
Lookup the legnth for a resource on the classpath
- def classpathDirExists(file: File, classLoader: ClassLoader): Boolean
Check if a directory exists on the classpath
- def classpathDirExists(file: File): Boolean
Check if a directory exists on the classpath
- def classpathDirExists(file: String, classLoader: ClassLoader): Boolean
Check if a directory exists on the classpath
- def classpathDirExists(file: String): Boolean
Check if a directory exists on the classpath
- def classpathFileExists(file: File, classLoader: ClassLoader): Boolean
Check if a file exists on the classpath
- def classpathFileExists(file: File): Boolean
Check if a file exists on the classpath
- def classpathFileExists(file: String, classLoader: ClassLoader): Boolean
Check if a file exists on the classpath
- def classpathFileExists(file: String): Boolean
Check if a file exists on the classpath
- def classpathLastModified(file: File, classLoader: ClassLoader): Long
Lookup the lastModified timestamp for a resource on the classpath
- def classpathLastModified(file: File): Long
Lookup the lastModified timestamp for a resource on the classpath
- def classpathLastModified(file: String, classLoader: ClassLoader): Long
Lookup the lastModified timestamp for a resource on the classpath
- def classpathLastModified(file: String): Long
Lookup the lastModified timestamp for a resource on the classpath
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def companionObject(cls: Class[_]): AnyRef
- def companionObjectAs[T <: AnyRef](cls: Class[_], asCls: Class[T]): T
- def companionObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): T
- def companionObjectClass(cls: Class[_]): Class[_]
Lookup the companion object class for a class
- def companionObjectClass(cls: String, classLoader: ClassLoader): Class[_]
Lookup the companion object class for a class
- def companionObjectClass(cls: String): Class[_]
Lookup the companion object class for a class
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def findAnnotatedClasses[T <: Annotation](basePackage: String, annotationClass: Class[T], classLoader: ClassLoader): Set[Class[_]]
Find all classes annotated with a Java Annotation.
Find all classes annotated with a Java Annotation.
Note: This loads ALL classes under the basePackage!
- def findAnnotatedClasses[T <: Annotation](basePackage: String, annotationClass: Class[T]): Set[Class[_]]
Find all classes annotated with a Java Annotation.
Find all classes annotated with a Java Annotation.
Note: This loads ALL classes under the basePackage!
- def findClassNames(basePackage: String, classLoader: ClassLoader): Set[String]
Find all class names under the base package (includes anonymous/inner/objects etc...)
- def findClassNames(basePackage: String): Set[String]
Find all class names under the base package (includes anonymous/inner/objects etc...)
- def findClasspathFiles(basePackage: String, classLoader: ClassLoader): Set[File]
Recursively Find files on the classpath given a base package.
- def findClasspathFiles(basePackage: String): Set[File]
Recursively Find files on the classpath given a base package.
- def findImplementingClasses[T](basePackage: String, clazz: Class[T], classLoader: ClassLoader): Set[Class[_ <: T]]
Find all concrete classes that extend a trait/interface/class.
Find all concrete classes that extend a trait/interface/class.
Note: This loads ALL classes under the basePackage and uses Class.isAssignableFrom for checking.
- def findImplementingClasses[T](basePackage: String, clazz: Class[T]): Set[Class[_ <: T]]
Find all concrete classes that extend a trait/interface/class.
Find all concrete classes that extend a trait/interface/class.
Note: This loads ALL classes under the basePackage and uses Class.isAssignableFrom for checking.
- def findImplementingObjects[T <: AnyRef](basePackage: String, clazz: Class[T], classLoader: ClassLoader): Set[T]
Finds all Scala Objects that extends a trait/interface/class.
Finds all Scala Objects that extends a trait/interface/class.
Note: This loads ALL classes under the basePackage and uses Class.isAssignableFrom for checking.
- def findImplementingObjects[T <: AnyRef](basePackage: String, clazz: Class[T]): Set[T]
Finds all Scala Objects that extends a trait/interface/class.
Finds all Scala Objects that extends a trait/interface/class.
Note: This loads ALL classes under the basePackage and uses Class.isAssignableFrom for checking.
- def findLoadedClass(cls: String, classLoader: ClassLoader): Option[Class[_]]
- def findLoadedClass(cls: String): Option[Class[_]]
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def getClassForName(cls: String, classLoader: ClassLoader): Option[Class[_]]
- def getClassForName(cls: String): Option[Class[_]]
- def getCompanionObject(cls: Class[_]): Option[AnyRef]
- def getCompanionObjectAs[T <: AnyRef](cls: Class[_], asCls: Class[T]): Option[T]
- def getCompanionObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): Option[T]
- def getCompanionObjectClass(cls: Class[_]): Option[Class[_]]
- def getCompanionObjectClass(cls: String, classLoader: ClassLoader): Option[Class[_]]
Lookup the companion object class for a class
- def getCompanionObjectClass(cls: String): Option[Class[_]]
Lookup the companion object class for a class
- def getNewInstanceOrObject[T <: AnyRef](cls: Class[T]): Option[T]
Creates a new instance of a class using a 0-args constructor or returns the Scala object instance of this class
- def getNewInstanceOrObjectAs[T <: AnyRef](cls: Class[_], asCls: Class[T]): Option[T]
Creates a new instance of a class using a 0-args constructor or returns the Scala object instance of this class
Creates a new instance of a class using a 0-args constructor or returns the Scala object instance of this class
- cls
The class to create an instance of (or to get the Object instance for)
- asCls
The return type
- def getNewInstanceOrObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): Option[T]
- def getScalaObject(objectCls: Class[_]): Option[AnyRef]
Returns the Scala object instance for this class (if it is the class of a Scala object)
- def getScalaObjectAs[T <: AnyRef](objectCls: Class[_], asCls: Class[T]): Option[T]
Returns the Scala object instance for this class (if it is the class of a Scala object)
- def getScalaObjectAs[T <: AnyRef](objectCls: Class[_])(implicit arg0: ClassTag[T]): Option[T]
Returns the Scala object instance for this class (if it is the class of a Scala object)
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def isClassLoaded(cls: String, classLoader: ClassLoader): Boolean
Check if a class is loaded
- def isClassLoaded(cls: String): Boolean
Check if a class is loaded
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isScalaObject(cls: Class[_]): Boolean
Is this the class for a Scala Object?
- def isScalaObject(cls: String, classLoader: ClassLoader): Boolean
Does this class represent a Scala object
Does this class represent a Scala object
- cls
The fully qualified name of the class to check (Note: should end with a '$' character)
- def isScalaObject(cls: String): Boolean
Does this class represent a Scala object
Does this class represent a Scala object
- cls
The fully qualified name of the class to check (Note: should end with a '$' character)
- def listClasspathFiles(basePackage: String, classLoader: ClassLoader): Set[File]
Similar to File.listFiles() (i.e.
Similar to File.listFiles() (i.e. a non-recursive findClassPathFiles)
- def listClasspathFiles(basePackage: String): Set[File]
Similar to File.listFiles() (i.e.
Similar to File.listFiles() (i.e. a non-recursive findClassPathFiles)
- lazy val logger: Logger
- Attributes
- protected
- Definition Classes
- Logging
- Annotations
- @transient()
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def newInstanceOrObject[T <: AnyRef](cls: Class[T]): T
Creates a new instance of a class using a 0-args constructor or returns the Scala object instance of this class
- def newInstanceOrObjectAs[T <: AnyRef](cls: Class[_], asCls: Class[T]): T
Creates a new instance of a class using a 0-args constructor or returns the Scala object instance of this class
- def newInstanceOrObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): T
Creates a new instance of a class using a 0-args constructor or returns the Scala object instance of this class
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def requireClass(cls: String, msg: => String, classLoader: ClassLoader): Unit
Check if a class exists.
Check if a class exists. If it does not then a ClassNotFoundException is thrown.
- def requireClass(cls: String, msg: => String): Unit
Check if a class exists.
Check if a class exists. If it does not then a ClassNotFoundException is thrown.
- def scalaObject(objectCls: Class[_]): AnyRef
Returns the Scala object instance for this class
- def scalaObjectAs[T <: AnyRef](objectCls: Class[_], asCls: Class[T]): T
Returns the Scala object instance for this class
- def scalaObjectAs[T <: AnyRef](objectCls: Class[_])(implicit arg0: ClassTag[T]): T
Returns the Scala object instance for this class
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])