public final class JPackage extends java.lang.Object implements JDeclaration, JGenerable, JClassContainer, JAnnotatable, java.lang.Comparable<JPackage>, JDocCommentable
Modifier and Type | Field and Description |
---|---|
private java.util.List<JAnnotationUse> |
annotations
Lazily created list of package annotations.
|
private java.util.Map<java.lang.String,JDefinedClass> |
classes
List of classes contained within this package keyed by their name.
|
private JDocComment |
jdoc
package javadoc.
|
private java.lang.String |
name
Name of the package.
|
private JCodeModel |
owner |
private java.util.Set<JResourceFile> |
resources
List of resources files inside this package.
|
private java.util.Map<java.lang.String,JDefinedClass> |
upperCaseClassMap
All
JClass s in this package keyed the upper case class name. |
Constructor and Description |
---|
JPackage(java.lang.String name,
JCodeModel cw)
JPackage constructor
|
Modifier and Type | Method and Description |
---|---|
JDefinedClass |
_annotationTypeDeclaration(java.lang.String name)
Add an annotationType Declaration to this package
|
JDefinedClass |
_class(int mods,
java.lang.String name)
Add a class to this package.
|
JDefinedClass |
_class(int mods,
java.lang.String name,
boolean isInterface)
Deprecated.
|
JDefinedClass |
_class(int mods,
java.lang.String name,
ClassType classTypeVal)
Creates a new class/enum/interface/annotation.
|
JDefinedClass |
_class(java.lang.String name)
Adds a public class to this package.
|
JDefinedClass |
_enum(java.lang.String name)
Add a public enum to this package
|
JDefinedClass |
_getClass(java.lang.String name)
Gets a reference to the already created
JDefinedClass . |
JDefinedClass |
_interface(int mods,
java.lang.String name)
Add an interface to this package.
|
JDefinedClass |
_interface(java.lang.String name)
Adds a public interface to this package.
|
JResourceFile |
addResourceFile(JResourceFile rsrc)
Adds a new resource file to this package.
|
JAnnotationUse |
annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
Adds an annotation to this program element.
|
JAnnotationUse |
annotate(JClass clazz)
Adds an annotation to this program element.
|
<W extends JAnnotationWriter> |
annotate2(java.lang.Class<W> clazz)
Adds an annotation to this program element
and returns a type-safe writer to fill in the values of such annotations.
|
java.util.Collection<JAnnotationUse> |
annotations()
Read-only live view of all annotations on this
JAnnotatable |
(package private) void |
build(CodeWriter src,
CodeWriter res) |
java.util.Iterator<JDefinedClass> |
classes()
Returns an iterator that walks the top-level classes defined in this
package.
|
int |
compareTo(JPackage that)
Order is based on the lexicological order of the package name.
|
(package private) int |
countArtifacts() |
private JFormatter |
createJavaSourceFileWriter(CodeWriter src,
java.lang.String className) |
void |
declare(JFormatter f) |
void |
generate(JFormatter f) |
JPackage |
getPackage()
Gets the nearest package parent.
|
boolean |
hasResourceFile(java.lang.String name)
Checks if a resource of the given name exists.
|
boolean |
isClass()
Returns true if the container is a class.
|
boolean |
isDefined(java.lang.String classLocalName)
Checks if a given name is already defined as a class/interface
|
boolean |
isPackage()
Returns true if the container is a package.
|
boolean |
isUnnamed()
Checks if this package is the root, unnamed package.
|
JDocComment |
javadoc()
Creates, if necessary, and returns the package javadoc for this
JDefinedClass.
|
java.lang.String |
name()
Get the name of this package
|
JCodeModel |
owner()
Return the code model root object being used to create this package.
|
JPackage |
parent()
Gets the parent package, or null if this class is the root package.
|
JClassContainer |
parentContainer()
Parent JClassContainer.
|
java.util.Iterator<JResourceFile> |
propertyFiles()
Iterates all resource files in this package.
|
JClass |
ref(java.lang.String name)
Reference a class within this package.
|
void |
remove(JClass c)
Removes a class from this package.
|
JPackage |
subPackage(java.lang.String pkg)
Gets a reference to a sub package of this package.
|
(package private) java.io.File |
toPath(java.io.File dir)
Convert the package name to directory path equivalent
|
private java.lang.String name
private final JCodeModel owner
private final java.util.Map<java.lang.String,JDefinedClass> classes
private final java.util.Set<JResourceFile> resources
private final java.util.Map<java.lang.String,JDefinedClass> upperCaseClassMap
JClass
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.private java.util.List<JAnnotationUse> annotations
private JDocComment jdoc
JPackage(java.lang.String name, JCodeModel cw)
name
- Name of packagecw
- The code writer being used to create this packagejava.lang.IllegalArgumentException
- If each part of the package name is not a valid identifierpublic JClassContainer parentContainer()
JClassContainer
parentContainer
in interface JClassContainer
public JPackage parent()
public boolean isClass()
JClassContainer
isClass
in interface JClassContainer
public boolean isPackage()
JClassContainer
isPackage
in interface JClassContainer
public JPackage getPackage()
JClassContainer
If this.isPackage(), then return this.
getPackage
in interface JClassContainer
public JDefinedClass _class(int mods, java.lang.String name) throws JClassAlreadyExistsException
_class
in interface JClassContainer
mods
- Modifiers for this class declarationname
- Name of class to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _class(int mods, java.lang.String name, boolean isInterface) throws JClassAlreadyExistsException
_class
in interface JClassContainer
JClassAlreadyExistsException
public JDefinedClass _class(int mods, java.lang.String name, ClassType classTypeVal) throws JClassAlreadyExistsException
JClassContainer
_class
in interface JClassContainer
JClassAlreadyExistsException
public JDefinedClass _class(java.lang.String name) throws JClassAlreadyExistsException
_class
in interface JClassContainer
JClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _getClass(java.lang.String name)
JDefinedClass
.public int compareTo(JPackage that)
compareTo
in interface java.lang.Comparable<JPackage>
public JDefinedClass _interface(int mods, java.lang.String name) throws JClassAlreadyExistsException
_interface
in interface JClassContainer
mods
- Modifiers for this interface declarationname
- Name of interface to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _interface(java.lang.String name) throws JClassAlreadyExistsException
_interface
in interface JClassContainer
JClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _annotationTypeDeclaration(java.lang.String name) throws JClassAlreadyExistsException
_annotationTypeDeclaration
in interface JClassContainer
name
- Name of the annotation Type declaration to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JDefinedClass _enum(java.lang.String name) throws JClassAlreadyExistsException
_enum
in interface JClassContainer
name
- Name of the enum to be added to this packageJClassAlreadyExistsException
- When the specified class/interface was already created.public JResourceFile addResourceFile(JResourceFile rsrc)
public boolean hasResourceFile(java.lang.String name)
public java.util.Iterator<JResourceFile> propertyFiles()
public JDocComment javadoc()
javadoc
in interface JDocCommentable
public void remove(JClass c)
public JClass ref(java.lang.String name) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public JPackage subPackage(java.lang.String pkg)
public java.util.Iterator<JDefinedClass> classes()
classes
in interface JClassContainer
public boolean isDefined(java.lang.String classLocalName)
public final boolean isUnnamed()
public java.lang.String name()
"java.lang"
public final JCodeModel owner()
owner
in interface JClassContainer
public JAnnotationUse annotate(JClass clazz)
JAnnotatable
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the program element withpublic JAnnotationUse annotate(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
JAnnotatable
annotate
in interface JAnnotatable
clazz
- The annotation class to annotate the program element withpublic <W extends JAnnotationWriter> W annotate2(java.lang.Class<W> clazz)
JAnnotatable
annotate2
in interface JAnnotatable
public java.util.Collection<JAnnotationUse> annotations()
JAnnotatable
JAnnotatable
annotations
in interface JAnnotatable
java.io.File toPath(java.io.File dir)
public void declare(JFormatter f)
declare
in interface JDeclaration
public void generate(JFormatter f)
generate
in interface JGenerable
void build(CodeWriter src, CodeWriter res) throws java.io.IOException
java.io.IOException
int countArtifacts()
private JFormatter createJavaSourceFileWriter(CodeWriter src, java.lang.String className) throws java.io.IOException
java.io.IOException