Package org.apache.bcel
Class Repository
- java.lang.Object
-
- org.apache.bcel.Repository
-
public abstract class Repository extends java.lang.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:
Repository,SyntheticRepository
-
-
Constructor Summary
Constructors Constructor Description Repository()Constructs a new Repository.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JavaClassaddClass(JavaClass clazz)Adds clazz to repository if there isn't an equally named class already in there.static voidclearCache()Clears the repository.static JavaClass[]getInterfaces(java.lang.String className)Gets all interfaces implemented by the class.static JavaClass[]getInterfaces(JavaClass clazz)Gets all interfaces implemented by the class.static RepositorygetRepository()Gets the currently used repository instance.static JavaClass[]getSuperClasses(java.lang.String className)Gets the list of super classes.static JavaClass[]getSuperClasses(JavaClass clazz)Gets the list of super classes.static booleanimplementationOf(java.lang.String clazz, java.lang.String inter)Tests if clazz is an implementation of interface inter.static booleanimplementationOf(java.lang.String clazz, JavaClass inter)Tests if clazz is an implementation of interface inter.static booleanimplementationOf(JavaClass clazz, java.lang.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(java.lang.String clazz, java.lang.String superclass)Tests if clazz is an instance of superclass.static booleaninstanceOf(java.lang.String clazz, JavaClass superclass)Tests if clazz is an instance of superclass.static booleaninstanceOf(JavaClass clazz, java.lang.String superclass)Tests if clazz is an instance of superclass.static booleaninstanceOf(JavaClass clazz, JavaClass superclass)Equivalent to runtime "instanceof" operator.static JavaClasslookupClass(java.lang.Class<?> clazz)Tries to find class source using the internal repository instance.static JavaClasslookupClass(java.lang.String className)Lookups class somewhere found on your CLASSPATH, or wherever the repository instance looks for it.static ClassPath.ClassFilelookupClassFile(java.lang.String className)Looks up the class file.static voidremoveClass(java.lang.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 Detail
-
Repository
public Repository()
Constructs a new Repository.
-
-
Method Detail
-
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 java.lang.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:
java.lang.ClassNotFoundException- Thrown if any of the class's superclasses or superinterfaces can't be found.
-
getInterfaces
public static JavaClass[] getInterfaces(java.lang.String className) throws java.lang.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:
java.lang.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
public static JavaClass[] getSuperClasses(JavaClass clazz) throws java.lang.ClassNotFoundException
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:
java.lang.ClassNotFoundException- Thrown if any of the superclasses can't be found.
-
getSuperClasses
public static JavaClass[] getSuperClasses(java.lang.String className) throws java.lang.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:
java.lang.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 java.lang.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:
java.lang.ClassNotFoundException- Thrown if any superclasses or superinterfaces of clazz can't be found.
-
implementationOf
public static boolean implementationOf(JavaClass clazz, java.lang.String inter) throws java.lang.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:
java.lang.ClassNotFoundException- Thrown if inter or any superclasses or superinterfaces of clazz can't be found.
-
implementationOf
public static boolean implementationOf(java.lang.String clazz, JavaClass inter) throws java.lang.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:
java.lang.ClassNotFoundException- Thrown if clazz or any superclasses or superinterfaces of clazz can't be found.
-
implementationOf
public static boolean implementationOf(java.lang.String clazz, java.lang.String inter) throws java.lang.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:
java.lang.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 java.lang.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:
java.lang.ClassNotFoundException- Thrown if any superclasses or superinterfaces of clazz can't be found.
-
instanceOf
public static boolean instanceOf(JavaClass clazz, java.lang.String superclass) throws java.lang.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:
java.lang.ClassNotFoundException- Thrown if superclass can't be found.
-
instanceOf
public static boolean instanceOf(java.lang.String clazz, JavaClass superclass) throws java.lang.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:
java.lang.ClassNotFoundException- Thrown if clazz can't be found.
-
instanceOf
public static boolean instanceOf(java.lang.String clazz, java.lang.String superclass) throws java.lang.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:
java.lang.ClassNotFoundException- Thrown if either clazz or superclass can't be found.
-
lookupClass
public static JavaClass lookupClass(java.lang.Class<?> clazz) throws java.lang.ClassNotFoundException
Tries to find class source using the internal repository instance.- Parameters:
clazz- The class.- Returns:
- JavaClass object for given runtime class.
- Throws:
java.lang.ClassNotFoundException- Thrown if the class could not be found or parsed correctly.- See Also:
Class
-
lookupClass
public static JavaClass lookupClass(java.lang.String className) throws java.lang.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:
java.lang.ClassNotFoundException- Thrown if the class could not be found or parsed correctly.
-
lookupClassFile
public static ClassPath.ClassFile lookupClassFile(java.lang.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(java.lang.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.
-
-