public final class JMethod extends java.lang.Object implements JMember, JAnnotatedElement
| Constructor and Description |
|---|
JMethod(java.lang.String name)
Creates a new JMethod with the given name and "void" return type.
|
JMethod(java.lang.String name,
JType returnType,
java.lang.String returnDoc)
Creates a new JMethod with the given name and returnType.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAnnotation(JAnnotation annotation)
Adds a JAnnotation to this source element.
|
protected void |
addDeclaringClass(JClass jClass)
Adds the given JClass to the set of classes that contain this method.
|
void |
addException(JClass exp,
java.lang.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)
Retrieves a JAnnotation for the given JAnnotationType, returns null if no
annotation has been set.
|
JAnnotation[] |
getAnnotations()
Returns a list of JAnnotation's already set on this source element.
|
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.
|
java.lang.String |
getName()
Returns the name of this JMethod.
|
JParameter |
getParameter(int index)
Returns the JParameter at the given index.
|
protected java.lang.String[] |
getParameterClassNames()
Return the list of class names representing the 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()
Returns true if this source element has any annotations.
|
boolean |
isAnnotationPresent(JAnnotationType annotationType)
Returns true if a JAnnotation exists for the given JAnnotationType.
|
void |
print(JSourceWriter jsw)
Prints this JMethod to the given JSourceWriter.
|
JAnnotation |
removeAnnotation(JAnnotationType annotationType)
Removes the JAnnotation from this source element for the given
JAnnotationType.
|
protected void |
removeDeclaringClass(JClass jClass)
Removes the given JClass from the set of classes that contain this method.
|
void |
setComment(java.lang.String comment)
Sets the comment describing this JMethod.
|
void |
setModifiers(JModifiers modifiers)
Sets the JModifiers for this JMethod.
|
void |
setName(java.lang.String name)
Sets the name of this JMethod.
|
void |
setSourceCode(JSourceCode source)
Sets the given JSourceCode as the source code (method body) for this
JMethod.
|
void |
setSourceCode(java.lang.String source)
Sets the given string as the source code (method body) for this JMethod.
|
java.lang.String |
toString()
Returns the String representation of this JMethod, which is the method
prototype.
|
public JMethod(java.lang.String name)
name - the method name. Must not be null.public JMethod(java.lang.String name,
JType returnType,
java.lang.String returnDoc)
JMethod(String) instead of this constructor.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.public void addException(JClass exp, java.lang.String description)
exp - the JClass representing the Exceptiondescription - JavaDoc comment explaining when this exception is thrownpublic void addParameter(JParameter parameter)
parameter - the parameter to add to the this JMethod's list of
parameters.public JDocComment getJDocComment()
public JClass[] getExceptions()
public JModifiers getModifiers()
getModifiers in interface JMemberpublic java.lang.String getName()
public JParameter getParameter(int index)
index - the index of the JParameter to returnpublic JParameter[] getParameters()
Note: the array is a copy, the parameters in the array are the actual references
public JType getReturnType()
public JMethodSignature getSignature()
public JSourceCode getSourceCode()
public void setName(java.lang.String name)
name - the name of this methodpublic void setComment(java.lang.String comment)
comment - the comment for this membergetJDocComment()public void setModifiers(JModifiers modifiers)
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.
modifiers - the JModifiers to set.public void setSourceCode(java.lang.String source)
source - the String that represents the method bodypublic void setSourceCode(JSourceCode source)
source - the JSourceCode that represents the method bodypublic void print(JSourceWriter jsw)
jsw - the JSourceWriter to print topublic java.lang.String toString()
toString in class java.lang.Objectpublic JAnnotation getAnnotation(JAnnotationType annotationType)
JAnnotatedElementgetAnnotation in interface JAnnotatedElementannotationType - Annotation type to retrieve#getAnnotation(org.exolab.javasource.JAnnotationType)
{@inheritDoc}public JAnnotation[] getAnnotations()
JAnnotatedElementgetAnnotations in interface JAnnotatedElement{@inheritDoc}public boolean isAnnotationPresent(JAnnotationType annotationType)
JAnnotatedElementisAnnotationPresent in interface JAnnotatedElementannotationType - Annotation type to check for presence or absense#isAnnotationPresent(org.exolab.javasource.JAnnotationType)
{@inheritDoc}public void addAnnotation(JAnnotation annotation)
JAnnotatedElementaddAnnotation in interface JAnnotatedElementannotation - a JAnnotation to add to this source element.#addAnnotation(org.exolab.javasource.JAnnotation)
{@inheritDoc}public JAnnotation removeAnnotation(JAnnotationType annotationType)
JAnnotatedElementremoveAnnotation in interface JAnnotatedElementannotationType - Annotation type to remove#removeAnnotation(org.exolab.javasource.JAnnotationType)
{@inheritDoc}public boolean hasAnnotations()
JAnnotatedElementhasAnnotations in interface JAnnotatedElement{@inheritDoc}protected void addDeclaringClass(JClass jClass)
jClass - the JClass to add as one of the JClasses that contain this
methodprotected void removeDeclaringClass(JClass jClass)
jClass - the JClass to remove as one of the JClasses that contain
this methodprotected java.lang.String[] getParameterClassNames()
JMethodSignature.getParameterClassNames()Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com