Arch4J 1.1

org.arch4j.generator
Class JavaConstructorDefinition

java.lang.Object
  |
  +--org.arch4j.generator.JavaDefinition
        |
        +--org.arch4j.generator.JavaFunctionDefinition
              |
              +--org.arch4j.generator.JavaConstructorDefinition
All Implemented Interfaces:
JavaKeywordConstants, JavaPrimitiveConstants

public class JavaConstructorDefinition
extends JavaFunctionDefinition
implements JavaKeywordConstants

This class is used to define the attributes of a Java constructor method. The attributes can then be used to generate a valid Java constructor method definition string.

The number of constructors are meant to make it easy to define a constructor with as few statements as possible. There are also additional shortcut static methods to create a default constructor.

If left uninitialized, the access control modifier for the constructor defaults to public access.

Version:
1.0
Author:
Ross E. Greinke

Field Summary
protected  String className
          The class name for this constructor.
static String DEFAULT_CODE_BLOCK
          The code block to use for the default constructor.
 
Fields inherited from class org.arch4j.generator.JavaFunctionDefinition
codeBlock, exceptions, parameters
 
Fields inherited from class org.arch4j.generator.JavaDefinition
accessModifier, comment
 
Fields inherited from interface org.arch4j.generator.JavaKeywordConstants
ABSTRACT, CATCH, CLASS, DEFAULT_ACCESS, EXTENDS, FALSE, FINAL, FINALLY, IMPLEMENTS, IMPORT, INTERFACE, NATIVE, NEW, NULL, PACKAGE, PRIVATE, PROTECTED, PUBLIC, RETURN, STATIC, STRICTFP, SUPER, SYNCHRONIZED, THIS, THROW, THROWS, TRANSIENT, TRUE, TRY, VOID, VOLATILE
 
Fields inherited from interface org.arch4j.generator.JavaPrimitiveConstants
BOOLEAN, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORT
 
Constructor Summary
JavaConstructorDefinition(String comment, JavaAccessModifier accessModifier, String className, List parameters, List exceptions, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, list of thrown exceptions, and code block.
JavaConstructorDefinition(String comment, JavaAccessModifier accessModifier, String className, List parameters, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, and code block.
JavaConstructorDefinition(String comment, JavaAccessModifier accessModifier, String className, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, and code block.
JavaConstructorDefinition(String className, List parameters, List exceptions, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified class name, list of formal parameters, list of thrown exceptions, and code block.
JavaConstructorDefinition(String className, List parameters, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified class name, list of formal parameters, and code block.
JavaConstructorDefinition(String className, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified class name and code block.
JavaConstructorDefinition(String comment, String accessModifier, String className, List parameters, List exceptions, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, list of thrown exceptions, and code block.
JavaConstructorDefinition(String comment, String accessModifier, String className, List parameters, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, and code block.
JavaConstructorDefinition(String comment, String accessModifier, String className, String codeBlock)
          Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, and code block.
 
Method Summary
static JavaConstructorDefinition defaultConstructorFor(String className)
          Create a new default constructor with the specified class name.
static JavaConstructorDefinition defaultConstructorFor(String comment, JavaAccessModifier accessModifier, String className)
          Create a new default constructor with the specified comment, access control modifier, and class name.
static JavaConstructorDefinition defaultConstructorFor(String comment, JavaAccessModifier accessModifier, String className, String codeBlock)
          Create a new default constructor with the specified comment, access control modifier, class name, and code block.
static JavaConstructorDefinition defaultConstructorFor(String className, String codeBlock)
          Create a new default constructor with the specified class name and code block.
static JavaConstructorDefinition defaultConstructorFor(String comment, String accessModifier, String className)
          Create a new default constructor with the specified comment, access control modifier, and class name.
static JavaConstructorDefinition defaultConstructorFor(String comment, String accessModifier, String className, String codeBlock)
          Create a new default constructor with the specified comment, access control modifier, class name, and code block.
 String getClassName()
          Returns the constructor's class name.
protected  String getDefaultComment()
          Returns a simple, descriptive, one line comment for the function.
protected  String getReturnComment()
          Returns a javadoc @return string.
protected  boolean hasReturnType()
          Returns whether the function has a return type or not.
 void writeDefinitionTo(CodeBuffer buffer)
          Write the Java source representation of the constructor to the CodeBuffer.
 
Methods inherited from class org.arch4j.generator.JavaFunctionDefinition
addException, addException, addExceptions, addParameter, addParameter, addParameter, addParameters, getCodeBlock, getExceptions, getFormattedComment, getImports, getParameters, hasExceptions, hasParameters, setExceptions, setParameters
 
Methods inherited from class org.arch4j.generator.JavaDefinition
getAccessModifier, getComment, getDefinition, hasComment, setAccessModifier, setComment
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CODE_BLOCK

public static final String DEFAULT_CODE_BLOCK
The code block to use for the default constructor.

See Also:
Constant Field Values

className

protected String className
The class name for this constructor.

Constructor Detail

JavaConstructorDefinition

public JavaConstructorDefinition(String className,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified class name and code block. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero. The access control modifier defaults to public access.

Parameters:
className - The class name, which is the same as the constructor name.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String className,
                                 List parameters,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified class name, list of formal parameters, and code block. The parameter list should contain JavaIdentifier objects. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero. The access control modifier defaults to public access.

Parameters:
className - The class name, which is the same as the constructor name.
parameters - The list of formal parameters the constructor accepts.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String className,
                                 List parameters,
                                 List exceptions,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified class name, list of formal parameters, list of thrown exceptions, and code block. The parameter list should contain JavaIdentifier objects. The exception list should contain JavaType objects, although Strings will be converted if it is more convenient to use Strings. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero. The access control modifier defaults to public access.

Parameters:
className - The class name, which is the same as the constructor name.
parameters - The list of formal parameters the constructor accepts.
exceptions - The list of exceptions thrown by the constructor.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String comment,
                                 String accessModifier,
                                 String className,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, and code block. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String comment,
                                 JavaAccessModifier accessModifier,
                                 String className,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, and code block. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String comment,
                                 String accessModifier,
                                 String className,
                                 List parameters,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, and code block. The parameter list should contain JavaIdentifier objects. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
parameters - The list of formal parameters the constructor accepts.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String comment,
                                 JavaAccessModifier accessModifier,
                                 String className,
                                 List parameters,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, and code block. The parameter list should contain JavaIdentifier objects. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
parameters - The list of formal parameters the constructor accepts.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String comment,
                                 String accessModifier,
                                 String className,
                                 List parameters,
                                 List exceptions,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, list of thrown exceptions, and code block. The parameter list should contain JavaIdentifier objects. The exception list should contain JavaType objects, although Strings will be converted if it is more convenient to use Strings. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
parameters - The list of formal parameters the constructor accepts.
exceptions - The list of exceptions thrown by the constructor.
codeBlock - The statements defining the body of the constructor.

JavaConstructorDefinition

public JavaConstructorDefinition(String comment,
                                 JavaAccessModifier accessModifier,
                                 String className,
                                 List parameters,
                                 List exceptions,
                                 String codeBlock)
Constructs a JavaConstructorDefinition with the specified comment, access control modifier, class name, list of formal parameters, list of thrown exceptions, and code block. The parameter list should contain JavaIdentifier objects. The exception list should contain JavaType objects, although Strings will be converted if it is more convenient to use Strings. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
parameters - The list of formal parameters the constructor accepts.
exceptions - The list of exceptions thrown by the constructor.
codeBlock - The statements defining the body of the constructor.
Method Detail

defaultConstructorFor

public static JavaConstructorDefinition defaultConstructorFor(String className)
Create a new default constructor with the specified class name.

Parameters:
className - The class name, which is the same as the constructor name.

defaultConstructorFor

public static JavaConstructorDefinition defaultConstructorFor(String className,
                                                              String codeBlock)
Create a new default constructor with the specified class name and code block. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
className - The class name, which is the same as the constructor name.
codeBlock - The statements defining the body of the constructor.

defaultConstructorFor

public static JavaConstructorDefinition defaultConstructorFor(String comment,
                                                              String accessModifier,
                                                              String className)
Create a new default constructor with the specified comment, access control modifier, and class name.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.

defaultConstructorFor

public static JavaConstructorDefinition defaultConstructorFor(String comment,
                                                              JavaAccessModifier accessModifier,
                                                              String className)
Create a new default constructor with the specified comment, access control modifier, and class name.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.

defaultConstructorFor

public static JavaConstructorDefinition defaultConstructorFor(String comment,
                                                              String accessModifier,
                                                              String className,
                                                              String codeBlock)
Create a new default constructor with the specified comment, access control modifier, class name, and code block. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
codeBlock - The statements defining the body of the constructor.

defaultConstructorFor

public static JavaConstructorDefinition defaultConstructorFor(String comment,
                                                              JavaAccessModifier accessModifier,
                                                              String className,
                                                              String codeBlock)
Create a new default constructor with the specified comment, access control modifier, class name, and code block. If the code block contains more than one line, format it with a CodeBuffer. Create it with an initial indentation level of zero.

Parameters:
comment - The constructor's descriptive comment.
accessModifier - The constructor's access control modifier.
className - The class name, which is the same as the constructor name.
codeBlock - The statements defining the body of the constructor.

getClassName

public String getClassName()
Returns the constructor's class name.

Returns:
The constructor's class name.

getDefaultComment

protected String getDefaultComment()
Description copied from class: JavaFunctionDefinition
Returns a simple, descriptive, one line comment for the function.

Specified by:
getDefaultComment in class JavaFunctionDefinition
Returns:
A simple, descriptive, one line comment for the function.

hasReturnType

protected boolean hasReturnType()
Description copied from class: JavaFunctionDefinition
Returns whether the function has a return type or not.

Specified by:
hasReturnType in class JavaFunctionDefinition
Returns:
true if the function has a return type.

getReturnComment

protected String getReturnComment()
Description copied from class: JavaFunctionDefinition
Returns a javadoc @return string.

Specified by:
getReturnComment in class JavaFunctionDefinition
Returns:
A javadoc @return string.

writeDefinitionTo

public void writeDefinitionTo(CodeBuffer buffer)
Write the Java source representation of the constructor to the CodeBuffer.

Specified by:
writeDefinitionTo in class JavaDefinition
Parameters:
buffer - The CodeBuffer with which to append the data.
See Also:
CodeBuffer

Arch4J 1.1

Copyright © 2000-2004 SpiderLogic, a service of Wipfli Ullrich Bertelson LLP.