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

    • PACKAGE_SEPARATOR

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

      static final char PACKAGE_SEPARATOR_CHAR
      See Also:
      Constant Field Values
    • TOP_LEVEL_PACKAGE_NAME

      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.
      Parameters:
      name - the simple name of searched package
      Returns:
      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.
      Returns:
      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.
      Returns:
      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
      Parameters:
      pack - new set of child packages
    • addPackage

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

      boolean removePackage(CtPackage pack)
      remove a subpackage
      Parameters:
      pack -
      Returns:
      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.
      Parameters:
      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()
      Returns:
      true if the package contains a package-info.java file
    • isEmpty

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