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 Details

  • Method Details

    • 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:
      getInterfaces in interface CodeClass
    • getMethods

      public 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 Set getMethodsByName(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 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:
      NoSuchMethodException - if there is no matching constructor
    • getMethod

      public CodeMethod getMethod(String name, CodeClass[] args) throws 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:
      NoSuchMethodException - if there is no maching method
    • getFields

      public 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(String name) throws 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:
      NoSuchFieldException - if there is no field by that name accessible through this class
    • getName

      public String getName()
      Specified by:
      getName in interface CodeClass
    • getJName

      public 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 String getDescriptor()
      Specified by:
      getDescriptor in interface CodeClass
    • 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 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(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(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:
      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