Packages

o

fm.common

ClassUtil

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
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ClassUtil
  2. Logging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def canCreateInstanceOf(cls: Class[_]): Boolean

    Can an instance of this class be created using a zero-args constructor?

  6. def canCreateInstanceOfOrIsObject(cls: Class[_]): Boolean

    Can an instance of this class be created using a zero-args constructor?

  7. def classExists(cls: String, classLoader: ClassLoader): Boolean

    Check if a class exists.

  8. def classExists(cls: String): Boolean

    Check if a class exists.

  9. def classForName(cls: String, classLoader: ClassLoader): Class[_]
  10. def classForName(cls: String): Class[_]
  11. def classpathContentLength(file: File, classLoader: ClassLoader): Long

    Lookup the legnth for a resource on the classpath

  12. def classpathContentLength(file: File): Long

    Lookup the legnth for a resource on the classpath

  13. def classpathContentLength(file: String, classLoader: ClassLoader): Long

    Lookup the legnth for a resource on the classpath

  14. def classpathContentLength(file: String): Long

    Lookup the legnth for a resource on the classpath

  15. def classpathDirExists(file: File, classLoader: ClassLoader): Boolean

    Check if a directory exists on the classpath

  16. def classpathDirExists(file: File): Boolean

    Check if a directory exists on the classpath

  17. def classpathDirExists(file: String, classLoader: ClassLoader): Boolean

    Check if a directory exists on the classpath

  18. def classpathDirExists(file: String): Boolean

    Check if a directory exists on the classpath

  19. def classpathFileExists(file: File, classLoader: ClassLoader): Boolean

    Check if a file exists on the classpath

  20. def classpathFileExists(file: File): Boolean

    Check if a file exists on the classpath

  21. def classpathFileExists(file: String, classLoader: ClassLoader): Boolean

    Check if a file exists on the classpath

  22. def classpathFileExists(file: String): Boolean

    Check if a file exists on the classpath

  23. def classpathLastModified(file: File, classLoader: ClassLoader): Long

    Lookup the lastModified timestamp for a resource on the classpath

  24. def classpathLastModified(file: File): Long

    Lookup the lastModified timestamp for a resource on the classpath

  25. def classpathLastModified(file: String, classLoader: ClassLoader): Long

    Lookup the lastModified timestamp for a resource on the classpath

  26. def classpathLastModified(file: String): Long

    Lookup the lastModified timestamp for a resource on the classpath

  27. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  28. def companionObject(cls: Class[_]): AnyRef
  29. def companionObjectAs[T <: AnyRef](cls: Class[_], asCls: Class[T]): T
  30. def companionObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): T
  31. def companionObjectClass(cls: Class[_]): Class[_]

    Lookup the companion object class for a class

  32. def companionObjectClass(cls: String, classLoader: ClassLoader): Class[_]

    Lookup the companion object class for a class

  33. def companionObjectClass(cls: String): Class[_]

    Lookup the companion object class for a class

  34. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  35. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  36. 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!

  37. 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!

  38. def findClassNames(basePackage: String, classLoader: ClassLoader): Set[String]

    Find all class names under the base package (includes anonymous/inner/objects etc...)

  39. def findClassNames(basePackage: String): Set[String]

    Find all class names under the base package (includes anonymous/inner/objects etc...)

  40. def findClasspathFiles(basePackage: String, classLoader: ClassLoader): Set[File]

    Recursively Find files on the classpath given a base package.

  41. def findClasspathFiles(basePackage: String): Set[File]

    Recursively Find files on the classpath given a base package.

  42. 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.

  43. 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.

  44. 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.

  45. 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.

  46. def findLoadedClass(cls: String, classLoader: ClassLoader): Option[Class[_]]
  47. def findLoadedClass(cls: String): Option[Class[_]]
  48. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  49. def getClassForName(cls: String, classLoader: ClassLoader): Option[Class[_]]
  50. def getClassForName(cls: String): Option[Class[_]]
  51. def getCompanionObject(cls: Class[_]): Option[AnyRef]
  52. def getCompanionObjectAs[T <: AnyRef](cls: Class[_], asCls: Class[T]): Option[T]
  53. def getCompanionObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): Option[T]
  54. def getCompanionObjectClass(cls: Class[_]): Option[Class[_]]
  55. def getCompanionObjectClass(cls: String, classLoader: ClassLoader): Option[Class[_]]

    Lookup the companion object class for a class

  56. def getCompanionObjectClass(cls: String): Option[Class[_]]

    Lookup the companion object class for a class

  57. 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

  58. 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

  59. def getNewInstanceOrObjectAs[T <: AnyRef](cls: Class[_])(implicit arg0: ClassTag[T]): Option[T]
  60. def getScalaObject(objectCls: Class[_]): Option[AnyRef]

    Returns the Scala object instance for this class (if it is the class of a Scala object)

  61. 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)

  62. 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)

  63. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  64. def isClassLoaded(cls: String, classLoader: ClassLoader): Boolean

    Check if a class is loaded

  65. def isClassLoaded(cls: String): Boolean

    Check if a class is loaded

  66. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  67. def isScalaObject(cls: Class[_]): Boolean

    Is this the class for a Scala Object?

  68. 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)

  69. 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)

  70. def listClasspathFiles(basePackage: String, classLoader: ClassLoader): Set[File]

    Similar to File.listFiles() (i.e.

    Similar to File.listFiles() (i.e. a non-recursive findClassPathFiles)

  71. def listClasspathFiles(basePackage: String): Set[File]

    Similar to File.listFiles() (i.e.

    Similar to File.listFiles() (i.e. a non-recursive findClassPathFiles)

  72. lazy val logger: Logger
    Attributes
    protected
    Definition Classes
    Logging
    Annotations
    @transient()
  73. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  74. 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

  75. 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

  76. 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

  77. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  78. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  79. 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.

  80. 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.

  81. def scalaObject(objectCls: Class[_]): AnyRef

    Returns the Scala object instance for this class

  82. def scalaObjectAs[T <: AnyRef](objectCls: Class[_], asCls: Class[T]): T

    Returns the Scala object instance for this class

  83. def scalaObjectAs[T <: AnyRef](objectCls: Class[_])(implicit arg0: ClassTag[T]): T

    Returns the Scala object instance for this class

  84. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  85. def toString(): String
    Definition Classes
    AnyRef → Any
  86. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  87. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  88. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from Logging

Inherited from AnyRef

Inherited from Any

Ungrouped