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 thisJAnnotatableclasses()Returns an iterator that walks the top-level classes defined in this package.intOrder is based on the lexicological order of the package name.voidvoidGets the nearest package parent.booleanChecks 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.booleanChecks if a given name is already defined as a class/interfacebooleanReturns true if the container is a package.final booleanChecks 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 JCodeModelowner()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.voidRemoves a class from this package.booleanremoveAnnotation(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: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
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
Description copied from interface:JClassContainerGets the nearest package parent.If
this.isPackage(), then returnthis.- Specified by:
getPackagein interfaceJClassContainer
-
_class
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
Adds a public class to this package.- Specified by:
_classin interfaceJClassContainer- Parameters:
name-- Returns:
- Throws:
JClassAlreadyExistsException
-
_getClass
Gets a reference to the already createdJDefinedClass.- Parameters:
name-- Returns:
- null If the class is not yet created.
-
compareTo
Order is based on the lexicological order of the package name.- Specified by:
compareToin interfaceComparable<JPackage>- Parameters:
that-
-
_interface
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
Adds a public interface to this package.- Specified by:
_interfacein interfaceJClassContainer- Parameters:
name-- Returns:
- Throws:
JClassAlreadyExistsException
-
_annotationTypeDeclaration
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
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
Adds a new resource file to this package.- Parameters:
rsrc-- Returns:
-
hasResourceFile
Checks if a resource of the given name exists.- Parameters:
name-- Returns:
-
propertyFiles
Iterates all resource files in this package.- Returns:
-
javadoc
Creates, if necessary, and returns the package javadoc for this JDefinedClass.- Specified by:
javadocin interfaceJDocCommentable- Returns:
- JDocComment containing javadocs for this class
-
remove
Removes a class from this package.- Parameters:
c-
-
ref
Reference a class within this package.- Parameters:
name-- Returns:
- Throws:
ClassNotFoundException
-
subPackage
Gets a reference to a sub package of this package.- Parameters:
pkg-- Returns:
-
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
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
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:
ownerin interfaceJClassContainer- Returns:
-
annotate
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
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
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
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
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
- Specified by:
declarein interfaceJDeclaration
-
generate
- Specified by:
generatein interfaceJGenerable
-