Class Repository

java.lang.Object
org.apache.bcel.Repository

public abstract class Repository extends Object
The repository maintains informations about class interdependencies, for example, whether a class is a sub-class of another. Delegates actual class loading to SyntheticRepository with current class path by default.
See Also:
  • Constructor Details

    • Repository

      public Repository()
      Constructs a new Repository.
  • Method Details

    • addClass

      public static JavaClass addClass(JavaClass clazz)
      Adds clazz to repository if there isn't an equally named class already in there.
      Parameters:
      clazz - The class to add.
      Returns:
      old entry in repository.
    • clearCache

      public static void clearCache()
      Clears the repository.
    • getInterfaces

      public static JavaClass[] getInterfaces(JavaClass clazz) throws ClassNotFoundException
      Gets all interfaces implemented by the class.
      Parameters:
      clazz - The class.
      Returns:
      all interfaces implemented by class and its super classes and the interfaces that those interfaces extend, and so on. (Some people call this a transitive hull).
      Throws:
      ClassNotFoundException - Thrown if any of the class's superclasses or superinterfaces can't be found.
    • getInterfaces

      public static JavaClass[] getInterfaces(String className) throws ClassNotFoundException
      Gets all interfaces implemented by the class.
      Parameters:
      className - The class name.
      Returns:
      all interfaces implemented by class and its super classes and the interfaces that extend those interfaces, and so on.
      Throws:
      ClassNotFoundException - Thrown if the named class can't be found, or if any of its superclasses or superinterfaces can't be found.
    • getRepository

      public static Repository getRepository()
      Gets the currently used repository instance.
      Returns:
      currently used repository instance.
    • getSuperClasses

      Gets the list of super classes.
      Parameters:
      clazz - The class.
      Returns:
      list of super classes of clazz in ascending order, that is, Object is always the last element.
      Throws:
      ClassNotFoundException - Thrown if any of the superclasses can't be found.
    • getSuperClasses

      public static JavaClass[] getSuperClasses(String className) throws ClassNotFoundException
      Gets the list of super classes.
      Parameters:
      className - The class name.
      Returns:
      list of super classes of clazz in ascending order, that is, Object is always the last element.
      Throws:
      ClassNotFoundException - Thrown if the named class or any of its superclasses can't be found.
    • implementationOf

      public static boolean implementationOf(JavaClass clazz, JavaClass inter) throws ClassNotFoundException
      Tests if clazz is an implementation of interface inter.
      Parameters:
      clazz - The class to test.
      inter - The interface.
      Returns:
      true, if clazz is an implementation of interface inter.
      Throws:
      ClassNotFoundException - Thrown if any superclasses or superinterfaces of clazz can't be found.
    • implementationOf

      public static boolean implementationOf(JavaClass clazz, String inter) throws ClassNotFoundException
      Tests if clazz is an implementation of interface inter.
      Parameters:
      clazz - The class to test.
      inter - The interface name.
      Returns:
      true, if clazz is an implementation of interface inter.
      Throws:
      ClassNotFoundException - Thrown if inter or any superclasses or superinterfaces of clazz can't be found.
    • implementationOf

      public static boolean implementationOf(String clazz, JavaClass inter) throws ClassNotFoundException
      Tests if clazz is an implementation of interface inter.
      Parameters:
      clazz - The class name to test.
      inter - The interface.
      Returns:
      true, if clazz is an implementation of interface inter.
      Throws:
      ClassNotFoundException - Thrown if clazz or any superclasses or superinterfaces of clazz can't be found.
    • implementationOf

      public static boolean implementationOf(String clazz, String inter) throws ClassNotFoundException
      Tests if clazz is an implementation of interface inter.
      Parameters:
      clazz - The class name to test.
      inter - The interface name.
      Returns:
      true, if clazz is an implementation of interface inter.
      Throws:
      ClassNotFoundException - Thrown if clazz, inter, or any superclasses or superinterfaces of clazz can't be found.
    • instanceOf

      public static boolean instanceOf(JavaClass clazz, JavaClass superclass) throws ClassNotFoundException
      Equivalent to runtime "instanceof" operator.
      Parameters:
      clazz - The class to test.
      superclass - The superclass.
      Returns:
      true, if clazz is an instance of superclass.
      Throws:
      ClassNotFoundException - Thrown if any superclasses or superinterfaces of clazz can't be found.
    • instanceOf

      public static boolean instanceOf(JavaClass clazz, String superclass) throws ClassNotFoundException
      Tests if clazz is an instance of superclass.
      Parameters:
      clazz - The class to test.
      superclass - The superclass name.
      Returns:
      true, if clazz is an instance of superclass.
      Throws:
      ClassNotFoundException - Thrown if superclass can't be found.
    • instanceOf

      public static boolean instanceOf(String clazz, JavaClass superclass) throws ClassNotFoundException
      Tests if clazz is an instance of superclass.
      Parameters:
      clazz - The class name to test.
      superclass - The superclass.
      Returns:
      true, if clazz is an instance of superclass.
      Throws:
      ClassNotFoundException - Thrown if clazz can't be found.
    • instanceOf

      public static boolean instanceOf(String clazz, String superclass) throws ClassNotFoundException
      Tests if clazz is an instance of superclass.
      Parameters:
      clazz - The class name to test.
      superclass - The superclass name.
      Returns:
      true, if clazz is an instance of superclass.
      Throws:
      ClassNotFoundException - Thrown if either clazz or superclass can't be found.
    • lookupClass

      public static JavaClass lookupClass(Class<?> clazz) throws ClassNotFoundException
      Tries to find class source using the internal repository instance.
      Parameters:
      clazz - The class.
      Returns:
      JavaClass object for given runtime class.
      Throws:
      ClassNotFoundException - Thrown if the class could not be found or parsed correctly.
      See Also:
    • lookupClass

      public static JavaClass lookupClass(String className) throws ClassNotFoundException
      Lookups class somewhere found on your CLASSPATH, or wherever the repository instance looks for it.
      Parameters:
      className - The class name.
      Returns:
      class object for given fully qualified class name.
      Throws:
      ClassNotFoundException - Thrown if the class could not be found or parsed correctly.
    • lookupClassFile

      public static ClassPath.ClassFile lookupClassFile(String className)
      Looks up the class file.
      Parameters:
      className - The class name.
      Returns:
      class file object for given Java class by looking on the system class path; returns null if the class file can't be found.
    • removeClass

      public static void removeClass(JavaClass clazz)
      Removes given class from repository.
      Parameters:
      clazz - The class to remove.
    • removeClass

      public static void removeClass(String clazz)
      Removes class with given (fully qualified) name from repository.
      Parameters:
      clazz - The class name to remove.
    • setRepository

      public static void setRepository(Repository rep)
      Sets repository instance to be used for class loading.
      Parameters:
      rep - The repository instance.