public class JMethod extends Object implements JDeclaration, JAnnotatable, JDocCommentable
Modifier and Type | Method and Description |
---|---|
JMethod |
_throws(Class<? extends Throwable> exception) |
JMethod |
_throws(JClass exception)
Add an exception to the list of exceptions that this
method may throw.
|
JAnnotationUse |
annotate(Class<? extends Annotation> clazz)
Adds an annotation to this variable.
|
JAnnotationUse |
annotate(JClass clazz)
Adds an annotation to this variable.
|
<W extends JAnnotationWriter> |
annotate2(Class<W> clazz)
Adds an annotation to this program element
and returns a type-safe writer to fill in the values of such annotations.
|
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
|
JTypeVar |
generify(String name)
Adds a new type variable to this declaration.
|
JTypeVar |
generify(String name,
Class<?> bound)
Adds a new type variable to this declaration with a bound.
|
JTypeVar |
generify(String name,
JClass bound)
Adds a new type variable to this declaration with a bound.
|
JMods |
getMods()
Deprecated.
use
mods() |
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.
|
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() |
String |
name() |
void |
name(String n)
Changes the name of the method.
|
protected JCodeModel |
owner() |
JVar |
param(Class<?> type,
String name) |
JVar |
param(int mods,
Class<?> type,
String name) |
JVar |
param(int mods,
JType type,
String name)
Add the specified variable to the list of parameters
for this method signature.
|
JVar |
param(JType type,
String name) |
List<JVar> |
params()
Returns the list of variable of this method.
|
boolean |
removeAnnotation(JAnnotationUse annotation)
Removes annotation from this program element.
|
JType |
type()
Returns the return type.
|
void |
type(JType t)
Overrides the return type.
|
JTypeVar[] |
typeParams()
Iterates all the type parameters of this class/interface.
|
JVar |
varParam(Class<?> type,
String name) |
JVar |
varParam(JType type,
String name)
Add the specified variable argument to the list of parameters
for this method signature.
|
public JMethod _throws(JClass exception)
exception
- Name of an exception that this method may throwpublic List<JVar> params()
public JVar param(int mods, JType type, String name)
type
- JType of the parameter being addedname
- Name of the parameter being addedpublic JVar varParam(Class<?> type, String name)
varParam(JType, String)
public JVar varParam(JType type, String name)
type
- Type of the parameter being added.name
- Name of the parameter being addedIllegalStateException
- 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(Class<? extends Annotation> clazz)
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the field withpublic <W extends JAnnotationWriter> W annotate2(Class<W> clazz)
JAnnotatable
annotate2
in interface JAnnotatable
public boolean removeAnnotation(JAnnotationUse annotation)
JAnnotatable
removeAnnotation
in interface JAnnotatable
annotation
- The annotation to be removed from the program elementpublic Collection<JAnnotationUse> annotations()
JAnnotatable
JAnnotatable
annotations
in interface JAnnotatable
public boolean hasVarArgs()
public String name()
public void name(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
public JMods mods()
protected JCodeModel owner()
public JTypeVar generify(String name)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar generify(String name, Class<?> bound)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar generify(String name, JClass bound)
JGenerifiable
generify
in interface JGenerifiable
public JTypeVar[] typeParams()
JGenerifiable
typeParams
in interface JGenerifiable
Copyright © 2019 JBoss by Red Hat. All rights reserved.