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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List
<JAnnotationUse> Lazily created list of package annotations.private final Map
<String, JDefinedClass> List of classes contained within this package keyed by their name.private JDocComment
package javadoc.private String
Name of the package.private final JCodeModel
private final Set
<JResourceFile> List of resources files inside this package.private final Map
<String, JDefinedClass> AllJClass
s in this package keyed the upper case class name. -
Constructor Summary
Constructors -
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>
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 thisJAnnotatable
(package private) void
build
(CodeWriter src, CodeWriter res) classes()
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.(package private) int
private JFormatter
createJavaSourceFileWriter
(CodeWriter src, String className) void
void
Gets the nearest package parent.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.final 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 packagefinal JCodeModel
owner()
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.subPackage
(String pkg) Gets a reference to a sub package of this package.(package private) File
Convert the package name to directory path equivalent
-
Field Details
-
name
Name of the package. May be the empty string for the root package. -
owner
-
classes
List of classes contained within this package keyed by their name. -
resources
List of resources files inside this package. -
upperCaseClassMap
AllJClass
s in this package keyed the upper case class name. This field is non-null only on Windows, to detect "Foo" and "foo" as a collision. -
annotations
Lazily created list of package annotations. -
jdoc
package javadoc.
-
-
Constructor Details
-
JPackage
JPackage(String name, JCodeModel cw) JPackage constructor- Parameters:
name
- Name of packagecw
- The code writer being used to create this package- Throws:
IllegalArgumentException
- If each part of the package name is not a valid identifier
-
-
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 return this.
- 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
public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException Deprecated.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
-
isDefined
Checks if a given name is already defined as a class/interface -
isUnnamed
public final 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
-
annotations
Description copied from interface:JAnnotatable
Read-only live view of all annotations on thisJAnnotatable
- Specified by:
annotations
in interfaceJAnnotatable
- Returns:
- Can be empty but never null.
-
toPath
Convert the package name to directory path equivalent -
declare
- Specified by:
declare
in interfaceJDeclaration
-
generate
- Specified by:
generate
in interfaceJGenerable
-
build
- Throws:
IOException
-
countArtifacts
int countArtifacts() -
createJavaSourceFileWriter
- Throws:
IOException
-