Interface CtPackage

All Superinterfaces:
Cloneable, CtElement, CtNamedElement, CtQueryable, CtShadowable, CtVisitable, FactoryAccessor, Serializable, SourcePositionHolder
All Known Implementing Classes:
CtModelImpl.CtRootPackage, CtPackageImpl

public interface CtPackage extends CtNamedElement, CtShadowable
This element defines a package declaration. The packages are represented by a tree.
  • Field Details


      static final String PACKAGE_SEPARATOR
      The separator for a string representation of a package.
      See Also:
      Constant Field Values

      static final char PACKAGE_SEPARATOR_CHAR
      See Also:
      Constant Field Values

      static final String TOP_LEVEL_PACKAGE_NAME
      The name for the top level package.
      See Also:
      Constant Field Values
  • Method Details

    • getDeclaringModule

      CtModule getDeclaringModule()
      Gets the declaring module.
    • getDeclaringPackage

      CtPackage getDeclaringPackage()
      Gets the declaring package of the current one. Returns null if the package is not yet in another one.
    • getPackage

      CtPackage getPackage(String name)
      Searches a child package by name.
      name - the simple name of searched package
      the found package or null
    • getPackages

      Set<CtPackage> getPackages()
      Gets the set of included child packages.
    • getQualifiedName

      String getQualifiedName()
      Returns the fully qualified name of this package. This is also known as the package's canonical name.
      the fully qualified name of this package, or the empty string if this is the unnamed package
    • getReference

      CtPackageReference getReference()
      Description copied from interface: CtNamedElement
      Returns the corresponding reference.
      Specified by:
      getReference in interface CtNamedElement
    • getType

      <T extends CtType<?>> T getType(String simpleName)
      Finds a top-level type by name.
      the found type or null
    • getTypes

      Set<CtType<?>> getTypes()
      Returns the set of the top-level types in this package.
    • addType

      <T extends CtPackage> T addType(CtType<?> type)
      Adds a type to this package.
    • removeType

      void removeType(CtType<?> type)
      Removes a type from this package.
    • setPackages

      <T extends CtPackage> T setPackages(Set<CtPackage> pack)
      Sets the children defined in this package
      pack - new set of child packages
    • addPackage

      <T extends CtPackage> T addPackage(CtPackage pack)
      add a subpackage
      pack -
      true if this element changed as a result of the call
    • removePackage

      boolean removePackage(CtPackage pack)
      remove a subpackage
      pack -
      true if this element changed as a result of the call
    • setTypes

      <T extends CtPackage> T setTypes(Set<CtType<?>> types)
      Sets the types defined in the package.
      types - new Set of types
    • clone

      CtPackage clone()
      Description copied from interface: CtElement
      Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtNamedElement
    • isUnnamedPackage

      boolean isUnnamedPackage()
      Returns true if this is an unnamed Java package. See JLS ยง7.4.2. Unnamed Packages.
    • hasPackageInfo

      boolean hasPackageInfo()
      true if the package contains a file
    • isEmpty

      boolean isEmpty()
      true if the package contains no types nor any other packages