ac.essex.ooechs.ecj.ecj2java
Class JavaWriter

java.lang.Object
  extended by ac.essex.ooechs.ecj.ecj2java.JavaWriter

public class JavaWriter
extends java.lang.Object

Takes an ECJ individual and outputs it as Java Code. For this class to work properly, all your GP functions must implement the functionality in the ParseableNode interface. This means either extending the ParseableGPNode adapter class (for functions and terminals) or extending the ParseableERC adapter class (for ERCs)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version, provided that any use properly credits the author. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details at http://www.gnu.org

Version:
1.0
Author:
Olly Oechsle, University of Essex, Date: 05-Sep-2006
See Also:
ParseableNode

Field Summary
protected  java.lang.String classExtends
          If this class extends another class.
protected  java.lang.String classImplements
          Similar to class extends - if this class implements functions defined in an interface.
protected  java.lang.String classModifiers
          The class modifiers, default is public although you may possibly want to generate a different kind of class, abstract for example or inner class.
protected  java.lang.String className
          The name of the class.
protected  java.lang.String classPackage
          The package to which this class belongs, set to null if the class is package-less.
protected  java.lang.String comments
          Comments that appear just before the class.
 
Constructor Summary
JavaWriter(java.lang.String className, java.lang.String GPFunctionSignature)
           
JavaWriter(java.lang.String className, java.lang.String GPFunctionSignature, java.lang.String comments)
           
JavaWriter(java.lang.String className, java.lang.String GPFunctionSignature, java.lang.String comments, java.lang.String classPackage)
           
 
Method Summary
 void addComments(java.lang.String comments)
           
 void addFunctionSignature(java.lang.String functionSignature)
          Adds another function signature, in the case that the individual consists of more than one tree.
 void addImport(java.lang.String className)
          Adds a classname to be added to the list of import statements
 void addIntConstant(java.lang.String name, int value)
           
 java.lang.String getJavaCode(ec.gp.GPIndividual ind)
          Converts the individual to a String, containing a complete class declaration that can then be saved to disk or do whatever you want with.
 void saveJavaCode(ec.gp.GPIndividual ind, java.io.File directory)
          Generates the java code (using getJavaCode) saves the code in a given directory.
 void setExtends(java.lang.String classExtends)
           
 void setImplements(java.lang.String classImplements)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classModifiers

protected java.lang.String classModifiers
The class modifiers, default is public although you may possibly want to generate a different kind of class, abstract for example or inner class.


comments

protected java.lang.String comments
Comments that appear just before the class. They are entered JavaDoc style.


classPackage

protected java.lang.String classPackage
The package to which this class belongs, set to null if the class is package-less.


className

protected java.lang.String className
The name of the class. The class will be saved to ${classname}.java in the directory of your choosing if you use the saveJavaCode() function.


classExtends

protected java.lang.String classExtends
If this class extends another class. It is quite often useful for the GP generated class to extend an a abstract class. For example, the GP generated class has an evaluatePixel(int x, int y) method, and extends an abstract class which has a function to load an image and then call the evaluatePixel() function on each pixel.


classImplements

protected java.lang.String classImplements
Similar to class extends - if this class implements functions defined in an interface.

Constructor Detail

JavaWriter

public JavaWriter(java.lang.String className,
                  java.lang.String GPFunctionSignature)

JavaWriter

public JavaWriter(java.lang.String className,
                  java.lang.String GPFunctionSignature,
                  java.lang.String comments)

JavaWriter

public JavaWriter(java.lang.String className,
                  java.lang.String GPFunctionSignature,
                  java.lang.String comments,
                  java.lang.String classPackage)
Method Detail

addImport

public void addImport(java.lang.String className)
Adds a classname to be added to the list of import statements

Parameters:
className -

addComments

public void addComments(java.lang.String comments)

setImplements

public void setImplements(java.lang.String classImplements)

setExtends

public void setExtends(java.lang.String classExtends)

addIntConstant

public void addIntConstant(java.lang.String name,
                           int value)

addFunctionSignature

public void addFunctionSignature(java.lang.String functionSignature)
Adds another function signature, in the case that the individual consists of more than one tree. Function signatures do not need to include the brace at the end, for example
public void evaluate(int x, int y)


getJavaCode

public java.lang.String getJavaCode(ec.gp.GPIndividual ind)
Converts the individual to a String, containing a complete class declaration that can then be saved to disk or do whatever you want with. You need to pass it a GPIndividual class from within ECJ, preferably from the describe method in your Problem class.


saveJavaCode

public void saveJavaCode(ec.gp.GPIndividual ind,
                         java.io.File directory)
                  throws java.io.IOException
Generates the java code (using getJavaCode) saves the code in a given directory. Since there is no flexibility in the naming of the Java file (it will always be "${classname}.java", the function doesn't allow the filename to be specified.

Throws:
java.io.IOException