Package serp.bytecode
Class Project
java.lang.Object
serp.bytecode.Project
- All Implemented Interfaces:
VisitAcceptor
The Project represents a working set of classes. It caches parsed
bytecode and is responsible for bytecode class creation. Currently
changes made in one class are not reflected in other
classes, though this will be an option in the future.
Bytecode that has been parsed is held in a cache so that retrieving
a class with the same name multiple times always returns the same
BCClass
instance.
A future goal is to eventually have facilities for traversing jars or directory structures to find classes that meet a given criteria (such as implementing a given interface, etc) and to perform operations on entire projects, similar to aspect-oriented programming.
- Author:
- Abe White
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptVisit
(BCVisitor visit) Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.void
clear()
Clears all classes from this project.boolean
containsClass
(Class type) Return true if the project already contains the given class.boolean
containsClass
(String type) Return true if the project already contains the given class.boolean
containsClass
(BCClass type) Return true if the project already contains the given class.BCClass[]
Return all loaded classes in the project.getName()
Return the project name, or null if unset.Return the name cache, which includes utilities for converting names from internal to external form and vice versa.Load the bytecode from the given class file.loadClass
(File classFile, ClassLoader loader) Load the bytecode from the given class file.loadClass
(InputStream in) Load the bytecode from the given stream.loadClass
(InputStream in, ClassLoader loader) Load the bytecode from the given stream.Load the bytecode for the given class.Load a class with the given name.loadClass
(String name, ClassLoader loader) Load the bytecode for the class with the given name.Import the given bytecode from another project.boolean
removeClass
(Class type) Remove a class from this project.boolean
removeClass
(String type) Remove a class from this project.boolean
removeClass
(BCClass type) Remove a class from this project.
-
Constructor Details
-
Project
public Project()Default constructor. -
Project
Construct a named project.
-
-
Method Details
-
getName
Return the project name, or null if unset. -
getNameCache
Return the name cache, which includes utilities for converting names from internal to external form and vice versa. -
loadClass
Load a class with the given name.- See Also:
-
loadClass
Load the bytecode for the class with the given name. If aBCClass
with the given name already exists in this project, it will be returned. Otherwise, a newBCClass
will be created with the given name and returned. If the name represents an existing type, the returned instance will contain the parsed bytecode for that type. If the name is of a primitive or array type, the returned instance will act accordingly.- Parameters:
name
- the name of the class, including packageloader
- the class loader to use to search for an existing class with the given name; if null defaults to the context loader of the current thread- Throws:
RuntimeException
- on parse error
-
loadClass
Load the bytecode for the given class. If aBCClass
with the name of the given class already exists in this project, it will be returned. Otherwise, the bytecode of the given class will be parsed and returned as a newBCClass
. If the given class is an array or primitive type, the returned instance will act accordingly.- Parameters:
type
- the class to parse- Throws:
RuntimeException
- on parse error
-
loadClass
Load the bytecode from the given class file. If this project already contains the class in the given file, it will be returned. Otherwise a newBCClass
will be created from the given bytecode.- Throws:
RuntimeException
- on parse error
-
loadClass
Load the bytecode from the given class file. If this project already contains the class in the given file, it will be returned. Otherwise a newBCClass
will be created from the given bytecode.- Throws:
RuntimeException
- on parse error
-
loadClass
Load the bytecode from the given stream. If this project already contains the class in the given stream, it will be returned. Otherwise a newBCClass
will be created from the given bytecode.- Throws:
RuntimeException
- on parse error
-
loadClass
Load the bytecode from the given stream. If this project already contains the class in the given stream, it will be returned. Otherwise a newBCClass
will be created from the given bytecode.- Throws:
RuntimeException
- on parse error
-
loadClass
-
clear
public void clear()Clears all classes from this project. -
removeClass
Remove a class from this project. After removal, the result of any further operations on the class is undefined.- Returns:
- true if the class belonged to this project, false otherwise
-
removeClass
Remove a class from this project. After removal, the result of any further operations on the class is undefined.- Returns:
- true if the class belonged to this project, false otherwise
-
removeClass
Remove a class from this project. After removal, the result of any further operations on the class is undefined.- Returns:
- true if the class belonged to this project, false otherwise
-
getClasses
Return all loaded classes in the project. -
containsClass
Return true if the project already contains the given class. -
containsClass
Return true if the project already contains the given class. -
containsClass
Return true if the project already contains the given class. -
acceptVisit
Description copied from interface:VisitAcceptor
Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.- Specified by:
acceptVisit
in interfaceVisitAcceptor
-