public class GeneratedCodeClass extends Object implements 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.
Constructor and Description |
---|
GeneratedCodeClass(String name,
Class superClass,
Class[] interfaces,
int modifiers) |
GeneratedCodeClass(String name,
CodeClass superClass,
CodeClass[] interfaces,
int modifiers) |
Modifier and Type | Method and Description |
---|---|
void |
createCode(OutputStream os) |
CodeField |
createField(String name,
CodeClass clazz,
int mods) |
GeneratedCodeMethod |
createMethod(String name,
CodeClass type,
CodeClass[] args,
int mods)
Create a new method.
|
GeneratedCodeMethod |
createMethod(String name,
CodeClass type,
CodeClass[] args,
String[] argNames,
int mods)
Create a new method.
|
CodeMethod |
getConstructor(CodeClass[] args)
Get a constructor by argument list.
|
String |
getDescriptor() |
CodeField |
getFieldByName(String name)
Get a field by its name.
|
Set |
getFields()
Get all fields accessible through this class.
|
List |
getInterfaces() |
String |
getJName() |
CodeMethod |
getMethod(String name,
CodeClass[] args)
Get a method by name and argument list.
|
Set |
getMethods()
Get all methods declared by this class and its super classes, removing
all super class methods that are over ridden.
|
Set |
getMethodsByName(String name)
Get the name of all methods that could be invoked through this class with
a given name.
|
int |
getModifiers()
Get the modifiers associated with the class.
|
String |
getName() |
String |
getSourceFile()
Get the source file associated with this code class.
|
CodeClass |
getSuperClass() |
boolean |
isArray()
Discover if the class is an array type.
|
boolean |
isDeprecated()
Get the deprecation flag.
|
boolean |
isPrimitive()
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.
|
public GeneratedCodeClass(String name, Class superClass, Class[] interfaces, int modifiers) throws CodeException
CodeException
public GeneratedCodeClass(String name, CodeClass superClass, CodeClass[] interfaces, int modifiers) throws CodeException
CodeException
public void setSourceFile(String sourceFile)
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.
sourceFile
- the source file for this classpublic String getSourceFile()
Null indicates that no source file is set.
public void setDeprecated(boolean deprecated)
If deprecated is true, the class will be flagged as deprecated.
deprecated
- the new value of the deprecationpublic boolean isDeprecated()
public List getInterfaces()
getInterfaces
in interface CodeClass
public Set getMethods()
CodeClass
This should return methods, regardless of their accessability.
getMethods
in interface CodeClass
public Set getMethodsByName(String name)
CodeClass
getMethodsByName
in interface CodeClass
name
- the name of the methodpublic CodeMethod getConstructor(CodeClass[] args) throws NoSuchMethodException
CodeClass
getConstructor
in interface CodeClass
args
- the arguments it takesNoSuchMethodException
- if there is no matching constructorpublic CodeMethod getMethod(String name, CodeClass[] args) throws NoSuchMethodException
CodeClass
getMethod
in interface CodeClass
name
- the name of the methodargs
- the arguments it takesNoSuchMethodException
- if there is no maching methodpublic Set getFields()
CodeClass
public CodeClass getSuperClass()
getSuperClass
in interface CodeClass
public CodeField getFieldByName(String name) throws NoSuchFieldException
CodeClass
getFieldByName
in interface CodeClass
name
- the field nameNoSuchFieldException
- if there is no field by that name accessible
through this classpublic int getModifiers()
CodeClass
getModifiers
in interface CodeClass
public String getDescriptor()
getDescriptor
in interface CodeClass
public GeneratedCodeMethod createMethod(String name, CodeClass type, CodeClass[] args, String[] argNames, int mods) throws CodeException
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.
name
- the method nametype
- the return typeargs
- arguments takenargNames
- names of the argumentsmods
- access modifiersCodeException
- if the method could not be createdpublic GeneratedCodeMethod createMethod(String name, CodeClass type, CodeClass[] args, int mods) throws CodeException
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.
name
- the method nametype
- the return typeargs
- arguments takenmods
- access modifiersCodeException
- if the method could not be createdpublic CodeField createField(String name, CodeClass clazz, int mods) throws CodeException
CodeException
public void setCodeGenerator(CodeMethod method, CodeGenerator cg) throws CodeException
CodeException
public void createCode(OutputStream os) throws IOException, CodeException
IOException
CodeException
public boolean isPrimitive()
CodeClass
isPrimitive
in interface CodeClass
Copyright © 2014 BioJava. All rights reserved.