public class CodeGenerator extends Object
Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights
reserved.
BSD-style license. See OpenTrafficSim License.
$LastChangedDate: 2015-07-26 01:01:13 +0200 (Sun, 26 Jul 2015) $, @version $Revision: 1155 $, by $Author: pknoppers
$, initial version okt. 2014
| Constructor and Description |
|---|
CodeGenerator(String generatorName,
String buildDir,
String packageBaseName,
String when,
Long serialVersionUID)
Create a new CodeGenerator.
|
| Modifier and Type | Method and Description |
|---|---|
static String[] |
arrayListToArray(ArrayList<String> code)
Convert an ArrayList<String> into an array of String.
|
String |
buildBlockComment(String indent,
String comment)
Generate a block comment.
|
String |
buildBrackets(int dimensions,
String contents)
Build a string with the specified number of [string] (square bracket with content) pairs.
|
String |
buildEmptyBrackets(int dimensions)
Build a string with the specified number of [] (square bracket) pairs.
|
String |
buildField(String indent,
String field,
String description)
Create a String that describes one field.
|
String |
buildMethod(String indent,
String qualifiersTypeAndName,
String description,
String[] parameters,
String exceptions,
String pragma,
String[] body,
boolean constructor)
Create a String that defines one method.
|
String |
buildSerialVersionUID(String indent)
Return the String that defines the serialVersionUID.
|
static void |
closeFile(BufferedWriter writer)
Close a file that was opened with openFile.
|
void |
generateAbstractClass(String relativePackage,
String name,
String[] imports,
String description,
String[] genericParams,
String typeInfo,
String contents)
Write a class file for an abstract class.
|
void |
generateClass(String relativePackage,
String name,
String[] imports,
String description,
String[] genericParams,
String qualifiers,
String typeInfo,
boolean generateSerialVersionUID,
String contents)
Write a class file.
|
void |
generateFinalClass(String relativePackage,
String name,
String[] imports,
String description,
String[] genericParams,
String typeInfo,
String contents)
Write a class file for a final class that cannot be instantiated.
|
void |
generateInterface(String relativePackage,
String name,
String[] imports,
String description,
String[] genericParams,
String typeInfo,
String body)
Write an interface file that defines an interface that does nothing but define it's own name.
|
void |
generatePackageInfo(String relativePackageName,
String contents)
Generate a package-info.java file.
|
String |
indent(int steps)
Create an indent of N units.
|
BufferedWriter |
openFile(String relativePackage,
String name,
String[] imports,
String description,
String[] genericParams)
Open a file and write the package line and initial block comment.
|
public CodeGenerator(String generatorName, String buildDir, String packageBaseName, String when, Long serialVersionUID)
generatorName - String; name of the program that uses this CodeGeneratorbuildDir - String; path to directory for generated files and sub-directoriespackageBaseName - String; prepended to all package nameswhen - String; textual description of the date that this CodeGenerator is usedserialVersionUID - String; serialVersionID to put in the generated class filespublic final BufferedWriter openFile(String relativePackage, String name, String[] imports, String description, String[] genericParams)
relativePackage - String; the last element(s) of the package namename - String; the name of the class file to writeimports - String[]; the imports for the new class filedescription - String; the description that is inserted in the block comment at the start of the filegenericParams - String[]; descriptions of the generic parameters of the classpublic static void closeFile(BufferedWriter writer)
writer - BufferedWriter; the result of the preceding call to openFilepublic final String buildSerialVersionUID(String indent)
indent - String; prepended to each output linepublic final void generateClass(String relativePackage, String name, String[] imports, String description, String[] genericParams, String qualifiers, String typeInfo, boolean generateSerialVersionUID, String contents)
relativePackage - String; the last element(s) of the package namename - String; the name of the class file to writeimports - String[]; the imports for the new class filedescription - String; the description that is inserted in the block comment at the start of the filegenericParams - String[]; the descriptions of the generic parameters of the classqualifiers - String; qualifiers that go before the class key word; e.g. public abstracttypeInfo - String; the text that goes immediately after the class namegenerateSerialVersionUID - boolean; if true a serialVersionUID is put in the resultcontents - String; the text that goes in the classpublic final void generateAbstractClass(String relativePackage, String name, String[] imports, String description, String[] genericParams, String typeInfo, String contents)
relativePackage - String; the last element(s) of the package namename - String; the name of the class file to writeimports - String[]; the imports for the new class filedescription - String; the description that is inserted in the block comment at the start of the filegenericParams - String[]; the descriptions of the generic parameters of the classtypeInfo - String; the text that goes immediately after the class namecontents - String; the text that goes in the classpublic final void generateFinalClass(String relativePackage, String name, String[] imports, String description, String[] genericParams, String typeInfo, String contents)
relativePackage - String; the last element(s) of the package namename - String; the name of the class file to writeimports - String[]; the imports for the new class filedescription - String; the description that is inserted in the block comment at the start of the filegenericParams - String[]; the descriptions of the generic parameters of the classtypeInfo - String; the text that goes immediately after the class namecontents - String; the text that goes in the classpublic final String buildField(String indent, String field, String description)
indent - String; prepended to each output linefield - String; the type and name of the fielddescription - String; the description of the fieldpublic final String buildBlockComment(String indent, String comment)
indent - String; prefix of all output linescomment - String; the text to center in the block commentpublic final String indent(int steps)
steps - int; the number Npublic final String buildMethod(String indent, String qualifiersTypeAndName, String description, String[] parameters, String exceptions, String pragma, String[] body, boolean constructor)
indent - String; prefix for all output linesqualifiersTypeAndName - String; the qualifiers, the type and the name of the method separated by vertical
bars, e.g. final public|double|getDoubleValue. If the method that must be generated
overrides a method in a parent class set this parameter to null.description - String; description of the methodparameters - String[]; one String for each parameter of the method. Each parameter string consists of
qualifiers, type, name separated by vertical bars, e.g. final int|index|index of the
entry. Null entries in the parameters array are silently ignored.exceptions - String; exception type and description separated by a vertical bar, or null if this method does
not throw exceptionspragma - String; text that goes after the JavaDoc, but before the start of the method codebody - String[]; the lines of the body of the method. Lines on the outermost level should start with 0
spaces. Null entries in the body array are silently ignoredconstructor - boolean; if true; the new method is a constructor; if false; the new method is not a
constructorpublic final void generateInterface(String relativePackage, String name, String[] imports, String description, String[] genericParams, String typeInfo, String body)
relativePackage - String; the last element(s) of the package namename - String; the name of the class file to writeimports - String[]; the imports for the new class filedescription - String; the description that is inserted in the block comment at the start of the filegenericParams - String[]; the descriptions of the generic parameters of the classtypeInfo - String; the text that goes immediately after the class namebody - String; the body of the interface filepublic final void generatePackageInfo(String relativePackageName, String contents)
relativePackageName - String; relative package namecontents - String; contents of the package-info filepublic String buildEmptyBrackets(int dimensions)
dimensions - int; the number of bracket pairs to concatenatepublic String buildBrackets(int dimensions, String contents)
dimensions - int; the number of bracket pairs with contents to concatenatecontents - String; the text that goes between each pair of bracketsCopyright © 2014–2015 Delft University of Technology. All rights reserved.