Class JPackage

    • Field Detail

      • name

        private java.lang.String name
        Name of the package. May be the empty string for the root package.
      • classes

        private final java.util.Map<java.lang.String,​JDefinedClass> classes
        List of classes contained within this package keyed by their name.
      • resources

        private final java.util.Set<JResourceFile> resources
        List of resources files inside this package.
      • upperCaseClassMap

        private final java.util.Map<java.lang.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.
      • annotations

        private java.util.List<JAnnotationUse> annotations
        Lazily created list of package annotations.
    • Constructor Detail

      • JPackage

        JPackage​(java.lang.String name,
                 JCodeModel cw)
        JPackage constructor
        Parameters:
        name - Name of package
        cw - The code writer being used to create this package
        Throws:
        java.lang.IllegalArgumentException - If each part of the package name is not a valid identifier
    • Method Detail

      • parentContainer

        public JClassContainer 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 interface JClassContainer
      • parent

        public JPackage parent()
        Gets the parent package, or null if this class is the root package.
      • _getClass

        public JDefinedClass _getClass​(java.lang.String name)
        Gets a reference to the already created JDefinedClass.
        Returns:
        null If the class is not yet created.
      • compareTo

        public int compareTo​(JPackage that)
        Order is based on the lexicological order of the package name.
        Specified by:
        compareTo in interface java.lang.Comparable<JPackage>
      • hasResourceFile

        public boolean hasResourceFile​(java.lang.String name)
        Checks if a resource of the given name exists.
      • propertyFiles

        public java.util.Iterator<JResourceFile> propertyFiles()
        Iterates all resource files in this package.
      • javadoc

        public JDocComment javadoc()
        Creates, if necessary, and returns the package javadoc for this JDefinedClass.
        Specified by:
        javadoc in interface JDocCommentable
        Returns:
        JDocComment containing javadocs for this class
      • remove

        public void remove​(JClass c)
        Removes a class from this package.
      • ref

        public JClass ref​(java.lang.String name)
                   throws java.lang.ClassNotFoundException
        Reference a class within this package.
        Throws:
        java.lang.ClassNotFoundException
      • subPackage

        public JPackage subPackage​(java.lang.String pkg)
        Gets a reference to a sub package of this package.
      • classes

        public java.util.Iterator<JDefinedClass> classes()
        Returns an iterator that walks the top-level classes defined in this package.
        Specified by:
        classes in interface JClassContainer
      • isDefined

        public boolean isDefined​(java.lang.String classLocalName)
        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

        public java.lang.String 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

        public final JCodeModel owner()
        Return the code model root object being used to create this package.
        Specified by:
        owner in interface JClassContainer
      • annotate

        public JAnnotationUse annotate​(JClass clazz)
        Description copied from interface: JAnnotatable
        Adds an annotation to this program element.
        Specified by:
        annotate in interface JAnnotatable
        Parameters:
        clazz - The annotation class to annotate the program element with
      • annotate

        public JAnnotationUse annotate​(java.lang.Class<? extends java.lang.annotation.Annotation> clazz)
        Description copied from interface: JAnnotatable
        Adds an annotation to this program element.
        Specified by:
        annotate in interface JAnnotatable
        Parameters:
        clazz - The annotation class to annotate the program element with
      • annotate2

        public <W extends JAnnotationWriter> W annotate2​(java.lang.Class<W> clazz)
        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 interface JAnnotatable
      • toPath

        java.io.File toPath​(java.io.File dir)
        Convert the package name to directory path equivalent
      • build

        void build​(CodeWriter src,
                   CodeWriter res)
            throws java.io.IOException
        Throws:
        java.io.IOException
      • countArtifacts

        int countArtifacts()
      • createJavaSourceFileWriter

        private JFormatter createJavaSourceFileWriter​(CodeWriter src,
                                                      java.lang.String className)
                                               throws java.io.IOException
        Throws:
        java.io.IOException