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
Modifier and TypeMethodDescriptionAdd an annotationType Declaration to this packageAdd a class to this package.Deprecated.Creates a new class/enum/interface/annotation.Adds a public class to this package.Add a public enum to this packageGets a reference to the already createdJDefinedClass
._interface
(int mods, String name) Add an interface to this package._interface
(String name) Adds a public interface to this package.addResourceFile
(JResourceFile rsrc) Adds a new resource file to this package.Adds an annotation to this program element.annotate
(Class<? extends Annotation> clazz) Adds an annotation to this program element.<W extends JAnnotationWriter<? extends Annotation>>
WAdds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.Read-only live view of all annotations on thisclasses()
Returns an iterator that walks the top-level classes defined in this package.int
Order is based on the lexicological order of the package name.void
void
Gets the nearest package parent.boolean
Checks if this package contains any classes.boolean
hasResourceFile
(String name) Checks if a resource of the given name exists.boolean
isClass()
Returns true if the container is a class.boolean
Checks if a given name is already defined as a class/interfaceboolean
Returns true if the container is a package.boolean
Checks if this package is the root, unnamed package.javadoc()
Creates, if necessary, and returns the package javadoc for this JDefinedClass.name()
Get the name of this packageowner()
Return the code model root object being used to create this package.parent()
Gets the parent package, or null if this class is the root package.Parent JClassContainer.Iterates all resource files in this package.Reference a class within this package.void
Removes a class from this package.boolean
removeAnnotation
(JAnnotationUse annotation) Removes annotation from this program element.subPackage
(String pkg) Gets a reference to a sub package of this package.
-
Method Details
-
parentContainer
Description copied from interface:JClassContainer
Parent 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:
parentContainer
in interfaceJClassContainer
-
parent
Gets the parent package, or null if this class is the root package. -
isClass
public boolean isClass()Description copied from interface:JClassContainer
Returns true if the container is a class.- Specified by:
isClass
in interfaceJClassContainer
-
isPackage
public boolean isPackage()Description copied from interface:JClassContainer
Returns true if the container is a package.- Specified by:
isPackage
in interfaceJClassContainer
-
getPackage
Description copied from interface:JClassContainer
Gets the nearest package parent.If
this.isPackage()
, then returnthis
.- Specified by:
getPackage
in interfaceJClassContainer
-
_class
Add a class to this package.- Specified by:
_class
in 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.Description copied from interface:JClassContainer
Create a new class or a new interface.- Specified by:
_class
in interfaceJClassContainer
- Throws:
JClassAlreadyExistsException
-
_class
public JDefinedClass _class(int mods, String name, ClassType classTypeVal) throws JClassAlreadyExistsException Description copied from interface:JClassContainer
Creates a new class/enum/interface/annotation.- Specified by:
_class
in interfaceJClassContainer
- Throws:
JClassAlreadyExistsException
-
_class
Adds a public class to this package.- Specified by:
_class
in interfaceJClassContainer
- Throws:
JClassAlreadyExistsException
- When the specified class/interface was already created.
-
_getClass
Gets a reference to the already createdJDefinedClass
.- Returns:
- null If the class is not yet created.
-
compareTo
Order is based on the lexicological order of the package name.- Specified by:
compareTo
in interfaceComparable<JPackage>
-
_interface
Add an interface to this package.- Specified by:
_interface
in interfaceJClassContainer
- Parameters:
mods
- Modifiers for this interface declarationname
- Name of interface to be added to this package- Returns:
- Newly generated interface
- Throws:
JClassAlreadyExistsException
- When the specified class/interface was already created.
-
_interface
Adds a public interface to this package.- Specified by:
_interface
in interfaceJClassContainer
- Throws:
JClassAlreadyExistsException
- When the specified class/interface was already created.
-
_annotationTypeDeclaration
Add an annotationType Declaration to this package- Specified by:
_annotationTypeDeclaration
in 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
Add a public enum to this package- Specified by:
_enum
in 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
Adds a new resource file to this package. -
hasResourceFile
Checks if a resource of the given name exists. -
propertyFiles
Iterates all resource files in this package. -
javadoc
Creates, if necessary, and returns the package javadoc for this JDefinedClass.- Specified by:
javadoc
in interfaceJDocCommentable
- Returns:
- JDocComment containing javadocs for this class
-
remove
Removes a class from this package. -
ref
Reference a class within this package.- Throws:
ClassNotFoundException
-
subPackage
Gets a reference to a sub package of this package. -
classes
Returns an iterator that walks the top-level classes defined in this package.- Specified by:
classes
in interfaceJClassContainer
-
hasClasses
public boolean hasClasses()Checks if this package contains any classes.- Returns:
true
if this package contains any classes orfalse
otherwise.
-
isDefined
Checks if a given name is already defined as a class/interface -
isUnnamed
public boolean isUnnamed()Checks if this package is the root, unnamed package. -
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
Return the code model root object being used to create this package.- Specified by:
owner
in interfaceJClassContainer
-
annotate
Description copied from interface:JAnnotatable
Adds an annotation to this program element.- Specified by:
annotate
in interfaceJAnnotatable
- Parameters:
clazz
- The annotation class to annotate the program element with
-
annotate
Description copied from interface:JAnnotatable
Adds an annotation to this program element.- Specified by:
annotate
in interfaceJAnnotatable
- Parameters:
clazz
- The annotation class to annotate the program element with
-
annotate2
Description copied from interface:JAnnotatable
Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.- Specified by:
annotate2
in interfaceJAnnotatable
-
removeAnnotation
Description copied from interface:JAnnotatable
Removes annotation from this program element.- Specified by:
removeAnnotation
in interfaceJAnnotatable
- Parameters:
annotation
- The annotation to be removed from the program element
-
annotations
Description copied from interface:JAnnotatable
Read-only live view of all annotations on this- Specified by:
annotations
in interfaceJAnnotatable
- Returns:
- Can be empty but never null.
-
declare
- Specified by:
declare
in interfaceJDeclaration
-
generate
- Specified by:
generate
in interfaceJGenerable
-