net.percederberg.grammatica.code.java
Class JavaMethod

java.lang.Object
  |
  +--net.percederberg.grammatica.code.CodeElement
        |
        +--net.percederberg.grammatica.code.java.JavaMethod
All Implemented Interfaces:
java.lang.Comparable

public class JavaMethod
extends CodeElement

A class generating a Java method declaration.

Version:
1.0
Author:
Per Cederberg,

Field Summary
static int ABSTRACT
          The abstract modifier constant.
static int FINAL
          The final modifier constant.
static int NATIVE
          The abstract modifier constant.
static int PACKAGE_LOCAL
          The package local access modifier constant (i.e. no modifier).
static int PRIVATE
          The private access modifier constant.
static int PROTECTED
          The protected access modifier constant.
static int PUBLIC
          The public access modifier constant.
static int STATIC
          The static modifier constant.
static int STRICTFP
          The strictfp modifier constant.
static int SYNCHRONIZED
          The synchronized modifier constant.
 
Constructor Summary
JavaMethod(int modifiers, java.lang.String name, java.lang.String args, java.lang.String returnType)
          Creates a new method with the specified arguments.
JavaMethod(java.lang.String name)
          Creates a new method with the specified name.
JavaMethod(java.lang.String name, java.lang.String args)
          Creates a new method with the specified name and arguments.
JavaMethod(java.lang.String name, java.lang.String args, java.lang.String returnType)
          Creates a new method with the specified arguments.
 
Method Summary
 void addCode(java.lang.String codeLines)
          Adds one or more lines of actual code.
 void addComment(JavaComment comment)
          Sets a comment for this method.
 void addThrows(java.lang.String className)
          Adds a class to the list of exceptions thrown.
 boolean canPrintCode()
          Checks if the method source code can the printed.
 int category()
          Returns a numeric category number for the code element.
 void print(java.io.PrintWriter out, CodeStyle style, int indent)
          Prints the code element to the specified output stream.
 void setPrintCode(boolean value)
          Sets the print code flag.
 
Methods inherited from class net.percederberg.grammatica.code.CodeElement
compareTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PUBLIC

public static final int PUBLIC
The public access modifier constant.

See Also:
Constant Field Values

PROTECTED

public static final int PROTECTED
The protected access modifier constant.

See Also:
Constant Field Values

PACKAGE_LOCAL

public static final int PACKAGE_LOCAL
The package local access modifier constant (i.e. no modifier).

See Also:
Constant Field Values

PRIVATE

public static final int PRIVATE
The private access modifier constant.

See Also:
Constant Field Values

STATIC

public static final int STATIC
The static modifier constant.

See Also:
Constant Field Values

ABSTRACT

public static final int ABSTRACT
The abstract modifier constant.

See Also:
Constant Field Values

FINAL

public static final int FINAL
The final modifier constant.

See Also:
Constant Field Values

SYNCHRONIZED

public static final int SYNCHRONIZED
The synchronized modifier constant.

See Also:
Constant Field Values

NATIVE

public static final int NATIVE
The abstract modifier constant.

See Also:
Constant Field Values

STRICTFP

public static final int STRICTFP
The strictfp modifier constant.

See Also:
Constant Field Values
Constructor Detail

JavaMethod

public JavaMethod(java.lang.String name)
Creates a new method with the specified name. The method will not take any arguments and will return void.

Parameters:
name - the method name

JavaMethod

public JavaMethod(java.lang.String name,
                  java.lang.String args)
Creates a new method with the specified name and arguments. The method will return void.

Parameters:
name - the method name
args - the argument list, excluding parenthesis

JavaMethod

public JavaMethod(java.lang.String name,
                  java.lang.String args,
                  java.lang.String returnType)
Creates a new method with the specified arguments.

Parameters:
name - the method name
args - the argument list, excluding parenthesis
returnType - the return type

JavaMethod

public JavaMethod(int modifiers,
                  java.lang.String name,
                  java.lang.String args,
                  java.lang.String returnType)
Creates a new method with the specified arguments.

Parameters:
modifiers - the modifier flags to use
name - the method name
args - the argument list, excluding parenthesis
returnType - the return type
Method Detail

addThrows

public void addThrows(java.lang.String className)
Adds a class to the list of exceptions thrown.

Parameters:
className - the name of the exception thrown

addCode

public void addCode(java.lang.String codeLines)
Adds one or more lines of actual code.

Parameters:
codeLines - the lines of Java code to add

addComment

public void addComment(JavaComment comment)
Sets a comment for this method.

Parameters:
comment - the new method comment

category

public int category()
Returns a numeric category number for the code element. A lower category number implies that the code element should be placed before code elements with a higher category number within a declaration.

Specified by:
category in class CodeElement
Returns:
the category number

canPrintCode

public boolean canPrintCode()
Checks if the method source code can the printed. This method will return false if the method is abstract or if the print code flag is set to false.

Returns:
true if method source code can be printed, or false otherwise

setPrintCode

public void setPrintCode(boolean value)
Sets the print code flag.

Parameters:
value - the new print code flag value

print

public void print(java.io.PrintWriter out,
                  CodeStyle style,
                  int indent)
Prints the code element to the specified output stream.

Specified by:
print in class CodeElement
Parameters:
out - the output stream
style - the code style to use
indent - the indentation level