Class JMethod
java.lang.Object
org.codehaus.modello.plugin.java.javasource.JMethod
A class which holds information about the methods of
a JClass.
Modelled closely after the Java Reflection API.
This class is part of package which is used to
create source code.
- Version:
- $Revision$ $Date$
- Author:
- Keith Visco
-
Constructor Summary
ConstructorDescriptionCreates a new JMethod with the given name and "void" return type.Creates a new JMethod with the given name and returnType.Deprecated.removed in future version of javasource -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
(String annotation) JClass[]
Returns the exceptions that this JMember throws.Returns the JDocComment describing this member.Returns the modifiers for this JMember.getName()
Returns the name of this JMember.getParameter
(int index) Returns the JParameter at the given index.protected String[]
Returns the set of JParameters for this JMethod.Returns the JType that represents the return type of the method.Returns the JMethodSignature for this JMethod.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
(String comment) Sets the comment describing this member.void
setModifiers
(JModifiers modifiers) Sets the JModifiers for this JMethod.void
setSourceCode
(String source) Sets the given string as the source code (method body) for this JMethod.void
setSourceCode
(JSourceCode source) Sets the given JSourceCode as the source code (method body) for this JMethod.toString()
Returns the String representation of this JMethod, which is the method prototype.
-
Constructor Details
-
JMethod
Creates a new JMethod with the given name and "void" return type.- Parameters:
name
- , the method name. Must not be null.
-
JMethod
Deprecated.removed in future version of javasourceCreates a new JMethod with the given name and returnType. For "void" return types, simply pass in null as the returnType.- Parameters:
returnType
- the return type of the method. May be null.name
- , the method name. Must not be null.
-
JMethod
Creates a new JMethod with the given name and returnType. For "void" return types, simply pass in null as the returnType.- Parameters:
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.
-
-
Method Details
-
addException
Adds the given Exception to this Method's throws clause.- Parameters:
exp
- the JClass representing the Exception
-
addParameter
Adds the given parameter to this JMethod's list of parameters.- Parameters:
parameter
- the parameter to add to the this Methods list of parameters.- Throws:
IllegalArgumentException
- when a parameter already exists for this Method with the same name as the new parameter
-
getJDocComment
Returns the JDocComment describing this member.- Returns:
- the JDocComment describing this member.
-
getExceptions
Returns the exceptions that this JMember throws.- Returns:
- the exceptions that this JMember throws.
-
getModifiers
Returns the modifiers for this JMember.- Returns:
- the modifiers for this JMember.
-
getName
Returns the name of this JMember.- Returns:
- the name of this JMember.
-
getParameter
Returns the JParameter at the given index.- Parameters:
index
- the index of the JParameter to return.- Returns:
- the JParameter at the given index.
-
getParameters
Returns the set of JParameters for this JMethod.
Note: the array is a copy, the params in the array are the actual references.- Returns:
- the set of JParameters for this JMethod
-
getReturnType
Returns the JType that represents the return type of the method.- Returns:
- the JType that represents the return type of the method.
-
getSignature
Returns the JMethodSignature for this JMethod.- Returns:
- the JMethodSignature for this JMethod.
-
getSourceCode
Returns the JSourceCode for the method body.- Returns:
- the JSourceCode for the method body.
-
setComment
Sets the comment describing this member. The comment will be printed when this member is printed with the Class Printer.- Parameters:
comment
- the comment for this member- See Also:
-
setModifiers
Sets the JModifiers for this JMethod. This JMethod will use only a copy of the JModifiers. Note: The JModifiers will be set in the containing JMethodSignature. If the JMethodSignature is used by other methods, keep in mind that it will be changed.- Parameters:
modifiers
- the JModifiers to set.
-
setSourceCode
Sets the given string as the source code (method body) for this JMethod.- Parameters:
source
- the String that represents the method body.
-
setSourceCode
Sets the given JSourceCode as the source code (method body) for this JMethod.- Parameters:
source
- the JSourceCode that represents the method body.
-
print
Prints this JMethod to the given JSourceWriter.- Parameters:
jsw
- the JSourceWriter to print to.
-
toString
Returns the String representation of this JMethod, which is the method prototype. -
addDeclaringClass
Adds the given JClass to the set of classes that contain this method.- Parameters:
jClass
- the JClass to add as one of the JClasses that contain this method.
-
removeDeclaringClass
Removes the given JClass from the set of classes that contain this method.- Parameters:
jClass
- the JClass to add as one of the JClasses that contain this method.
-
getParameterClassNames
-
getAnnotations
- Returns:
- the annotations
-
appendAnnotation
- Parameters:
annotation
- the annotation to append
-
setAnnotations
- Parameters:
annotations
- the annotations to set
-