org.exolab.javasource

Class JMethod

public 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: 1.4 $ $Date: 2004/12/03 18:47:32 $

Author: Keith Visco

Constructor Summary
JMethod(String name)
Creates a new JMethod with the given name and "void" return type.
JMethod(JType returnType, String name)
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)
Adds the given Exception to this Method'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 JMember throws.
JDocCommentgetJDocComment()
Returns the JDocComment describing this member.
JModifiersgetModifiers()
Returns the modifiers for this JMember.
StringgetName()
Returns the name of this JMember.
JParametergetParameter(int index)
Returns the JParameter at the given index.
protected String[]getParameterClassNames()
JParameter[]getParameters()
Returns the set of JParameters for this JMethod.
JTypegetReturnType()
Returns the JType that represents the return type of the method.
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 member.
voidsetModifiers(JModifiers modifiers)
Sets the JModifiers for this JMethod.
voidsetName(String name)
Sets the name of this JMember.
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(JType returnType, String name)
Creates a new JMethod with the given name and returnType. For "void" return types, simply pass in null as the returnType.

Parameters: name, the method name. Must not be null. returnType the return type of the method. May be null.

Method Detail

addAnnotation

public void addAnnotation(JAnnotation annotation)

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)
Adds the given Exception to this Method's throws clause.

Parameters: exp the JClass representing the Exception

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 Methods list of parameters.

Throws: IllegalArgumentException when a parameter already exists for this Method with the same name as the new parameter

getAnnotation

public JAnnotation getAnnotation(JAnnotationType annotationType)

getAnnotations

public JAnnotation[] getAnnotations()

getExceptions

public JClass[] getExceptions()
Returns the exceptions that this JMember throws.

Returns: the exceptions that this JMember throws.

getJDocComment

public JDocComment getJDocComment()
Returns the JDocComment describing this member.

Returns: the JDocComment describing this member.

getModifiers

public JModifiers getModifiers()
Returns the modifiers for this JMember.

Returns: the modifiers for this JMember.

getName

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

Returns: the name of this JMember.

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

getParameters

public JParameter[] getParameters()
Returns the set of JParameters for this JMethod.
Note: the array is a copy, the params 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 method.

Returns: the JType that represents the return type of the method.

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

isAnnotationPresent

public boolean isAnnotationPresent(JAnnotationType annotationType)

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)

removeDeclaringClass

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

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

setComment

public void setComment(String comment)
Sets the comment describing this member. The comment will be printed when this member is printed with the Class Printer.

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 JMember.

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-2004. All rights reserved http://www.intalio.com