001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.codemodel;
021:
022: import java.util.Iterator;
023:
024: /**
025: * The common aspect of a package and a class.
026: */
027: public interface JClassContainer {
028:
029: /**
030: * Returns true if the container is a class.
031: */
032: boolean isClass();
033:
034: /**
035: * Returns true if the container is a package.
036: */
037: boolean isPackage();
038:
039: /**
040: * Add a new class to this package/class.
041: *
042: * @param mods
043: * Modifiers for this class declaration
044: *
045: * @param name
046: * Name of class to be added to this package
047: *
048: * @return Newly generated class
049: *
050: * @exception JClassAlreadyExistsException
051: * When the specified class/interface was already created.
052: */
053: JDefinedClass _class(int mods, String name)
054: throws JClassAlreadyExistsException;
055:
056: /**
057: * Add a new public class to this class/package.
058: *
059: * @exception JClassAlreadyExistsException
060: * When the specified class/interface was already created.
061: */
062: public JDefinedClass _class(String name)
063: throws JClassAlreadyExistsException;
064:
065: /**
066: * Add an interface to this class/package.
067: *
068: * @param mods
069: * Modifiers for this interface declaration
070: *
071: * @param name
072: * Name of interface to be added to this package
073: *
074: * @return Newly generated interface
075: *
076: * @exception JClassAlreadyExistsException
077: * When the specified class/interface was already created.
078: */
079: public JDefinedClass _interface(int mods, String name)
080: throws JClassAlreadyExistsException;
081:
082: /**
083: * Adds a public interface to this package.
084: *
085: * @exception JClassAlreadyExistsException
086: * When the specified class/interface was already created.
087: */
088: public JDefinedClass _interface(String name)
089: throws JClassAlreadyExistsException;
090:
091: /**
092: * Create a new class or a new interface.
093: *
094: * @deprecated
095: * use {@link #_class(int, String, ClassType)}
096: */
097: public JDefinedClass _class(int mods, String name,
098: boolean isInterface) throws JClassAlreadyExistsException;
099:
100: /**
101: * Creates a new class/enum/interface/annotation.
102: */
103: public JDefinedClass _class(int mods, String name, ClassType kind)
104: throws JClassAlreadyExistsException;
105:
106: /**
107: * Returns an iterator that walks the nested classes defined in this
108: * class.
109: */
110: public Iterator<JDefinedClass> classes();
111:
112: /**
113: * Parent JClassContainer.
114: *
115: * If this is a package, this method returns a parent package,
116: * or null if this package is the root package.
117: *
118: * If this is an outer-most class, this method returns a package
119: * to which it belongs.
120: *
121: * If this is an inner class, this method returns the outer
122: * class.
123: */
124: public JClassContainer parentContainer();
125:
126: /**
127: * Gets the nearest package parent.
128: *
129: * <p>
130: * If <tt>this.isPackage()</tt>, then return <tt>this</tt>.
131: */
132: public JPackage getPackage();
133:
134: /**
135: * Get the root code model object.
136: */
137: public JCodeModel owner();
138:
139: /**
140: * Add an annotationType Declaration to this package
141: * @param name
142: * Name of the annotation Type declaration to be added to this package
143: * @return
144: * newly created Annotation Type Declaration
145: * @exception JClassAlreadyExistsException
146: * When the specified class/interface was already created.
147:
148: */
149: public JDefinedClass _annotationTypeDeclaration(String name)
150: throws JClassAlreadyExistsException;
151:
152: /**
153: * Add a public enum to this package
154: * @param name
155: * Name of the enum to be added to this package
156: * @return
157: * newly created Enum
158: * @exception JClassAlreadyExistsException
159: * When the specified class/interface was already created.
160:
161: */
162: public JDefinedClass _enum(String name)
163: throws JClassAlreadyExistsException;
164:
165: }
|