/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Java method.
*/
public class JMethod extends JGenerifiableImpl implements JDeclaration, JAnnotatable, JDocCommentable {
/**
* Modifiers for this method
*/
/**
* Return type for this method
*/
/**
* Name of this method
*/
/**
* List of parameters for this method's declaration
*/
/**
* Set of exceptions that this method may throw.
* A set instance lazily created.
*/
/**
* JBlock of statements that makes up the body this method
*/
/**
* javadoc comments for this JMethod
*/
/**
* Variable parameter for this method's varargs declaration
* introduced in J2SE 1.5
*/
/**
* Annotations on this variable. Lazily created.
*/
private boolean isConstructor() {
}
/** To set the default value for the
* annotation member
*/
/**
* JMethod constructor
*
* @param mods
* Modifiers for this method's declaration
*
* @param type
* Return type for the method
*
* @param name
* Name of this method
*/
}
/**
* Constructor constructor
*
* @param mods
* Modifiers for this constructor's declaration
*
* @param _class
* JClass containing this constructor
*/
}
return _throws;
}
/**
* Add an exception to the list of exceptions that this
* method may throw.
*
* @param exception
* Name of an exception that this method may throw
*/
return this;
}
}
/**
* Returns the list of variable of this method.
*
* @return List of parameters of this method. This list is not modifiable.
*/
}
/**
* Add the specified variable to the list of parameters
* for this method signature.
*
* @param type
* JType of the parameter being added
*
* @param name
* Name of the parameter being added
*
* @return New parameter variable
*/
return v;
}
}
}
}
/**
* @see #varParam(JType, String)
*/
}
/**
* Add the specified variable argument to the list of parameters
* for this method signature.
*
* @param type
* Type of the parameter being added.
*
* @param name
* Name of the parameter being added
*
* @return the variable parameter
*
* @throws IllegalStateException
* If this method is called twice.
* varargs in J2SE 1.5 can appear only once in the
* method signature.
*/
if (!hasVarArgs()) {
varParam =
new JVar(
name,
null);
return varParam;
} else {
throw new IllegalStateException(
"Cannot have two varargs in a method,\n"
+ "Check if varParam method of JMethod is"
+ " invoked more than once");
}
}
/**
* Adds an annotation to this variable.
* @param clazz
* The annotation class to annotate the field with
*/
if(annotations==null)
annotations.add(a);
return a;
}
/**
* Adds an annotation to this variable.
*
* @param clazz
* The annotation class to annotate the field with
*/
}
}
if (annotations == null)
}
/**
* Check if there are any varargs declared
* for this method signature.
*/
public boolean hasVarArgs() {
}
return name;
}
/**
* Changes the name of the method.
*/
this.name = n;
}
/**
* Returns the return type.
*/
return type;
}
/**
* Overrides the return type.
*/
this.type = t;
}
/**
* Returns all the parameter types in an array.
* @return
* If there's no parameter, an empty array will be returned.
*/
for (int i = 0; i < r.length; i++)
return r;
}
/**
* Returns the varags parameter type.
* @return
* If there's no vararg parameter type, null will be returned.
*/
else
return null;
}
/**
* Returns all the parameters in an array.
* @return
* If there's no parameter, an empty array will be returned.
*/
}
/**
* Returns the variable parameter
* @return
* If there's no parameter, null will be returned.
*/
return varParam;
}
/**
* Returns true if the method has the specified signature.
*/
JVar[] p = listParams();
return false;
for (int i = 0; i < p.length; i++)
return false;
return true;
}
/**
* Get the block that makes up body of this method
*
* @return Body of method
*/
return body;
}
/**
* Specify the default value for this annotation member
* @param value
* Default value for the annotation member
*
*/
this.defaultValue = value;
}
/**
* Creates, if necessary, and returns the class javadoc for this
* JDefinedClass
*
* @return JDocComment containing javadocs for this class
*/
return jdoc;
}
f.g(jdoc);
if (annotations != null){
for (JAnnotationUse a : annotations)
f.g(a).nl();
}
f.g(mods);
// declare the generics parameters
super.declare(f);
if (!isConstructor())
f.g(type);
// when parameters are printed in new lines, we want them to be indented.
// there's a good chance no newlines happen, too, but just in case it does.
boolean first = true;
if (!first)
f.p(',');
if(var.isAnnotated())
f.nl();
f.b(var);
first = false;
}
if (hasVarArgs()) {
if (!first)
f.p(',');
f.p("... ");
}
f.o().p(')');
}
if (defaultValue != null) {
f.p("default ");
f.g(defaultValue);
}
f.s(body);
} else if (
!outer.isInterface() && !outer.isAnnotationTypeDeclaration() && !mods.isAbstract() && !mods.isNative()) {
// Print an empty body for non-native, non-abstract methods
f.s(new JBlock());
} else {
f.p(';').nl();
}
}
/**
* @return
* the current modifiers of this method.
* Always return non-null valid object.
*/
return mods;
}
/**
* @deprecated use {@link #mods()}
*/
return mods;
}
}
}