public class JMethod extends AbstractJGenerifiableImpl implements IJAnnotatable, IJDocCommentable
Modifier | Constructor and Description |
---|---|
protected |
JMethod(int mods,
JDefinedClass aClass)
Constructor for constructors
|
protected |
JMethod(JDefinedClass outer,
int mods,
AbstractJType type,
String name)
Constructor for regular methods
|
Modifier and Type | Method and Description |
---|---|
JMethod |
_throws(AbstractJClass exception)
Add an exception to the list of exceptions that this method may throw.
|
JMethod |
_throws(Class<? extends Throwable> exception) |
JAnnotationUse |
annotate(AbstractJClass clazz)
Adds an annotation to this variable.
|
JAnnotationUse |
annotate(Class<? extends Annotation> clazz)
Adds an annotation to this variable.
|
<W extends IJAnnotationWriter<?>> |
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
IJAnnotatable |
JBlock |
body()
Get the block that makes up body of this method
|
void |
declare(JFormatter f) |
void |
declareDefaultValue(IJExpression aDefaultValue)
Specify the default value for this method
|
Collection<AbstractJClass> |
getThrows() |
boolean |
hasSignature(AbstractJType[] argTypes)
Returns true if the method has the specified signature.
|
boolean |
hasVarArgs() |
boolean |
isConstructor() |
JDocComment |
javadoc()
Creates, if necessary, and returns the class javadoc for this
JMethod . |
JVar[] |
listParams()
Returns all the parameters in an array.
|
AbstractJType[] |
listParamTypes()
Returns all the parameter types in an array.
|
JVar |
listVarParam()
Deprecated.
Use
varParam() instead. |
AbstractJType |
listVarParamType()
Returns the varags parameter type.
|
JMods |
mods() |
String |
name() |
void |
name(String n)
Changes the name of the method.
|
JCodeModel |
owner()
Gets the owner code model object.
|
JVar |
param(AbstractJType type,
String name) |
JVar |
param(Class<?> type,
String name) |
JVar |
param(int mods,
AbstractJType type,
String name)
Add the specified variable to the list of parameters for this method
signature.
|
JVar |
param(int mods,
Class<?> type,
String name) |
JVar |
paramAtIndex(int index) |
List<JVar> |
params()
Returns the list of variable of this method.
|
AbstractJType |
type() |
void |
type(AbstractJType t)
Overrides the return type.
|
JVar |
varParam() |
JVar |
varParam(AbstractJType type,
String name)
Add the specified variable argument to the list of parameters for this
method signature.
|
JVar |
varParam(Class<?> type,
String name)
Add the specified variable argument to the list of parameters for this
method signature.
|
JVar |
varParam(int mods,
AbstractJType type,
String name)
Add the specified variable argument to the list of parameters for this
method signature.
|
JVar |
varParam(int mods,
Class<?> type,
String name)
Add the specified variable argument to the list of parameters for this
method signature.
|
generify, generify, generify, typeParamList, typeParams
protected JMethod(@Nonnull JDefinedClass outer, int mods, AbstractJType type, String name)
outer
- Outer classmods
- Modifiers for this method's declarationtype
- Return type for the methodname
- Name of this methodprotected JMethod(int mods, @Nonnull JDefinedClass aClass)
mods
- Modifiers for this constructor's declarationaClass
- JClass containing this constructorpublic boolean isConstructor()
@Nonnull public Collection<AbstractJClass> getThrows()
@Nonnull public JMethod _throws(@Nonnull AbstractJClass exception)
exception
- Name of an exception that this method may throw@Nonnull public List<JVar> params()
@Nonnull public JVar paramAtIndex(@Nonnegative int index)
@Nonnull public JVar param(int mods, @Nonnull AbstractJType type, @Nonnull String name)
mods
- Java modifiers to be usedtype
- JType of the parameter being addedname
- Name of the parameter being addedJVar
@Nonnull public JVar varParam(@Nonnull Class<?> type, @Nonnull 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.@Nonnull public JVar varParam(@Nonnull AbstractJType type, @Nonnull 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.@Nonnull public JVar varParam(int mods, @Nonnull Class<?> type, @Nonnull String name)
mods
- mods to usetype
- Type of the parameter being added. Is automatically converted to an
array.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.@Nonnull public JVar varParam(int mods, @Nonnull AbstractJType type, @Nonnull String name)
mods
- mods to usetype
- Type of the parameter being added. Is automatically converted to an
array.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 boolean hasVarArgs()
true
if there are any varargs declared for this method
signature.@Nullable public AbstractJType listVarParamType()
@Nonnull public JAnnotationUse annotate(@Nonnull AbstractJClass clazz)
annotate
in interface IJAnnotatable
clazz
- The annotation class to annotate the field withnull
.@Nonnull public JAnnotationUse annotate(@Nonnull Class<? extends Annotation> clazz)
annotate
in interface IJAnnotatable
clazz
- The annotation class to annotate the field withnull
.@Nonnull public <W extends IJAnnotationWriter<?>> W annotate2(@Nonnull Class<W> clazz)
IJAnnotatable
annotate2
in interface IJAnnotatable
W
- Implementation typeclazz
- Source class@Nonnull public Collection<JAnnotationUse> annotations()
IJAnnotatable
IJAnnotatable
annotations
in interface IJAnnotatable
null
.public String name()
public void name(String n)
n
- New name@Nullable public AbstractJType type()
null
for constructors.public void type(@Nullable AbstractJType t)
t
- The type to set. Set to null
to make this method a
constructor.@Nonnull public AbstractJType[] listParamTypes()
@Nonnull public JVar[] listParams()
@Nullable @Deprecated public JVar listVarParam()
varParam()
instead.public boolean hasSignature(@Nonnull AbstractJType[] argTypes)
argTypes
- Signature to checktrue
if this method has the provided signature@Nonnull public JBlock body()
null
.public void declareDefaultValue(@Nullable IJExpression aDefaultValue)
aDefaultValue
- Default value for the method@Nonnull public JDocComment javadoc()
JMethod
.javadoc
in interface IJDocCommentable
null
.public void declare(@Nonnull JFormatter f)
declare
in interface IJDeclaration
declare
in class AbstractJGenerifiableImpl
@Nonnull public JMods mods()
@Nonnull public JCodeModel owner()
IJOwned
Copyright © 2013–2015 Philip Helger. All rights reserved.