public class JMethod extends java.lang.Object implements JMember
Modifier and Type | Field and Description |
---|---|
private java.util.List<JClass> |
_classes
The set of classes that contain this JMethod.
|
private JMethodSignature |
_signature
The signature for this method.
|
private JAnnotations |
annotations
The annotation(s) for this method.
|
private JDocComment |
jdc
The JavaDoc comment for this JMethod.
|
private JSourceCode |
source
The source code for this method
|
Constructor and Description |
---|
JMethod(JType returnType,
java.lang.String name)
Deprecated.
removed in future version of javasource
|
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 |
---|---|
protected void |
addDeclaringClass(JClass jClass)
Adds the given JClass to the set of classes that
contain this method.
|
void |
addException(JClass exp)
Adds the given Exception to this Method's throws clause.
|
void |
addParameter(JParameter parameter)
Adds the given parameter to this JMethod's list of parameters.
|
void |
appendAnnotation(java.lang.String annotation) |
JAnnotations |
getAnnotations() |
JClass[] |
getExceptions()
Returns the exceptions that this JMember throws.
|
JDocComment |
getJDocComment()
Returns the JDocComment describing this member.
|
JModifiers |
getModifiers()
Returns the modifiers for this JMember.
|
java.lang.String |
getName()
Returns the name of this JMember.
|
JParameter |
getParameter(int index)
Returns the JParameter at the given index.
|
protected java.lang.String[] |
getParameterClassNames() |
JParameter[] |
getParameters()
Returns the set of JParameters for this JMethod.
|
JType |
getReturnType()
Returns the JType that represents the return type of the method.
|
JMethodSignature |
getSignature()
Returns the JMethodSignature for this JMethod.
|
JSourceCode |
getSourceCode()
Returns the JSourceCode for the method body.
|
void |
print(JSourceWriter jsw)
Prints this JMethod to the given JSourceWriter.
|
protected void |
removeDeclaringClass(JClass jClass)
Removes the given JClass from the set of classes that
contain this method.
|
void |
setAnnotations(JAnnotations annotations) |
void |
setComment(java.lang.String comment)
Sets the comment describing this member.
|
void |
setModifiers(JModifiers modifiers)
Sets the JModifiers for 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.
|
private java.util.List<JClass> _classes
private JDocComment jdc
private JSourceCode source
private JMethodSignature _signature
private JAnnotations annotations
public JMethod(java.lang.String name)
name,
- the method name. Must not be null.public JMethod(JType returnType, java.lang.String name)
name,
- the method name. Must not be null.returnType
- the return type of the method. May be null.public JMethod(java.lang.String name, JType returnType, java.lang.String returnDoc)
name,
- the method name. Must not be null.returnType
- the return type of the method. May 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)
exp
- the JClass representing the Exceptionpublic void addParameter(JParameter parameter) throws java.lang.IllegalArgumentException
parameter
- the parameter to add to the this Methods
list of parameters.java.lang.IllegalArgumentException
- when a parameter already
exists for this Method with the same name as the new parameterpublic JDocComment getJDocComment()
public JClass[] getExceptions()
public JModifiers getModifiers()
getModifiers
in interface JMember
public java.lang.String getName()
public JParameter getParameter(int index)
index
- the index of the JParameter to return.public JParameter[] getParameters()
public JType getReturnType()
public JMethodSignature getSignature()
public JSourceCode getSourceCode()
public void setComment(java.lang.String comment)
comment
- the comment for this membergetJDocComment()
public void setModifiers(JModifiers modifiers)
modifiers
- the JModifiers to set.public void setSourceCode(java.lang.String source)
source
- the String that represents the method body.public void setSourceCode(JSourceCode source)
source
- the JSourceCode that represents the method body.public void print(JSourceWriter jsw)
jsw
- the JSourceWriter to print to.public java.lang.String toString()
toString
in class java.lang.Object
protected void addDeclaringClass(JClass jClass)
jClass
- the JClass to add as one of
the JClasses that contain this method.protected void removeDeclaringClass(JClass jClass)
jClass
- the JClass to add as one of
the JClasses that contain this method.protected java.lang.String[] getParameterClassNames()
public JAnnotations getAnnotations()
getAnnotations
in interface JMember
public void appendAnnotation(java.lang.String annotation)
annotation
- the annotation to appendpublic void setAnnotations(JAnnotations annotations)
annotations
- the annotations to set