/*
* 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.
*/
/**
*
* <p>
* This class models a declaration, and since a declaration can be always
* used as a reference, it inherits {@link JClass}.
*
* <h2>Where to go from here?</h2>
* <p>
* You'd want to generate fields and methods on a class.
* See {@link #method(int, JType, String)} and {@link #field(int, JType, String)}.
*/
public class JDefinedClass
extends JClass
/** Name of this class. Null if anonymous. */
/** Modifiers for the class declaration */
/** Name of the super class of this class. */
/** List of interfaces that this class implements */
/** Fields keyed by their names. */
/** Static initializer, if this class has one */
/** class javadoc */
/** Set of constructors for this class, if any */
/** Set of methods that are members of this class */
/**
* Nested classes as a map from name to JDefinedClass.
* The name is all capitalized in a case sensitive file system
* ({@link JCodeModel#isCaseSensitiveFileSystem}) to avoid conflicts.
*
* Lazily created to save footprint.
*
* @see #getClasses()
*/
/**
* Flag that controls whether this class should be really generated or not.
*
* Sometimes it is useful to generate code that refers to class X,
* without actually generating the code of X.
* This flag is used to surpress X.java file in the output.
*/
private boolean hideFile = false;
/**
* Client-app spcific metadata associated with this user-created class.
*/
/**
* String that will be put directly inside the generated code.
* Can be null.
*/
/**
* If this is a package-member class, this is {@link JPackage}.
* If this is a nested class, this is {@link JDefinedClass}.
* If this is an anonymous class, this constructor shouldn't be used.
*/
/** Default value is class or interface
* or annotationTypeDeclaration
* or enum
*
*/
/** List containing the enum value declarations
*
*/
// private List enumValues = new ArrayList();
/**
* Set of enum constants that are keyed by names.
* In Java, enum constant order is actually significant,
* because of order ID they get. So let's preserve the order.
*/
private final Map<String,JEnumConstant> enumConstantsByName = new LinkedHashMap<String,JEnumConstant>();
/**
* Annotations on this variable. Lazily created.
*/
/**
* Helper class to implement {@link JGenerifiable}.
*/
protected JCodeModel owner() {
return JDefinedClass.this.owner();
}
};
}
/**
* Constructor for creating anonymous inner class.
*/
int mods,
}
private JDefinedClass(
int mods,
JCodeModel owner) {
}
/**
* JClass constructor
*
* @param mods
* Modifiers for this class declaration
*
* @param name
* Name of this class
*/
private JDefinedClass(
int mods,
super(owner);
throw new IllegalArgumentException("JClass name empty");
"JClass name "
+ name
+ " contains illegal character"
+ " for beginning of identifier: "
throw new IllegalArgumentException(msg);
}
"JClass name "
+ name
+ " contains illegal character "
throw new IllegalArgumentException(msg);
}
}
}
this.classType = classTypeVal;
if (isInterface())
else
}
/**
* Returns true if this is an anonymous class.
*/
public final boolean isAnonymous() {
}
/**
* This class extends the specifed class.
*
* @param superClass
* Superclass for this class
*
* @return This class
*/
if(superClass.isInterface()){
return this._implements(superClass);
} else throw new IllegalArgumentException("unable to set the super class for an interface");
if (superClass == null)
throw new NullPointerException();
if(this==o){
throw new IllegalArgumentException("Illegal class inheritance loop." +
}
}
this.superClass = superClass;
return this;
}
}
/**
* Returns the class extended by this class.
*/
if(superClass==null)
return superClass;
}
/**
* This class implements the specifed interface.
*
* @param iface
* Interface that this class implements
*
* @return This class
*/
return this;
}
}
/**
* Returns an iterator that walks the nested classes defined in this
* class.
*/
return interfaces.iterator();
}
/**
* JClass name accessor.
*
* <p>
* For example, for <code>java.util.List</code>, this method
* returns <code>"List"</code>"
*
* @return Name of this class
*/
return name;
}
/**
* If the named enum already exists, the reference to it is returned.
* Otherwise this method generates a new enum reference with the given
* name and returns it.
*
* @param name
* The name of the constant.
* @return
* The generated type-safe enum constant.
*/
}
return ec;
}
/**
* Gets the fully qualified name of this class.
*/
if (outer instanceof JDefinedClass)
if (p.isUnnamed())
return name();
else
}
if (outer instanceof JDefinedClass)
else
return fullName();
}
public boolean isInterface() {
}
public boolean isAbstract() {
return mods.isAbstract();
}
/**
* Adds a field to the list of field members of this JDefinedClass.
*
* @param mods
* Modifiers for this field
*
* @param type
* JType of this field
*
* @param name
* Name of this field
*
* @return Newly generated field
*/
}
}
/**
* Adds a field to the list of field members of this JDefinedClass.
*
* @param mods
* Modifiers for this field.
* @param type
* JType of this field.
* @param name
* Name of this field.
* @param init
* Initial value of this field.
*
* @return Newly generated field
*/
int mods,
JExpression init) {
}
return f;
}
/** This method indicates if the interface
* is an annotationTypeDeclaration
*
*/
public boolean isAnnotationTypeDeclaration() {
}
/**
* Add an annotationType Declaration to this package
* @param name
* Name of the annotation Type declaration to be added to this package
* @return
* newly created Annotation Type Declaration
* @exception JClassAlreadyExistsException
*/
}
/**
* Add a public enum to this package
* @param name
* Name of the enum to be added to this package
* @return
* newly created Enum
* @exception JClassAlreadyExistsException
*/
}
/**
* Add a public enum to this package
* @param name
* Name of the enum to be added to this package
* @param mods
* Modifiers for this enum declaration
* @return
* newly created Enum
* @exception JClassAlreadyExistsException
*/
}
return this.classType;
}
int mods,
JExpression init) {
}
/**
* Returns all the fields declred in this class.
* The returned {@link Map} is a read-only live view.
*
* @return always non-null.
*/
}
/**
* Removes a {@link JFieldVar} from this class.
*
* @throws IllegalArgumentException
* if the given field is not a field on this class.
*/
throw new IllegalArgumentException();
}
/**
* Creates, if necessary, and returns the static initializer
* for this class.
*
* @return JBlock containing initialization statements for this class
*/
return init;
}
/**
* Adds a constructor to this class.
*
* @param mods
* Modifiers for this constructor
*/
constructors.add(c);
return c;
}
/**
* Returns an iterator that walks the constructors defined in this class.
*/
return constructors.iterator();
}
/**
* Looks for a method that has the specified method signature
* and return it.
*
* @return
* null if not found.
*/
for (JMethod m : constructors) {
if (m.hasSignature(argTypes))
return m;
}
return null;
}
/**
* Add a method to the list of method members of this JDefinedClass instance.
*
* @param mods
* Modifiers for this method
*
* @param type
* Return type for this method
*
* @param name
* Name of the method
*
* @return Newly generated JMethod
*/
// XXX problems caught in M constructor
return m;
}
}
/**
* Returns the set of methods defined in this class.
*/
return methods;
}
/**
* Looks for a method that has the specified method signature
* and return it.
*
* @return
* null if not found.
*/
continue;
if (m.hasSignature(argTypes))
return m;
}
return null;
}
public boolean isClass() {
return true;
}
public boolean isPackage() {
return false;
}
/**
* Add a new nested class to this class.
*
* @param mods
* Modifiers for this class declaration
*
* @param name
* Name of class to be added to this package
*
* @return Newly generated class
*/
throws JClassAlreadyExistsException {
}
/**
* {@inheritDoc}
*
* @deprecated
*/
public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException {
}
throws JClassAlreadyExistsException {
else
else {
// XXX problems caught in the NC constructor
return c;
}
}
/**
* Add a new public nested class to this class.
*/
throws JClassAlreadyExistsException {
}
/**
* Add an interface to this package.
*
* @param mods
* Modifiers for this interface declaration
*
* @param name
* Name of interface to be added to this package
*
* @return Newly generated interface
*/
throws JClassAlreadyExistsException {
}
/**
* Adds a public interface to this package.
*/
throws JClassAlreadyExistsException {
}
/**
* Creates, if necessary, and returns the class javadoc for this
* JDefinedClass
*
* @return JDocComment containing javadocs for this class
*/
return jdoc;
}
/**
* Mark this file as hidden, so that this file won't be
* generated.
*
* <p>
* This feature could be used to generate code that refers
* to class X, without actually generating X.java.
*/
public void hide() {
hideFile = true;
}
public boolean isHidden() {
return hideFile;
}
/**
* Returns an iterator that walks the nested classes defined in this
* class.
*/
else
}
return classes;
}
/**
* Returns all the nested classes defined in this class.
*/
return new JClass[0];
else
}
else
return null;
}
if (annotations != null){
f.g(annotation).nl();
}
if (!interfaces.isEmpty()) {
if (superClass == null)
f.nl();
f.g(interfaces);
f.nl().o();
}
declareBody(f);
}
/**
* prints the body of a class.
*/
boolean first = true;
if (!enumConstantsByName.isEmpty()) {
f.d(c);
first = false;
}
f.p(';').nl();
}
f.d(field);
for (JMethod m : constructors) {
f.nl().d(m);
}
f.nl().d(m);
}
if (directBlock != null)
f.p(directBlock);
}
/**
* Places the given string directly inside the generated class.
*
* generated by CodeModel.
* This method should be used only as the last resort.
*/
if (directBlock == null)
else
directBlock += string;
}
JClassContainer p = outer;
while (!(p instanceof JPackage))
p = p.parentContainer();
return (JPackage) p;
}
return outer;
}
}
}
}
return generifiable.typeParams();
}
return this;
}
/** Adding ability to annotate a class
* @param clazz
* The annotation class to annotate the class with
*/
}
/** Adding ability to annotate a class
* @param clazz
* The annotation class to annotate the class with
*/
if(annotations==null)
annotations.add(a);
return a;
}
}
/**
* {@link JAnnotatable#annotations()}
*/
if (annotations == null)
}
/**
* @return
* the current modifiers of this class.
* Always return non-null valid object.
*/
return mods;
}
}