Package com.sun.codemodel
Class JPackage
- java.lang.Object
-
- com.sun.codemodel.JPackage
-
- All Implemented Interfaces:
JAnnotatable,JClassContainer,JDeclaration,JDocCommentable,JGenerable,Comparable<JPackage>
public final class JPackage extends Object implements JDeclaration, JGenerable, JClassContainer, JAnnotatable, Comparable<JPackage>, JDocCommentable
A Java package.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JDefinedClass_annotationTypeDeclaration(String name)Add an annotationType Declaration to this packageJDefinedClass_class(int mods, String name)Add a class to this package.JDefinedClass_class(int mods, String name, boolean isInterface)Deprecated.JDefinedClass_class(int mods, String name, ClassType classTypeVal)Creates a new class/enum/interface/annotation.JDefinedClass_class(String name)Adds a public class to this package.JDefinedClass_enum(String name)Add a public enum to this packageJDefinedClass_getClass(String name)Gets a reference to the already createdJDefinedClass.JDefinedClass_interface(int mods, String name)Add an interface to this package.JDefinedClass_interface(String name)Adds a public interface to this package.JResourceFileaddResourceFile(JResourceFile rsrc)Adds a new resource file to this package.JAnnotationUseannotate(JClass clazz)Adds an annotation to this program element.JAnnotationUseannotate(Class<? extends Annotation> clazz)Adds an annotation to this program element.<W extends JAnnotationWriter<? extends Annotation>>
Wannotate2(Class<W> clazz)Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.Collection<JAnnotationUse>annotations()Read-only live view of all annotations on thisJAnnotatableIterator<JDefinedClass>classes()Returns an iterator that walks the top-level classes defined in this package.intcompareTo(JPackage that)Order is based on the lexicological order of the package name.voiddeclare(JFormatter f)voidgenerate(JFormatter f)JPackagegetPackage()Gets the nearest package parent.booleanhasClasses()Checks if this package contains any classes.booleanhasResourceFile(String name)Checks if a resource of the given name exists.booleanisClass()Returns true if the container is a class.booleanisDefined(String classLocalName)Checks if a given name is already defined as a class/interfacebooleanisPackage()Returns true if the container is a package.booleanisUnnamed()Checks if this package is the root, unnamed package.JDocCommentjavadoc()Creates, if necessary, and returns the package javadoc for this JDefinedClass.Stringname()Get the name of this packageJCodeModelowner()Return the code model root object being used to create this package.JPackageparent()Gets the parent package, or null if this class is the root package.JClassContainerparentContainer()Parent JClassContainer.Iterator<JResourceFile>propertyFiles()Iterates all resource files in this package.JClassref(String name)Reference a class within this package.voidremove(JClass c)Removes a class from this package.booleanremoveAnnotation(JAnnotationUse annotation)Removes annotation from this program element.JPackagesubPackage(String pkg)Gets a reference to a sub package of this package.
-
-
-
Method Detail
-
parentContainer
public JClassContainer parentContainer()
Description copied from interface:JClassContainerParent JClassContainer. If this is a package, this method returns a parent package, or null if this package is the root package. If this is an outer-most class, this method returns a package to which it belongs. If this is an inner class, this method returns the outer class.- Specified by:
parentContainerin interfaceJClassContainer
-
parent
public JPackage parent()
Gets the parent package, or null if this class is the root package.- Returns:
-
isClass
public boolean isClass()
Description copied from interface:JClassContainerReturns true if the container is a class.- Specified by:
isClassin interfaceJClassContainer
-
isPackage
public boolean isPackage()
Description copied from interface:JClassContainerReturns true if the container is a package.- Specified by:
isPackagein interfaceJClassContainer
-
getPackage
public JPackage getPackage()
Description copied from interface:JClassContainerGets the nearest package parent.If
this.isPackage(), then returnthis.- Specified by:
getPackagein interfaceJClassContainer
-
_class
public JDefinedClass _class(int mods, String name) throws JClassAlreadyExistsException
Add a class to this package.- Specified by:
_classin interfaceJClassContainer- Parameters:
mods- Modifiers for this class declarationname- Name of class to be added to this package- Returns:
- Newly generated class
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_class
@Deprecated public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException
Deprecated.Create a new class or a new interface.- Specified by:
_classin interfaceJClassContainer- Throws:
JClassAlreadyExistsException
-
_class
public JDefinedClass _class(int mods, String name, ClassType classTypeVal) throws JClassAlreadyExistsException
Description copied from interface:JClassContainerCreates a new class/enum/interface/annotation.- Specified by:
_classin interfaceJClassContainer- Throws:
JClassAlreadyExistsException
-
_class
public JDefinedClass _class(String name) throws JClassAlreadyExistsException
Adds a public class to this package.- Specified by:
_classin interfaceJClassContainer- Parameters:
name-- Returns:
- Throws:
JClassAlreadyExistsException
-
_getClass
public JDefinedClass _getClass(String name)
Gets a reference to the already createdJDefinedClass.- Parameters:
name-- Returns:
- null If the class is not yet created.
-
compareTo
public int compareTo(JPackage that)
Order is based on the lexicological order of the package name.- Specified by:
compareToin interfaceComparable<JPackage>- Parameters:
that-
-
_interface
public JDefinedClass _interface(int mods, String name) throws JClassAlreadyExistsException
Add an interface to this package.- Specified by:
_interfacein interfaceJClassContainer- Parameters:
mods- Modifiers for this interface declarationname- Name of interface to be added to this package- Returns:
- Newly generated interface
- Throws:
JClassAlreadyExistsException
-
_interface
public JDefinedClass _interface(String name) throws JClassAlreadyExistsException
Adds a public interface to this package.- Specified by:
_interfacein interfaceJClassContainer- Parameters:
name-- Returns:
- Throws:
JClassAlreadyExistsException
-
_annotationTypeDeclaration
public JDefinedClass _annotationTypeDeclaration(String name) throws JClassAlreadyExistsException
Add an annotationType Declaration to this package- Specified by:
_annotationTypeDeclarationin interfaceJClassContainer- Parameters:
name- Name of the annotation Type declaration to be added to this package- Returns:
- newly created Annotation Type Declaration
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
_enum
public JDefinedClass _enum(String name) throws JClassAlreadyExistsException
Add a public enum to this package- Specified by:
_enumin interfaceJClassContainer- Parameters:
name- Name of the enum to be added to this package- Returns:
- newly created Enum
- Throws:
JClassAlreadyExistsException- When the specified class/interface was already created.
-
addResourceFile
public JResourceFile addResourceFile(JResourceFile rsrc)
Adds a new resource file to this package.- Parameters:
rsrc-- Returns:
-
hasResourceFile
public boolean hasResourceFile(String name)
Checks if a resource of the given name exists.- Parameters:
name-- Returns:
-
propertyFiles
public Iterator<JResourceFile> propertyFiles()
Iterates all resource files in this package.- Returns:
-
javadoc
public JDocComment javadoc()
Creates, if necessary, and returns the package javadoc for this JDefinedClass.- Specified by:
javadocin interfaceJDocCommentable- Returns:
- JDocComment containing javadocs for this class
-
remove
public void remove(JClass c)
Removes a class from this package.- Parameters:
c-
-
ref
public JClass ref(String name) throws ClassNotFoundException
Reference a class within this package.- Parameters:
name-- Returns:
- Throws:
ClassNotFoundException
-
subPackage
public JPackage subPackage(String pkg)
Gets a reference to a sub package of this package.- Parameters:
pkg-- Returns:
-
classes
public Iterator<JDefinedClass> classes()
Returns an iterator that walks the top-level classes defined in this package.- Specified by:
classesin interfaceJClassContainer- Returns:
-
hasClasses
public boolean hasClasses()
Checks if this package contains any classes.- Returns:
trueif this package contains any classes orfalseotherwise.
-
isDefined
public boolean isDefined(String classLocalName)
Checks if a given name is already defined as a class/interface- Parameters:
classLocalName-- Returns:
-
isUnnamed
public final boolean isUnnamed()
Checks if this package is the root, unnamed package.- Returns:
-
name
public String name()
Get the name of this package- Returns:
- The name of this package, or the empty string if this is the null
package. For example, this method returns strings like
"java.lang"
-
owner
public final JCodeModel owner()
Return the code model root object being used to create this package.- Specified by:
ownerin interfaceJClassContainer- Returns:
-
annotate
public JAnnotationUse annotate(JClass clazz)
Description copied from interface:JAnnotatableAdds an annotation to this program element.- Specified by:
annotatein interfaceJAnnotatable- Parameters:
clazz- The annotation class to annotate the program element with
-
annotate
public JAnnotationUse annotate(Class<? extends Annotation> clazz)
Description copied from interface:JAnnotatableAdds an annotation to this program element.- Specified by:
annotatein interfaceJAnnotatable- Parameters:
clazz- The annotation class to annotate the program element with
-
annotate2
public <W extends JAnnotationWriter<? extends Annotation>> W annotate2(Class<W> clazz)
Description copied from interface:JAnnotatableAdds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.- Specified by:
annotate2in interfaceJAnnotatable- Returns:
-
removeAnnotation
public boolean removeAnnotation(JAnnotationUse annotation)
Description copied from interface:JAnnotatableRemoves annotation from this program element.- Specified by:
removeAnnotationin interfaceJAnnotatable- Parameters:
annotation- The annotation to be removed from the program element
-
annotations
public Collection<JAnnotationUse> annotations()
Description copied from interface:JAnnotatableRead-only live view of all annotations on thisJAnnotatable- Specified by:
annotationsin interfaceJAnnotatable- Returns:
- Can be empty but never null.
-
declare
public void declare(JFormatter f)
- Specified by:
declarein interfaceJDeclaration
-
generate
public void generate(JFormatter f)
- Specified by:
generatein interfaceJGenerable
-
-