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 TypeMethodDescriptionvoidcreateField(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.intGet the modifiers associated with the class.getName()Get the source file associated with this code class.booleanisArray()Discover if the class is an array type.booleanGet the deprecation flag.booleanDiscover 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 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:
getInterfacesin interfaceCodeClass
-
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
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
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
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
Description copied from interface:CodeClassGet all fields accessible through this class. -
getSuperClass
- Specified by:
getSuperClassin interfaceCodeClass
-
getFieldByName
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
-
getName
-
getJName
-
getModifiers
public int getModifiers()Description copied from interface:CodeClassGet the modifiers associated with the class.- Specified by:
getModifiersin interfaceCodeClass- Returns:
- the modifier integer
-
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
- Throws:
CodeException
-
setCodeGenerator
- Throws:
CodeException
-
createCode
- 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
-
isArray
public boolean isArray()Description copied from interface:CodeClassDiscover if the class is an array type.
-