Class GeneratedCodeClass
- java.lang.Object
-
- org.biojava.utils.bytecode.GeneratedCodeClass
-
- All Implemented Interfaces:
CodeClass
public class GeneratedCodeClass extends Object implements CodeClass
A CodeClass implementation that is used to generate new classes.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
Constructors Constructor Description GeneratedCodeClass(String name, Class superClass, Class[] interfaces, int modifiers)GeneratedCodeClass(String name, CodeClass superClass, CodeClass[] interfaces, int modifiers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateCode(OutputStream os)CodeFieldcreateField(String name, CodeClass clazz, int mods)GeneratedCodeMethodcreateMethod(String name, CodeClass type, CodeClass[] args, int mods)Create a new method.GeneratedCodeMethodcreateMethod(String name, CodeClass type, CodeClass[] args, String[] argNames, int mods)Create a new method.CodeMethodgetConstructor(CodeClass[] args)Get a constructor by argument list.StringgetDescriptor()CodeFieldgetFieldByName(String name)Get a field by its name.SetgetFields()Get all fields accessible through this class.ListgetInterfaces()StringgetJName()CodeMethodgetMethod(String name, CodeClass[] args)Get a method by name and argument list.SetgetMethods()Get all methods declared by this class and its super classes, removing all super class methods that are over ridden.SetgetMethodsByName(String name)Get the name of all methods that could be invoked through this class with a given name.intgetModifiers()Get the modifiers associated with the class.StringgetName()StringgetSourceFile()Get the source file associated with this code class.CodeClassgetSuperClass()booleanisArray()Discover if the class is an array type.booleanisDeprecated()Get the deprecation flag.booleanisPrimitive()Discover if the class represents a primitive type.voidsetCodeGenerator(CodeMethod method, CodeGenerator cg)voidsetDeprecated(boolean deprecated)Set the deprecation flag.voidsetSourceFile(String sourceFile)Set the source file associated with this code class.
-
-
-
Constructor Detail
-
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 Detail
-
setSourceFile
public void setSourceFile(String sourceFile)
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
public String 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
public List getInterfaces()
- Specified by:
getInterfacesin interfaceCodeClass
-
getMethods
public Set getMethods()
Description copied from interface:CodeClassGet 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:
getMethodsin interfaceCodeClass- Returns:
- a Set containing all methods
-
getMethodsByName
public Set getMethodsByName(String name)
Description copied from interface:CodeClassGet the name of all methods that could be invoked through this class with a given name.- Specified by:
getMethodsByNamein interfaceCodeClass- Parameters:
name- the name of the method- Returns:
- a Set of CodeMethod instances with that name
-
getConstructor
public CodeMethod getConstructor(CodeClass[] args) throws NoSuchMethodException
Description copied from interface:CodeClassGet a constructor by argument list.- Specified by:
getConstructorin interfaceCodeClass- Parameters:
args- the arguments it takes- Returns:
- a matching constructor
- Throws:
NoSuchMethodException- if there is no matching constructor
-
getMethod
public CodeMethod getMethod(String name, CodeClass[] args) throws NoSuchMethodException
Description copied from interface:CodeClassGet a method by name and argument list.- Specified by:
getMethodin 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
public Set getFields()
Description copied from interface:CodeClassGet all fields accessible through this class.
-
getSuperClass
public CodeClass getSuperClass()
- Specified by:
getSuperClassin interfaceCodeClass
-
getFieldByName
public CodeField getFieldByName(String name) throws NoSuchFieldException
Description copied from interface:CodeClassGet a field by its name.- Specified by:
getFieldByNamein 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
-
getModifiers
public int getModifiers()
Description copied from interface:CodeClassGet the modifiers associated with the class.- Specified by:
getModifiersin interfaceCodeClass- Returns:
- the modifier integer
-
getDescriptor
public String getDescriptor()
- Specified by:
getDescriptorin 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
public CodeField createField(String name, CodeClass clazz, int mods) throws CodeException
- Throws:
CodeException
-
setCodeGenerator
public void setCodeGenerator(CodeMethod method, CodeGenerator cg) throws CodeException
- Throws:
CodeException
-
createCode
public void createCode(OutputStream os) throws IOException, CodeException
- Throws:
IOExceptionCodeException
-
isPrimitive
public boolean isPrimitive()
Description copied from interface:CodeClassDiscover if the class represents a primitive type.- Specified by:
isPrimitivein interfaceCodeClass- Returns:
- true if the class represents a primative type
-
-