public class JMethod extends AbstractJGenerifiableImpl implements IJAnnotatable, IJDocCommentable
Modifier | Constructor and Description |
---|---|
protected |
JMethod(int nMods,
JDefinedClass aClass)
Constructor for constructors
|
protected |
JMethod(JDefinedClass aOwningClass,
int nMods,
AbstractJType aReturnType,
String sName)
Constructor for regular methods
|
Modifier and Type | Method and Description |
---|---|
JMethod |
_throws(AbstractJClass aException)
Add an exception to the list of exceptions that this method may throw.
|
JMethod |
_throws(Class<? extends Throwable> aException) |
JAnnotationUse |
annotate(AbstractJClass aClazz)
Adds an annotation to this variable.
|
JAnnotationUse |
annotate(Class<? extends Annotation> aClazz)
Adds an annotation to this variable.
|
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() |
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 sName)
Changes the name of the method.
|
JCodeModel |
owner()
Gets the owner code model object.
|
JDefinedClass |
owningClass() |
JVar |
param(AbstractJType aType,
String sName) |
JVar |
param(Class<?> aType,
String sName) |
JVar |
param(int nMods,
AbstractJType aType,
String sName)
Add the specified variable to the list of parameters for this method
signature.
|
JVar |
param(int nMods,
Class<?> aType,
String sName) |
JVar |
paramAtIndex(int nIndex) |
List<JVar> |
params()
Returns the list of variable of this method.
|
AbstractJType |
type() |
void |
type(AbstractJType aReturnType)
Overrides the return type.
|
JVar |
varParam() |
JVar |
varParam(AbstractJType aType,
String sName)
Add the specified variable argument to the list of parameters for this
method signature.
|
JVar |
varParam(Class<?> aType,
String sName)
Add the specified variable argument to the list of parameters for this
method signature.
|
JVar |
varParam(int nMods,
AbstractJType aType,
String sName)
Add the specified variable argument to the list of parameters for this
method signature.
|
JVar |
varParam(int nMods,
Class<?> aType,
String sName)
Add the specified variable argument to the list of parameters for this
method signature.
|
generify, typeParams
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
annotate2
generify, generify
protected JMethod(@Nonnull JDefinedClass aOwningClass, int nMods, @Nonnull AbstractJType aReturnType, @Nonnull String sName)
aOwningClass
- Outer class. May not be null
.nMods
- Modifiers for this method's declarationaReturnType
- Return type for the method. May not be null
.sName
- Name of this method. May neither be null
nor empty.protected JMethod(int nMods, @Nonnull JDefinedClass aClass)
nMods
- Modifiers for this constructor's declarationaClass
- Class containing this constructor. May not be null
.public boolean isConstructor()
@Nonnull public Collection<AbstractJClass> getThrows()
@Nonnull public JMethod _throws(@Nonnull AbstractJClass aException)
aException
- Name of an exception that this method may throw@Nonnull public List<JVar> params()
@Nonnull public JVar paramAtIndex(@Nonnegative int nIndex) throws IndexOutOfBoundsException
IndexOutOfBoundsException
@Nonnull public JVar param(int nMods, @Nonnull AbstractJType aType, @Nonnull String sName)
nMods
- Java modifiers to be usedaType
- JType of the parameter being addedsName
- Name of the parameter being addedJVar
@Nonnull public JVar varParam(@Nonnull Class<?> aType, @Nonnull String sName)
aType
- Type of the parameter being added.sName
- 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 aType, @Nonnull String sName)
aType
- Type of the parameter being added.sName
- 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 nMods, @Nonnull Class<?> aType, @Nonnull String sName)
nMods
- nMods to useaType
- Type of the parameter being added. Is automatically converted to an
array.sName
- 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 nMods, @Nonnull AbstractJType aType, @Nonnull String sName)
nMods
- nMods to useaType
- Type of the parameter being added. Is automatically converted to an
array.sName
- 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 aClazz)
annotate
in interface IJAnnotatable
aClazz
- The annotation class to annotate the field withnull
.@Nonnull public JAnnotationUse annotate(@Nonnull Class<? extends Annotation> aClazz)
annotate
in interface IJAnnotatable
aClazz
- The annotation class to annotate the field withnull
.@Nonnull public Collection<JAnnotationUse> annotations()
IJAnnotatable
IJAnnotatable
annotations
in interface IJAnnotatable
null
.public String name()
public void name(@Nonnull String sName)
sName
- New name@Nullable public AbstractJType type()
null
for constructors.public void type(@Nullable AbstractJType aReturnType)
aReturnType
- 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()
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 JDefinedClass owningClass()
JDefinedClass
to which this methods belongs. Never
null
.@Nonnull public JCodeModel owner()
IJOwned
Copyright © 2013–2017 Philip Helger. All rights reserved.