org.exolab.javasource

Class JMethod

Implemented Interfaces:
JAnnotatedElement, JMember

public final class JMethod
extends java.lang.Object
implements JMember, JAnnotatedElement

A class which holds information about the methods of a JClass. Modelled closely after the Java Reflection API. This class is part of package which is used to create source code.
Version:
$Revision: 7331 $ $Date: 2004-12-03 11:57:33 -0700 (Fri, 03 Dec 2004) $
Author:
Keith Visco

Constructor Summary

JMethod(String name)
Creates a new JMethod with the given name and "void" return type.
JMethod(String name, JType returnType, String returnDoc)
Creates a new JMethod with the given name and returnType.

Method Summary

void
addAnnotation(JAnnotation annotation)
void
addException(JClass exp, String description)
Adds the given Exception to this JMethod's throws clause.
void
addParameter(JParameter parameter)
Adds the given parameter to this JMethod's list of parameters.
JAnnotation
getAnnotation(JAnnotationType annotationType)
JAnnotation[]
getAnnotations()
int
getExceptionCount()
Returns the amount of exceptions thrown.
JClass[]
getExceptions()
Returns the exceptions that this JMethod throws.
JDocComment
getJDocComment()
Returns the JavaDoc comment describing this JMethod.
JModifiers
getModifiers()
Returns the modifiers for this JMethod.
String
getName()
Returns the name of this JMethod.
JParameter
getParameter(int index)
Returns the JParameter at the given index.
int
getParameterCount()
Returns the amount of parameters.
JParameter[]
getParameters()
Returns the set of JParameters for this JMethod.
JType
getReturnType()
Returns the JType that represents the return type of the JMethod.
JMethodSignature
getSignature()
Returns the JMethodSignature for this JMethod.
JSourceCode
getSourceCode()
Returns the JSourceCode for the method body.
boolean
hasAnnotations()
boolean
isAnnotationPresent(JAnnotationType annotationType)
void
print(JSourceWriter jsw)
Prints this JMethod to the given JSourceWriter.
JAnnotation
removeAnnotation(JAnnotationType annotationType)
void
setComment(String comment)
Sets the comment describing this JMethod.
void
setModifiers(JModifiers modifiers)
Sets the JModifiers for this JMethod.
void
setName(String name)
Sets the name of this JMethod.
void
setSourceCode(String source)
Sets the given string as the source code (method body) for this JMethod.
void
setSourceCode(JSourceCode source)
Sets the given JSourceCode as the source code (method body) for this JMethod.
String
toString()

Constructor Details

JMethod

public JMethod(String name)
Creates a new JMethod with the given name and "void" return type.
Parameters:
name - The method name. Must not be null.

JMethod

public JMethod(String name,
               JType returnType,
               String returnDoc)
Creates a new JMethod with the given name and returnType. The return type must not be empty or null. For "void" return types, use JMethod(String) instead of this constructor.
Parameters:
name - The method name. Must not be null.
returnType - The return type of the method. Must not be null.
returnDoc - Javadoc comment for the @return annotation. If null, a default (and mostly useless) javadoc comment will be generated.

Method Details

addAnnotation

public void addAnnotation(JAnnotation annotation)
Specified by:
addAnnotation in interface JAnnotatedElement

addException

public void addException(JClass exp,
                         String description)
Adds the given Exception to this JMethod's throws clause.
Parameters:
exp - The JClass representing the Exception.
description - JavaDoc comment explaining when this exception is thrown.

addParameter

public void addParameter(JParameter parameter)
Adds the given parameter to this JMethod's list of parameters.
Parameters:
parameter - The parameter to add to the this JMethod's list of parameters.

getAnnotation

public JAnnotation getAnnotation(JAnnotationType annotationType)
Specified by:
getAnnotation in interface JAnnotatedElement

getAnnotations

public JAnnotation[] getAnnotations()
Specified by:
getAnnotations in interface JAnnotatedElement

getExceptionCount

public int getExceptionCount()
Returns the amount of exceptions thrown.
Returns:
The amount of exceptions thrown.

getExceptions

public JClass[] getExceptions()
Returns the exceptions that this JMethod throws.
Returns:
The exceptions that this JMethod throws.

getJDocComment

public JDocComment getJDocComment()
Returns the JavaDoc comment describing this JMethod.
Returns:
The JavaDoc comment describing this JMethod.

getModifiers

public JModifiers getModifiers()
Returns the modifiers for this JMethod.
Specified by:
getModifiers in interface JMember
Returns:
The modifiers for this JMethod.

getName

public String getName()
Returns the name of this JMethod.
Specified by:
getName in interface JMember
Returns:
The name of this JMethod.

getParameter

public JParameter getParameter(int index)
Returns the JParameter at the given index.
Parameters:
index - The index of the JParameter to return.
Returns:
The JParameter at the given index.

getParameterCount

public int getParameterCount()
Returns the amount of parameters.
Returns:
The amount of parameters.

getParameters

public JParameter[] getParameters()
Returns the set of JParameters for this JMethod.
Note: the array is a copy, the parameters in the array are the actual references.
Returns:
The set of JParameters for this JMethod.

getReturnType

public JType getReturnType()
Returns the JType that represents the return type of the JMethod.
Returns:
The JType that represents the return type of the JMethod.

getSignature

public JMethodSignature getSignature()
Returns the JMethodSignature for this JMethod.
Returns:
The JMethodSignature for this JMethod.

getSourceCode

public JSourceCode getSourceCode()
Returns the JSourceCode for the method body.
Returns:
The JSourceCode for the method body.

hasAnnotations

public boolean hasAnnotations()
Specified by:
hasAnnotations in interface JAnnotatedElement

isAnnotationPresent

public boolean isAnnotationPresent(JAnnotationType annotationType)
Specified by:
isAnnotationPresent in interface JAnnotatedElement

print

public void print(JSourceWriter jsw)
Prints this JMethod to the given JSourceWriter.
Parameters:
jsw - The JSourceWriter to print to.

removeAnnotation

public JAnnotation removeAnnotation(JAnnotationType annotationType)
Specified by:
removeAnnotation in interface JAnnotatedElement

setComment

public void setComment(String comment)
Sets the comment describing this JMethod. The comment will be printed when this JMethod is printed.
Parameters:
comment - The comment for this member.

setModifiers

public void setModifiers(JModifiers modifiers)
Sets the JModifiers for this JMethod. This JMethod will use only a copy of the JModifiers.
Note: The JModifiers will be set in the containing JMethodSignature. If the JMethodSignature is used by other methods, keep in mind that it will be changed.
Parameters:
modifiers - The JModifiers to set.

setName

public void setName(String name)
Sets the name of this JMethod.
Parameters:
name - The name of this method.

setSourceCode

public void setSourceCode(String source)
Sets the given string as the source code (method body) for this JMethod.
Parameters:
source - The String that represents the method body.

setSourceCode

public void setSourceCode(JSourceCode source)
Sets the given JSourceCode as the source code (method body) for this JMethod.
Parameters:
source - The JSourceCode that represents the method body.

toString

public String toString()

Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com