public class JMethod extends JGenerifiableImpl implements JDeclaration, JAnnotatable, JDocCommentable
Modifier and Type | Field and Description |
---|---|
private java.util.Set<JClass> |
_throws
Set of exceptions that this method may throw.
|
private java.util.List<JAnnotationUse> |
annotations
Annotations on this variable.
|
private JBlock |
body
JBlock of statements that makes up the body this method
|
private JExpression |
defaultValue
To set the default value for the
annotation member
|
private JDocComment |
jdoc
javadoc comments for this JMethod
|
private JMods |
mods
Modifiers for this method
|
private java.lang.String |
name
Name of this method
|
private JDefinedClass |
outer |
private java.util.List<JVar> |
params
List of parameters for this method's declaration
|
private JType |
type
Return type for this method
|
private JVar |
varParam
Variable parameter for this method's varargs declaration
introduced in J2SE 1.5
|
Constructor and Description |
---|
JMethod(int mods,
JDefinedClass _class)
Constructor constructor
|
JMethod(JDefinedClass outer,
int mods,
JType type,
java.lang.String name)
JMethod constructor
|
Modifier and Type | Method and Description |
---|---|
JMethod |
_throws(java.lang.Class<? extends java.lang.Throwable> exception) |
JMethod |
_throws(JClass exception)
Add an exception to the list of exceptions that this
method may throw.
|
JAnnotationUse |
annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Adds an annotation to this variable.
|
JAnnotationUse |
annotate(JClass clazz)
Adds an annotation to this variable.
|
<W extends JAnnotationWriter> |
annotate2(java.lang.Class<W> clazz)
Adds an annotation to this program element
and returns a type-safe writer to fill in the values of such annotations.
|
java.util.Collection<JAnnotationUse> |
annotations()
Read-only live view of all annotations on this
JAnnotatable |
JBlock |
body()
Get the block that makes up body of this method
|
void |
declare(JFormatter f) |
void |
declareDefaultValue(JExpression value)
Specify the default value for this annotation member
|
JMods |
getMods()
Deprecated.
use
mods() |
private java.util.Set<JClass> |
getThrows() |
boolean |
hasSignature(JType[] argTypes)
Returns true if the method has the specified signature.
|
boolean |
hasVarArgs()
Check if there are any varargs declared
for this method signature.
|
private boolean |
isConstructor() |
JDocComment |
javadoc()
Creates, if necessary, and returns the class javadoc for this
JDefinedClass
|
JVar[] |
listParams()
Returns all the parameters in an array.
|
JType[] |
listParamTypes()
Returns all the parameter types in an array.
|
JVar |
listVarParam()
Returns the variable parameter
|
JType |
listVarParamType()
Returns the varags parameter type.
|
JMods |
mods() |
java.lang.String |
name() |
void |
name(java.lang.String n)
Changes the name of the method.
|
protected JCodeModel |
owner() |
JVar |
param(java.lang.Class<?> type,
java.lang.String name) |
JVar |
param(int mods,
java.lang.Class<?> type,
java.lang.String name) |
JVar |
param(int mods,
JType type,
java.lang.String name)
Add the specified variable to the list of parameters
for this method signature.
|
JVar |
param(JType type,
java.lang.String name) |
java.util.List<JVar> |
params()
Returns the list of variable of this method.
|
JType |
type()
Returns the return type.
|
void |
type(JType t)
Overrides the return type.
|
JVar |
varParam(java.lang.Class<?> type,
java.lang.String name) |
JVar |
varParam(JType type,
java.lang.String name)
Add the specified variable argument to the list of parameters
for this method signature.
|
generify, generify, generify, typeParams
private JMods mods
private JType type
private java.lang.String name
private final java.util.List<JVar> params
private java.util.Set<JClass> _throws
private JBlock body
private JDefinedClass outer
private JDocComment jdoc
private JVar varParam
private java.util.List<JAnnotationUse> annotations
private JExpression defaultValue
JMethod(JDefinedClass outer, int mods, JType type, java.lang.String name)
mods
- Modifiers for this method's declarationtype
- Return type for the methodname
- Name of this methodJMethod(int mods, JDefinedClass _class)
mods
- Modifiers for this constructor's declaration_class
- JClass containing this constructorprivate boolean isConstructor()
private java.util.Set<JClass> getThrows()
public JMethod _throws(JClass exception)
exception
- Name of an exception that this method may throwpublic JMethod _throws(java.lang.Class<? extends java.lang.Throwable> exception)
public java.util.List<JVar> params()
public JVar param(int mods, JType type, java.lang.String name)
type
- JType of the parameter being addedname
- Name of the parameter being addedpublic JVar param(int mods, java.lang.Class<?> type, java.lang.String name)
public JVar param(java.lang.Class<?> type, java.lang.String name)
public JVar varParam(java.lang.Class<?> type, java.lang.String name)
varParam(JType, String)
public JVar varParam(JType type, java.lang.String name)
type
- Type of the parameter being added.name
- Name of the parameter being addedjava.lang.IllegalStateException
- If this method is called twice.
varargs in J2SE 1.5 can appear only once in the
method signature.public JAnnotationUse annotate(JClass clazz)
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the field withpublic JAnnotationUse annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the field withpublic <W extends JAnnotationWriter> W annotate2(java.lang.Class<W> clazz)
JAnnotatable
annotate2
in interface JAnnotatable
public java.util.Collection<JAnnotationUse> annotations()
JAnnotatable
JAnnotatable
annotations
in interface JAnnotatable
public boolean hasVarArgs()
public java.lang.String name()
public void name(java.lang.String n)
public JType type()
public void type(JType t)
public JType[] listParamTypes()
public JType listVarParamType()
public JVar[] listParams()
public JVar listVarParam()
public boolean hasSignature(JType[] argTypes)
public JBlock body()
public void declareDefaultValue(JExpression value)
value
- Default value for the annotation memberpublic JDocComment javadoc()
javadoc
in interface JDocCommentable
public void declare(JFormatter f)
declare
in interface JDeclaration
declare
in class JGenerifiableImpl
public JMods mods()
protected JCodeModel owner()
owner
in class JGenerifiableImpl