Class Repository
java.lang.Object
org.apache.bcel.Repository
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JavaClassAdds clazz to repository if there isn't an equally named class already in there.static voidClears the repository.static JavaClass[]getInterfaces(String className) Gets all interfaces implemented by the class.static JavaClass[]getInterfaces(JavaClass clazz) Gets all interfaces implemented by the class.static RepositoryGets the currently used repository instance.static JavaClass[]getSuperClasses(String className) Gets the list of super classes.static JavaClass[]getSuperClasses(JavaClass clazz) Gets the list of super classes.static booleanimplementationOf(String clazz, String inter) Tests if clazz is an implementation of interface inter.static booleanimplementationOf(String clazz, JavaClass inter) Tests if clazz is an implementation of interface inter.static booleanimplementationOf(JavaClass clazz, String inter) Tests if clazz is an implementation of interface inter.static booleanimplementationOf(JavaClass clazz, JavaClass inter) Tests if clazz is an implementation of interface inter.static booleaninstanceOf(String clazz, String superclass) Tests if clazz is an instance of superclass.static booleaninstanceOf(String clazz, JavaClass superclass) Tests if clazz is an instance of superclass.static booleaninstanceOf(JavaClass clazz, String superclass) Tests if clazz is an instance of superclass.static booleaninstanceOf(JavaClass clazz, JavaClass superclass) Equivalent to runtime "instanceof" operator.static JavaClasslookupClass(Class<?> clazz) Tries to find class source using the internal repository instance.static JavaClasslookupClass(String className) Lookups class somewhere found on your CLASSPATH, or wherever the repository instance looks for it.static ClassPath.ClassFilelookupClassFile(String className) Looks up the class file.static voidremoveClass(String clazz) Removes class with given (fully qualified) name from repository.static voidremoveClass(JavaClass clazz) Removes given class from repository.static voidsetRepository(Repository rep) Sets repository instance to be used for class loading.
-
Constructor Details
-
Repository
public Repository()Constructs a new Repository.
-
-
Method Details
-
addClass
-
clearCache
Clears the repository. -
getInterfaces
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
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
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
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
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
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
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
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
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
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
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
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
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
Removes given class from repository.- Parameters:
clazz- The class to remove.
-
removeClass
Removes class with given (fully qualified) name from repository.- Parameters:
clazz- The class name to remove.
-
setRepository
Sets repository instance to be used for class loading.- Parameters:
rep- The repository instance.
-