Class CtPackageImpl

All Implemented Interfaces:
Serializable, Cloneable, FactoryAccessor, SourcePositionHolder, CtElement, CtNamedElement, CtPackage, CtShadowable, CtQueryable, CtVisitable
Direct Known Subclasses:
CtModelImpl.CtRootPackage

public class CtPackageImpl extends CtNamedElementImpl implements CtPackage
The implementation for CtPackage.
Author:
Renaud Pawlak
See Also:
Serialized Form
  • Field Details

  • Constructor Details

    • CtPackageImpl

      public CtPackageImpl()
  • Method Details

    • accept

      public void accept(CtVisitor v)
      Description copied from interface: CtVisitable
      Accepts a visitor
      Specified by:
      accept in interface CtVisitable
    • addPackage

      public <T extends CtPackage> T addPackage(CtPackage pack)
      Description copied from interface: CtPackage
      add a subpackage
      Specified by:
      addPackage in interface CtPackage
      Returns:
      true if this element changed as a result of the call
    • removePackage

      public boolean removePackage(CtPackage pack)
      Description copied from interface: CtPackage
      remove a subpackage
      Specified by:
      removePackage in interface CtPackage
      Returns:
      true if this element changed as a result of the call
    • getDeclaringModule

      public CtModule getDeclaringModule()
      Description copied from interface: CtPackage
      Gets the declaring module.
      Specified by:
      getDeclaringModule in interface CtPackage
    • getDeclaringPackage

      public CtPackage getDeclaringPackage()
      Description copied from interface: CtPackage
      Gets the declaring package of the current one. Returns null if the package is not yet in another one.
      Specified by:
      getDeclaringPackage in interface CtPackage
    • getPackage

      public CtPackage getPackage(String simpleName)
      Description copied from interface: CtPackage
      Searches a child package by name.
      Specified by:
      getPackage in interface CtPackage
      Parameters:
      simpleName - the simple name of searched package
      Returns:
      the found package or null
    • getPackages

      public Set<CtPackage> getPackages()
      Description copied from interface: CtPackage
      Gets the set of included child packages. This method might take linear time (regarding the amount of packages in this package). For emptiness-checks, CtPackage.hasPackages() should be preferred.
      Specified by:
      getPackages in interface CtPackage
    • setSimpleName

      public <T extends CtNamedElement> T setSimpleName(String simpleName)
      Description copied from interface: CtNamedElement
      Sets the simple (unqualified) name of this element.
      Specified by:
      setSimpleName in interface CtNamedElement
      Overrides:
      setSimpleName in class CtNamedElementImpl
    • getQualifiedName

      public String getQualifiedName()
      Description copied from interface: CtPackage
      Returns the fully qualified name of this package. This is also known as the package's canonical name.
      Specified by:
      getQualifiedName in interface CtPackage
      Returns:
      the fully qualified name of this package, or the empty string if this is the unnamed package
    • getType

      public <T extends CtType<?>> T getType(String simpleName)
      Description copied from interface: CtPackage
      Finds a top-level type by name.
      Specified by:
      getType in interface CtPackage
      Returns:
      the found type or null
    • getTypes

      public Set<CtType<?>> getTypes()
      Description copied from interface: CtPackage
      Returns the set of the top-level types in this package. This method might take linear time (regarding the amount of types in this package). For emptiness-checks, CtPackage.hasTypes() should be preferred.
      Specified by:
      getTypes in interface CtPackage
    • setPackages

      public <T extends CtPackage> T setPackages(Set<CtPackage> packs)
      Description copied from interface: CtPackage
      Sets the children defined in this package
      Specified by:
      setPackages in interface CtPackage
      Parameters:
      packs - new set of child packages
    • setTypes

      public <T extends CtPackage> T setTypes(Set<CtType<?>> types)
      Description copied from interface: CtPackage
      Sets the types defined in the package.
      Specified by:
      setTypes in interface CtPackage
      Parameters:
      types - new Set of types
    • getReference

      public CtPackageReference getReference()
      Description copied from interface: CtNamedElement
      Returns the corresponding reference.
      Specified by:
      getReference in interface CtNamedElement
      Specified by:
      getReference in interface CtPackage
      Overrides:
      getReference in class CtNamedElementImpl
    • addType

      public <T extends CtPackage> T addType(CtType<?> type)
      Description copied from interface: CtPackage
      Adds a type to this package.
      Specified by:
      addType in interface CtPackage
    • removeType

      public void removeType(CtType<?> type)
      Description copied from interface: CtPackage
      Removes a type from this package.
      Specified by:
      removeType in interface CtPackage
    • toString

      public String toString()
      Specified by:
      toString in interface CtElement
      Overrides:
      toString in class CtElementImpl
      Returns:
      the source code of this element according to the setting of Environment.getPrettyPrintingMode().
    • isShadow

      public boolean isShadow()
      Description copied from interface: CtShadowable
      When an element isn't present in the factory (created in another factory), this element is considered as "shadow". e.g., a shadow element can be a CtType of java.lang.Class built when we call CtTypeReference.getTypeDeclaration() on a reference of java.lang.Class.
      Specified by:
      isShadow in interface CtShadowable
      Returns:
      true if the element is a shadow element, otherwise false.
    • setShadow

      public <E extends CtShadowable> E setShadow(boolean isShadow)
      Description copied from interface: CtShadowable
      Marks an element as shadow. To know what is a shadow element, see the javadoc of CtShadowable.isShadow().
      Specified by:
      setShadow in interface CtShadowable
    • clone

      public 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
      Specified by:
      clone in interface CtPackage
      Overrides:
      clone in class CtNamedElementImpl
    • isUnnamedPackage

      public boolean isUnnamedPackage()
      Description copied from interface: CtPackage
      Returns true if this is an unnamed Java package. See JLS ยง7.4.2. Unnamed Packages.
      Specified by:
      isUnnamedPackage in interface CtPackage
    • hasPackageInfo

      public boolean hasPackageInfo()
      Specified by:
      hasPackageInfo in interface CtPackage
      Returns:
      true if the package contains a package-info.java file
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface CtPackage
      Returns:
      true if the package contains no types nor any other packages
    • hasTypes

      public boolean hasTypes()
      Description copied from interface: CtPackage
      Returns true if this package contains any types. This method is expected to provide constant-time performance and should be preferred over CtPackage.getTypes().isEmpty().
      Specified by:
      hasTypes in interface CtPackage
      Returns:
      true if the package contains any types.
      See Also:
      CtPackage.getTypes()
    • hasPackages

      public boolean hasPackages()
      Description copied from interface: CtPackage
      Returns true if this package contains any sub-packages. This method is expected to provide constant-time performance and should be preferred over CtPackage.getPackages().isEmpty().
      Specified by:
      hasPackages in interface CtPackage
      Returns:
      true if the package contains any sub-packages
      See Also:
      CtPackage.getPackages()