Package spoon.reflect.declaration
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 Summary
Fields Modifier and Type Field Description static String
PACKAGE_SEPARATOR
The separator for a string representation of a package.static char
PACKAGE_SEPARATOR_CHAR
static String
TOP_LEVEL_PACKAGE_NAME
The name for the top level package.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends CtPackage>
TaddPackage(CtPackage pack)
add a subpackage<T extends CtPackage>
TaddType(CtType<?> type)
Adds a type to this package.CtPackage
clone()
Clone the element which calls this method in a new object.CtModule
getDeclaringModule()
Gets the declaring module.CtPackage
getDeclaringPackage()
Gets the declaring package of the current one.CtPackage
getPackage(String name)
Searches a child package by name.Set<CtPackage>
getPackages()
Gets the set of included child packages.String
getQualifiedName()
Returns the fully qualified name of this package.CtPackageReference
getReference()
Returns the corresponding reference.<T extends CtType<?>>
TgetType(String simpleName)
Finds a top-level type by name.Set<CtType<?>>
getTypes()
Returns the set of the top-level types in this package.boolean
hasPackageInfo()
boolean
isEmpty()
boolean
isUnnamedPackage()
Returnstrue
if this is an unnamed Java package.boolean
removePackage(CtPackage pack)
remove a subpackagevoid
removeType(CtType<?> type)
Removes a type from this package.<T extends CtPackage>
TsetPackages(Set<CtPackage> pack)
Sets the children defined in this package<T extends CtPackage>
TsetTypes(Set<CtType<?>> types)
Sets the types defined in the package.-
Methods inherited from interface spoon.reflect.declaration.CtElement
addAnnotation, addComment, asIterable, delete, descendantIterator, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hasParent, isImplicit, isParentInitialized, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setImplicit, setParent, setPosition, setPositions, setValueByRole, toString, toStringDebug, updateAllParentsBelow
-
Methods inherited from interface spoon.reflect.declaration.CtNamedElement
getSimpleName, setSimpleName
-
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
-
Methods inherited from interface spoon.reflect.declaration.CtShadowable
isShadow, setShadow
-
Methods inherited from interface spoon.reflect.visitor.CtVisitable
accept
-
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
-
-
-
Field Detail
-
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 Detail
-
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
-
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 interfaceCtNamedElement
-
getType
<T extends CtType<?>> T getType(String simpleName)
Finds a top-level type by name.- Returns:
- the found type or null
-
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 methodsRefactoring.copyType(CtType)
andRefactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.- Specified by:
clone
in interfaceCtElement
- Specified by:
clone
in interfaceCtNamedElement
-
isUnnamedPackage
boolean isUnnamedPackage()
Returnstrue
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
-
-