Top Description Fields Constructors Methods
com.sun.codemodel

public final Class JPackage

extends Object
implements JDeclaration, JGenerable, JClassContainer, JAnnotatable, Comparable<JPackage>, JDocCommentable
Class Inheritance
All Implemented Interfaces
com.sun.codemodel.JDocCommentable, java.lang.Comparable, com.sun.codemodel.JAnnotatable, com.sun.codemodel.JClassContainer, com.sun.codemodel.JGenerable, com.sun.codemodel.JDeclaration
Imports
java.io.BufferedOutputStream, .BufferedWriter, .File, .IOException, .OutputStream, .PrintWriter, .Writer, java.lang.annotation.Annotation, java.util.ArrayList, .HashMap, .HashSet, .Iterator, .List, .Map, .Set, .TreeMap, .Collection, .Collections

A Java package.

Field Summary

Modifier and TypeField and Description
private List<JAnnotationUse>
annotations

Lazily created list of package annotations.

private final Map<String, JDefinedClass>
classes

List of classes contained within this package keyed by their name.

private JDocComment
jdoc

package javadoc.

private String
name

Name of the package.

private final JCodeModel
private final Set<JResourceFile>
resources

List of resources files inside this package.

private final Map<String, JDefinedClass>
upperCaseClassMap

All JClasss in this package keyed the upper case class name.

Constructor Summary

AccessConstructor and Description
pack-priv
JPackage(String
Name of package
name
,
JCodeModel
The code writer being used to create this package
cw
)

JPackage constructor

Method Summary

Modifier and TypeMethod and Description
public JDefinedClass

Returns:

newly created Annotation Type Declaration
_annotationTypeDeclaration
(String
Name of the annotation Type declaration to be added to this package
name
)

Implements com.sun.codemodel.JClassContainer._annotationTypeDeclaration.

Add an annotationType Declaration to this package

public JDefinedClass

Returns:

Newly generated class
_class
(int
Modifiers for this class declaration
mods
,
String
Name of class to be added to this package
name
)

Implements com.sun.codemodel.JClassContainer._class.

Add a class to this package.

public JDefinedClass
_class(int mods, String name, boolean isInterface)

Implements com.sun.codemodel.JClassContainer._class.

Deprecated

Create a new class or a new interface.

public JDefinedClass
_class(int mods, String name, ClassType classTypeVal)

Implements com.sun.codemodel.JClassContainer._class.

Creates a new class/enum/interface/annotation.

public JDefinedClass
_class(String name)

Implements com.sun.codemodel.JClassContainer._class.

Adds a public class to this package.

public JDefinedClass

Returns:

newly created Enum
_enum
(String
Name of the enum to be added to this package
name
)

Implements com.sun.codemodel.JClassContainer._enum.

Add a public enum to this package

public JDefinedClass

Returns:

null If the class is not yet created.
_getClass
(String name)

Gets a reference to the already created JDefinedClass.

public JDefinedClass

Returns:

Newly generated interface
_interface
(int
Modifiers for this interface declaration
mods
,
String
Name of interface to be added to this package
name
)

Implements com.sun.codemodel.JClassContainer._interface.

Add an interface to this package.

public JDefinedClass
_interface(String name)

Implements com.sun.codemodel.JClassContainer._interface.

Adds a public interface to this package.

public JResourceFile
addResourceFile(JResourceFile rsrc)

Adds a new resource file to this package.

public JAnnotationUse
annotate(JClass clazz)

Implements com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this program element.

public JAnnotationUse
annotate(Class<? extends Annotation> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this program element.

public <W extends JAnnotationWriter<? extends Annotation>> W
annotate2(Class<W> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate2.

Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.

public Collection<JAnnotationUse>
annotations()

Implements com.sun.codemodel.JAnnotatable.annotations.

Read-only live view of all annotations on this

pack-priv void
public Iterator<JDefinedClass>
classes()

Implements com.sun.codemodel.JClassContainer.classes.

Returns an iterator that walks the top-level classes defined in this package.

public int
compareTo(JPackage that)

Implements java.lang.Comparable.compareTo.

Order is based on the lexicological order of the package name.

pack-priv int
private JFormatter
public void
public void
public JPackage
getPackage()

Implements com.sun.codemodel.JClassContainer.getPackage.

Gets the nearest package parent.

public boolean

Returns:

true if this package contains any classes or false otherwise.
hasClasses
()

Checks if this package contains any classes.

public boolean
hasResourceFile(String name)

Checks if a resource of the given name exists.

public boolean
isClass()

Implements com.sun.codemodel.JClassContainer.isClass.

Returns true if the container is a class.

public boolean
isDefined(String classLocalName)

Checks if a given name is already defined as a class/interface

public boolean
isPackage()

Implements com.sun.codemodel.JClassContainer.isPackage.

Returns true if the container is a package.

public boolean
isUnnamed()

Checks if this package is the root, unnamed package.

public JDocComment

Returns:

JDocComment containing javadocs for this class
javadoc
()

Implements com.sun.codemodel.JDocCommentable.javadoc.

Creates, if necessary, and returns the package javadoc for this JDefinedClass.

public String

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"
name
()

Get the name of this package

public JCodeModel
owner()

Implements com.sun.codemodel.JClassContainer.owner.

Return the code model root object being used to create this package.

public JPackage
parent()

Gets the parent package, or null if this class is the root package.

public JClassContainer
public Iterator<JResourceFile>
propertyFiles()

Iterates all resource files in this package.

public JClass
ref(String name)

Reference a class within this package.

public void
remove(JClass c)

Removes a class from this package.

public boolean
removeAnnotation(JAnnotationUse annotation)

Implements com.sun.codemodel.JAnnotatable.removeAnnotation.

Removes annotation from this program element.

public JPackage
subPackage(String pkg)

Gets a reference to a sub package of this package.

pack-priv File
toPath(File dir)

Convert the package name to directory path equivalent

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotationsback to summary
private List<JAnnotationUse> annotations

Lazily created list of package annotations.

classesback to summary
private final Map<String, JDefinedClass> classes

List of classes contained within this package keyed by their name.

jdocback to summary
private JDocComment jdoc

package javadoc.

nameback to summary
private String name

Name of the package. May be the empty string for the root package.

ownerback to summary
private final JCodeModel owner
resourcesback to summary
private final Set<JResourceFile> resources

List of resources files inside this package.

upperCaseClassMapback to summary
private final Map<String, JDefinedClass> upperCaseClassMap

All JClasss 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.

Constructor Detail

JPackageback to summary
pack-priv JPackage(String name, JCodeModel cw)

JPackage constructor

Parameters
name:String

Name of package

cw:JCodeModel

The code writer being used to create this package

Exceptions
IllegalArgumentException:
If each part of the package name is not a valid identifier

Method Detail

_annotationTypeDeclarationback to summary
public JDefinedClass _annotationTypeDeclaration(String name) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._annotationTypeDeclaration.

Add an annotationType Declaration to this package

Parameters
name:String

Name of the annotation Type declaration to be added to this package

Returns:JDefinedClass

newly created Annotation Type Declaration

Annotations
@Override
Exceptions
JClassAlreadyExistsException:
When the specified class/interface was already created.
_classback to summary
public JDefinedClass _class(int mods, String name) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._class.

Add a class to this package.

Parameters
mods:int

Modifiers for this class declaration

name:String

Name of class to be added to this package

Returns:JDefinedClass

Newly generated class

Annotations
@Override
Exceptions
JClassAlreadyExistsException:
When the specified class/interface was already created.
_classback to summary
public JDefinedClass _class(int mods, String name, boolean isInterface) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._class.

Doc from com.sun.codemodel.JClassContainer._class.

Deprecated

Create a new class or a new interface.

Annotations
@Deprecated
@Override
_classback to summary
public JDefinedClass _class(int mods, String name, ClassType classTypeVal) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._class.

Doc from com.sun.codemodel.JClassContainer._class.

Creates a new class/enum/interface/annotation.

Annotations
@Override
_classback to summary
public JDefinedClass _class(String name) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._class.

Adds a public class to this package.

Annotations
@Override
Exceptions
JClassAlreadyExistsException:

Doc from com.sun.codemodel.JClassContainer._class.

When the specified class/interface was already created.

_enumback to summary
public JDefinedClass _enum(String name) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._enum.

Add a public enum to this package

Parameters
name:String

Name of the enum to be added to this package

Returns:JDefinedClass

newly created Enum

Annotations
@Override
Exceptions
JClassAlreadyExistsException:
When the specified class/interface was already created.
_getClassback to summary
public JDefinedClass _getClass(String name)

Gets a reference to the already created JDefinedClass.

Returns:JDefinedClass

null If the class is not yet created.

_interfaceback to summary
public JDefinedClass _interface(int mods, String name) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._interface.

Add an interface to this package.

Parameters
mods:int

Modifiers for this interface declaration

name:String

Name of interface to be added to this package

Returns:JDefinedClass

Newly generated interface

Annotations
@Override
Exceptions
JClassAlreadyExistsException:

Doc from com.sun.codemodel.JClassContainer._interface.

When the specified class/interface was already created.

_interfaceback to summary
public JDefinedClass _interface(String name) throws JClassAlreadyExistsException

Implements com.sun.codemodel.JClassContainer._interface.

Adds a public interface to this package.

Annotations
@Override
Exceptions
JClassAlreadyExistsException:

Doc from com.sun.codemodel.JClassContainer._interface.

When the specified class/interface was already created.

addResourceFileback to summary
public JResourceFile addResourceFile(JResourceFile rsrc)

Adds a new resource file to this package.

annotateback to summary
public JAnnotationUse annotate(JClass clazz)

Implements com.sun.codemodel.JAnnotatable.annotate.

Doc from com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this program element.

Annotations
@Override
annotateback to summary
public JAnnotationUse annotate(Class<? extends Annotation> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate.

Doc from com.sun.codemodel.JAnnotatable.annotate.

Adds an annotation to this program element.

Annotations
@Override
annotate2back to summary
public <W extends JAnnotationWriter<? extends Annotation>> W annotate2(Class<W> clazz)

Implements com.sun.codemodel.JAnnotatable.annotate2.

Doc from com.sun.codemodel.JAnnotatable.annotate2.

Adds an annotation to this program element and returns a type-safe writer to fill in the values of such annotations.

Annotations
@Override
annotationsback to summary
public Collection<JAnnotationUse> annotations()

Implements com.sun.codemodel.JAnnotatable.annotations.

Doc from com.sun.codemodel.JAnnotatable.annotations.

Read-only live view of all annotations on this

Annotations
@Override
buildback to summary
pack-priv void build(CodeWriter src, CodeWriter res) throws IOException
classesback to summary
public Iterator<JDefinedClass> classes()

Implements com.sun.codemodel.JClassContainer.classes.

Returns an iterator that walks the top-level classes defined in this package.

Annotations
@Override
compareToback to summary
public int compareTo(JPackage that)

Implements java.lang.Comparable.compareTo.

Order is based on the lexicological order of the package name.

Annotations
@Override
countArtifactsback to summary
pack-priv int countArtifacts()
createJavaSourceFileWriterback to summary
private JFormatter createJavaSourceFileWriter(CodeWriter src, String className) throws IOException
declareback to summary
public void declare(JFormatter f)

Implements com.sun.codemodel.JDeclaration.declare.

Annotations
@Override
generateback to summary
public void generate(JFormatter f)

Implements com.sun.codemodel.JGenerable.generate.

Annotations
@Override
getPackageback to summary
public JPackage getPackage()

Implements com.sun.codemodel.JClassContainer.getPackage.

Doc from com.sun.codemodel.JClassContainer.getPackage.

Gets the nearest package parent.

If this.isPackage(), then return this.

Annotations
@Override
hasClassesback to summary
public boolean hasClasses()

Checks if this package contains any classes.

Returns:boolean

true if this package contains any classes or false otherwise.

hasResourceFileback to summary
public boolean hasResourceFile(String name)

Checks if a resource of the given name exists.

isClassback to summary
public boolean isClass()

Implements com.sun.codemodel.JClassContainer.isClass.

Doc from com.sun.codemodel.JClassContainer.isClass.

Returns true if the container is a class.

Annotations
@Override
isDefinedback to summary
public boolean isDefined(String classLocalName)

Checks if a given name is already defined as a class/interface

isPackageback to summary
public boolean isPackage()

Implements com.sun.codemodel.JClassContainer.isPackage.

Doc from com.sun.codemodel.JClassContainer.isPackage.

Returns true if the container is a package.

Annotations
@Override
isUnnamedback to summary
public boolean isUnnamed()

Checks if this package is the root, unnamed package.

javadocback to summary
public JDocComment javadoc()

Implements com.sun.codemodel.JDocCommentable.javadoc.

Creates, if necessary, and returns the package javadoc for this JDefinedClass.

Returns:JDocComment

JDocComment containing javadocs for this class

Annotations
@Override
nameback to summary
public String name()

Get the name of this package

Returns:String

The name of this package, or the empty string if this is the null package. For example, this method returns strings like "java.lang"

ownerback to summary
public JCodeModel owner()

Implements com.sun.codemodel.JClassContainer.owner.

Return the code model root object being used to create this package.

Annotations
@Override
parentback to summary
public JPackage parent()

Gets the parent package, or null if this class is the root package.

parentContainerback to summary
public JClassContainer parentContainer()

Implements com.sun.codemodel.JClassContainer.parentContainer.

Doc from com.sun.codemodel.JClassContainer.parentContainer.

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.

Annotations
@Override
propertyFilesback to summary
public Iterator<JResourceFile> propertyFiles()

Iterates all resource files in this package.

refback to summary
public JClass ref(String name) throws ClassNotFoundException

Reference a class within this package.

removeback to summary
public void remove(JClass c)

Removes a class from this package.

removeAnnotationback to summary
public boolean removeAnnotation(JAnnotationUse annotation)

Implements com.sun.codemodel.JAnnotatable.removeAnnotation.

Doc from com.sun.codemodel.JAnnotatable.removeAnnotation.

Removes annotation from this program element.

Annotations
@Override
subPackageback to summary
public JPackage subPackage(String pkg)

Gets a reference to a sub package of this package.

toPathback to summary
pack-priv File toPath(File dir)

Convert the package name to directory path equivalent