public final class JMethod extends Object implements JMember, JAnnotatedElement
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAnnotation(JAnnotation annotation)
Adds a JAnnotation to this source element.
|
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)
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.
|
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()
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.
|
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(JSourceCode source)
Sets the given JSourceCode as the source code (method body) for this JMethod.
|
void |
setSourceCode(String source)
Sets the given string as the source code (method body) for this JMethod.
|
String |
toString() |
public JMethod(String name)
name - The method name. Must not be null.public JMethod(String name, JType returnType, 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, String description)
exp - The JClass representing the Exception.description - JavaDoc comment explaining when this exception is thrown.public void addParameter(JParameter parameter)
parameter - The parameter to add to the this JMethod's list of parameters.public JDocComment getJDocComment()
public JClass[] getExceptions()
public int getExceptionCount()
public JModifiers getModifiers()
getModifiers in interface JMemberpublic String getName()
public JParameter getParameter(int index)
index - The index of the JParameter to return.public JParameter[] getParameters()
public int getParameterCount()
public JType getReturnType()
public JMethodSignature getSignature()
public JSourceCode getSourceCode()
public void setName(String name)
name - The name of this method.public void setComment(String comment)
comment - The comment for this member.public void setModifiers(JModifiers modifiers)
modifiers - The JModifiers to set.public void setSourceCode(String source)
source - The String that represents the method body.public void setSourceCode(JSourceCode source)
source - The JSourceCode that represents the method body.public JAnnotation getAnnotation(JAnnotationType annotationType)
getAnnotation in interface JAnnotatedElementannotationType - Annotation type to retrieve.public JAnnotation[] getAnnotations()
getAnnotations in interface JAnnotatedElementpublic boolean isAnnotationPresent(JAnnotationType annotationType)
isAnnotationPresent in interface JAnnotatedElementannotationType - Annotation type to check for presence or absense.public void addAnnotation(JAnnotation annotation)
addAnnotation in interface JAnnotatedElementannotation - A JAnnotation to add to this source element.public JAnnotation removeAnnotation(JAnnotationType annotationType)
removeAnnotation in interface JAnnotatedElementannotationType - Annotation type to remove.public boolean hasAnnotations()
hasAnnotations in interface JAnnotatedElementpublic void print(JSourceWriter jsw)
jsw - The JSourceWriter to print to.Copyright © 2016. All rights reserved.