aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/util/ClassUtils.scala
blob: 095e875cd040fc528c39d6a65e87ae5c7cc2574a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// SPDX-License-Identifier: Apache-2.0

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
  }
}