org.biojava.utils.bytecode
Class GeneratedCodeClass

java.lang.Object
  extended by org.biojava.utils.bytecode.GeneratedCodeClass
All Implemented Interfaces:
CodeClass

public class GeneratedCodeClass
extends java.lang.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
GeneratedCodeClass(java.lang.String name, java.lang.Class superClass, java.lang.Class[] interfaces, int modifiers)
           
GeneratedCodeClass(java.lang.String name, CodeClass superClass, CodeClass[] interfaces, int modifiers)
           
 
Method Summary
 void createCode(java.io.OutputStream os)
           
 CodeField createField(java.lang.String name, CodeClass clazz, int mods)
           
 GeneratedCodeMethod createMethod(java.lang.String name, CodeClass type, CodeClass[] args, int mods)
          Create a new method.
 GeneratedCodeMethod createMethod(java.lang.String name, CodeClass type, CodeClass[] args, java.lang.String[] argNames, int mods)
          Create a new method.
 CodeMethod getConstructor(CodeClass[] args)
          Get a constructor by argument list.
 java.lang.String getDescriptor()
           
 CodeField getFieldByName(java.lang.String name)
          Get a field by its name.
 java.util.Set getFields()
          Get all fields accessible through this class.
 java.util.List getInterfaces()
           
 java.lang.String getJName()
           
 CodeMethod getMethod(java.lang.String name, CodeClass[] args)
          Get a method by name and argument list.
 java.util.Set getMethods()
          Get all methods declared by this class and its super classes, removing all super class methods that are over ridden.
 java.util.Set getMethodsByName(java.lang.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.
 java.lang.String getName()
           
 java.lang.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(java.lang.String sourceFile)
          Set the source file associated with this code class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneratedCodeClass

public GeneratedCodeClass(java.lang.String name,
                          java.lang.Class superClass,
                          java.lang.Class[] interfaces,
                          int modifiers)
                   throws CodeException
Throws:
CodeException

GeneratedCodeClass

public GeneratedCodeClass(java.lang.String name,
                          CodeClass superClass,
                          CodeClass[] interfaces,
                          int modifiers)
                   throws CodeException
Throws:
CodeException
Method Detail

setSourceFile

public void setSourceFile(java.lang.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 java.lang.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 java.util.List getInterfaces()
Specified by:
getInterfaces in interface CodeClass

getMethods

public java.util.Set 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 interface CodeClass
Returns:
a Set containing all methods

getMethodsByName

public java.util.Set getMethodsByName(java.lang.String name)
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 interface CodeClass
Parameters:
name - the name of the method
Returns:
a Set of CodeMethod instances with that name

getConstructor

public CodeMethod getConstructor(CodeClass[] args)
                          throws java.lang.NoSuchMethodException
Description copied from interface: CodeClass
Get a constructor by argument list.

Specified by:
getConstructor in interface CodeClass
Parameters:
args - the arguments it takes
Returns:
a matching constructor
Throws:
java.lang.NoSuchMethodException - if there is no matching constructor

getMethod

public CodeMethod getMethod(java.lang.String name,
                            CodeClass[] args)
                     throws java.lang.NoSuchMethodException
Description copied from interface: CodeClass
Get a method by name and argument list.

Specified by:
getMethod in interface CodeClass
Parameters:
name - the name of the method
args - the arguments it takes
Returns:
a matching method
Throws:
java.lang.NoSuchMethodException - if there is no maching method

getFields

public java.util.Set getFields()
Description copied from interface: CodeClass
Get all fields accessible through this class.

Specified by:
getFields in interface CodeClass
Returns:
a Set of all accessible fields

getSuperClass

public CodeClass getSuperClass()
Specified by:
getSuperClass in interface CodeClass

getFieldByName

public CodeField getFieldByName(java.lang.String name)
                         throws java.lang.NoSuchFieldException
Description copied from interface: CodeClass
Get a field by its name.

Specified by:
getFieldByName in interface CodeClass
Parameters:
name - the field name
Returns:
a CodeField representing the field
Throws:
java.lang.NoSuchFieldException - if there is no field by that name accessible through this class

getName

public java.lang.String getName()
Specified by:
getName in interface CodeClass

getJName

public java.lang.String getJName()
Specified by:
getJName in interface CodeClass

getModifiers

public int getModifiers()
Description copied from interface: CodeClass
Get the modifiers associated with the class.

Specified by:
getModifiers in interface CodeClass
Returns:
the modifier integer

getDescriptor

public java.lang.String getDescriptor()
Specified by:
getDescriptor in interface CodeClass

createMethod

public GeneratedCodeMethod createMethod(java.lang.String name,
                                        CodeClass type,
                                        CodeClass[] args,
                                        java.lang.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 name
type - the return type
args - arguments taken
argNames - names of the arguments
mods - access modifiers
Returns:
a new GeneratedCodeMethod
Throws:
CodeException - if the method could not be created

createMethod

public GeneratedCodeMethod createMethod(java.lang.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 name
type - the return type
args - arguments taken
mods - access modifiers
Returns:
a new GeneratedCodeMethod
Throws:
CodeException - if the method could not be created

createField

public CodeField createField(java.lang.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(java.io.OutputStream os)
                throws java.io.IOException,
                       CodeException
Throws:
java.io.IOException
CodeException

isPrimitive

public boolean isPrimitive()
Description copied from interface: CodeClass
Discover if the class represents a primitive type.

Specified by:
isPrimitive in interface CodeClass
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.

Specified by:
isArray in interface CodeClass
Returns:
true if the class is an array type