org.exolab.javasource

Class JMethod

public final class JMethod extends 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: 6324 $ $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
voidaddAnnotation(JAnnotation annotation)
protected voidaddDeclaringClass(JClass jClass)
Adds the given JClass to the set of classes that contain this method.
voidaddException(JClass exp, String description)
Adds the given Exception to this JMethod's throws clause.
voidaddParameter(JParameter parameter)
Adds the given parameter to this JMethod's list of parameters.
JAnnotationgetAnnotation(JAnnotationType annotationType)
JAnnotation[]getAnnotations()
JClass[]getExceptions()
Returns the exceptions that this JMethod throws.
JDocCommentgetJDocComment()
Returns the JavaDoc comment describing this JMethod.
JModifiersgetModifiers()
Returns the modifiers for this JMethod.
StringgetName()
Returns the name of this JMethod.
JParametergetParameter(int index)
Returns the JParameter at the given index.
protected String[]getParameterClassNames()
Return the list of class names representing the parameters.
JParameter[]getParameters()
Returns the set of JParameters for this JMethod.
JTypegetReturnType()
Returns the JType that represents the return type of the JMethod.
JMethodSignaturegetSignature()
Returns the JMethodSignature for this JMethod.
JSourceCodegetSourceCode()
Returns the JSourceCode for the method body.
booleanhasAnnotations()
booleanisAnnotationPresent(JAnnotationType annotationType)
voidprint(JSourceWriter jsw)
Prints this JMethod to the given JSourceWriter.
JAnnotationremoveAnnotation(JAnnotationType annotationType)
protected voidremoveDeclaringClass(JClass jClass)
Removes the given JClass from the set of classes that contain this method.
voidsetComment(String comment)
Sets the comment describing this JMethod.
voidsetModifiers(JModifiers modifiers)
Sets the JModifiers for this JMethod.
voidsetName(String name)
Sets the name of this JMethod.
voidsetSourceCode(String source)
Sets the given string as the source code (method body) for this JMethod.
voidsetSourceCode(JSourceCode source)
Sets the given JSourceCode as the source code (method body) for this JMethod.
StringtoString()
Returns the String representation of this JMethod, which is the method prototype.

Constructor Detail

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 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 Detail

addAnnotation

public void addAnnotation(JAnnotation annotation)

See Also: #addAnnotation(org.exolab.javasource.JAnnotation) {@inheritDoc }

addDeclaringClass

protected void addDeclaringClass(JClass jClass)
Adds the given JClass to the set of classes that contain this method.

Parameters: jClass the JClass to add as one of the JClasses that contain this method

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)

See Also: #getAnnotation(org.exolab.javasource.JAnnotationType) {@inheritDoc }

getAnnotations

public JAnnotation[] getAnnotations()

See Also: {@inheritDoc }

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.

Returns: the modifiers for this JMethod.

getName

public String getName()
Returns the name of this JMethod.

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.

getParameterClassNames

protected String[] getParameterClassNames()
Return the list of class names representing the parameters.

Returns: the list of class names representing the parameters

See Also: JMethodSignature

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()

See Also: {@inheritDoc }

isAnnotationPresent

public boolean isAnnotationPresent(JAnnotationType annotationType)

See Also: #isAnnotationPresent(org.exolab.javasource.JAnnotationType) {@inheritDoc }

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)

See Also: #removeAnnotation(org.exolab.javasource.JAnnotationType) {@inheritDoc }

removeDeclaringClass

protected void removeDeclaringClass(JClass jClass)
Removes the given JClass from the set of classes that contain this method.

Parameters: jClass the JClass to remove as one of the JClasses that contain this method

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

See Also: JMethod

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()
Returns the String representation of this JMethod, which is the method prototype.

Returns: the String representation of this JMethod, which is simply the method prototype

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