aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/util/ClassUtils.scala
blob: 34ff60fca1e6c65f8f5d81f5f0bc4878d165e420 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package firrtl.util

object ClassUtils {

  /** Determine if a named class is loaded.
    *
    * @param name - name of the class: "foo.bar" or "org.foo.bar"
    * @return true if the class has been loaded (is accessible), false otherwise.
    */
  def isClassLoaded(name: String): Boolean = {
    val found =
      try {
        Class.forName(name, false, getClass.getClassLoader) != null
      } catch {
        case e: ClassNotFoundException => false
        case x: Throwable              => throw x
      }
//    println(s"isClassLoaded: %s $name".format(if (found) "found" else "didn't find"))
    found
  }
}