Class GeneratedCodeClass
- All Implemented Interfaces:
CodeClass
When creating classes, instantiate one of these, add fields and methods. Associate CodeGenerator instances with methods. Then, use GeneratedClassLoader to make a new class.
- Author:
- Matthew Pocock
-
Constructor Summary
ConstructorsConstructorDescriptionGeneratedCodeClass
(String name, Class superClass, Class[] interfaces, int modifiers) GeneratedCodeClass
(String name, CodeClass superClass, CodeClass[] interfaces, int modifiers) -
Method Summary
Modifier and TypeMethodDescriptionvoid
createField
(String name, CodeClass clazz, int mods) createMethod
(String name, CodeClass type, CodeClass[] args, int mods) Create a new method.createMethod
(String name, CodeClass type, CodeClass[] args, String[] argNames, int mods) Create a new method.getConstructor
(CodeClass[] args) Get a constructor by argument list.getFieldByName
(String name) Get a field by its name.Get all fields accessible through this class.getJName()
Get a method by name and argument list.Get all methods declared by this class and its super classes, removing all super class methods that are over ridden.getMethodsByName
(String name) Get the name of all methods that could be invoked through this class with a given name.int
Get the modifiers associated with the class.getName()
Get the source file associated with this code class.boolean
isArray()
Discover if the class is an array type.boolean
Get the deprecation flag.boolean
Discover if the class represents a primitive type.void
setCodeGenerator
(CodeMethod method, CodeGenerator cg) void
setDeprecated
(boolean deprecated) Set the deprecation flag.void
setSourceFile
(String sourceFile) Set the source file associated with this code class.
-
Constructor Details
-
GeneratedCodeClass
public GeneratedCodeClass(String name, Class superClass, Class[] interfaces, int modifiers) throws CodeException - Throws:
CodeException
-
GeneratedCodeClass
public GeneratedCodeClass(String name, CodeClass superClass, CodeClass[] interfaces, int modifiers) throws CodeException - Throws:
CodeException
-
-
Method Details
-
setSourceFile
Set the source file associated with this code class.The source file appears in debugging output and stack traces. Use this method to set the source file that this generated class will clame to be from. You can use non-file names e.g. uri:myGenerator:proxy/foo
To un-set the source file, use null.
- Parameters:
sourceFile
- the source file for this class
-
getSourceFile
Get the source file associated with this code class.Null indicates that no source file is set.
- Returns:
- the source file for this code class
-
setDeprecated
public void setDeprecated(boolean deprecated) Set the deprecation flag.If deprecated is true, the class will be flagged as deprecated.
- Parameters:
deprecated
- the new value of the deprecation
-
isDeprecated
public boolean isDeprecated()Get the deprecation flag.- Returns:
- wether or not this class is deprecated
-
getInterfaces
- Specified by:
getInterfaces
in interfaceCodeClass
-
getMethods
Description copied from interface:CodeClass
Get all methods declared by this class and its super classes, removing all super class methods that are over ridden.This should return methods, regardless of their accessability.
- Specified by:
getMethods
in interfaceCodeClass
- Returns:
- a Set containing all methods
-
getMethodsByName
Description copied from interface:CodeClass
Get the name of all methods that could be invoked through this class with a given name.- Specified by:
getMethodsByName
in interfaceCodeClass
- Parameters:
name
- the name of the method- Returns:
- a Set of CodeMethod instances with that name
-
getConstructor
Description copied from interface:CodeClass
Get a constructor by argument list.- Specified by:
getConstructor
in interfaceCodeClass
- Parameters:
args
- the arguments it takes- Returns:
- a matching constructor
- Throws:
NoSuchMethodException
- if there is no matching constructor
-
getMethod
Description copied from interface:CodeClass
Get a method by name and argument list.- Specified by:
getMethod
in interfaceCodeClass
- Parameters:
name
- the name of the methodargs
- the arguments it takes- Returns:
- a matching method
- Throws:
NoSuchMethodException
- if there is no maching method
-
getFields
Description copied from interface:CodeClass
Get all fields accessible through this class. -
getSuperClass
- Specified by:
getSuperClass
in interfaceCodeClass
-
getFieldByName
Description copied from interface:CodeClass
Get a field by its name.- Specified by:
getFieldByName
in interfaceCodeClass
- Parameters:
name
- the field name- Returns:
- a CodeField representing the field
- Throws:
NoSuchFieldException
- if there is no field by that name accessible through this class
-
getName
-
getJName
-
getModifiers
public int getModifiers()Description copied from interface:CodeClass
Get the modifiers associated with the class.- Specified by:
getModifiers
in interfaceCodeClass
- Returns:
- the modifier integer
-
getDescriptor
- Specified by:
getDescriptor
in interfaceCodeClass
-
createMethod
public GeneratedCodeMethod createMethod(String name, CodeClass type, CodeClass[] args, String[] argNames, int mods) throws CodeException Create a new method.This defines the shape of a method that will be generated. Use
setCodeGenerator(org.biojava.utils.bytecode.CodeMethod, org.biojava.utils.bytecode.CodeGenerator)
to associate code with the method.The argNames will become the names of local variables for each argument.
- Parameters:
name
- the method nametype
- the return typeargs
- arguments takenargNames
- names of the argumentsmods
- access modifiers- Returns:
- a new GeneratedCodeMethod
- Throws:
CodeException
- if the method could not be created
-
createMethod
public GeneratedCodeMethod createMethod(String name, CodeClass type, CodeClass[] args, int mods) throws CodeException Create a new method.This defines the shape of a method that will be generated. Use
setCodeGenerator(org.biojava.utils.bytecode.CodeMethod, org.biojava.utils.bytecode.CodeGenerator)
to associate code with the method.- Parameters:
name
- the method nametype
- the return typeargs
- arguments takenmods
- access modifiers- Returns:
- a new GeneratedCodeMethod
- Throws:
CodeException
- if the method could not be created
-
createField
- Throws:
CodeException
-
setCodeGenerator
- Throws:
CodeException
-
createCode
- Throws:
IOException
CodeException
-
isPrimitive
public boolean isPrimitive()Description copied from interface:CodeClass
Discover if the class represents a primitive type.- Specified by:
isPrimitive
in interfaceCodeClass
- Returns:
- true if the class represents a primative type
-
isArray
public boolean isArray()Description copied from interface:CodeClass
Discover if the class is an array type.
-