Package spoon.reflect.declaration
Interface CtPackage
- All Superinterfaces:
Cloneable
,CtElement
,CtNamedElement
,CtQueryable
,CtShadowable
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Implementing Classes:
CtModelImpl.CtRootPackage
,CtPackageImpl
This element defines a package declaration. The packages are represented by a
tree.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescription<T extends CtPackage>
TaddPackage(CtPackage pack)
add a subpackage<T extends CtPackage>
TAdds a type to this package.clone()
Clone the element which calls this method in a new object.Gets the declaring module.Gets the declaring package of the current one.getPackage(String name)
Searches a child package by name.Gets the set of included child packages.Returns the fully qualified name of this package.Returns the corresponding reference.<T extends CtType<?>>
TFinds a top-level type by name.getTypes()
Returns the set of the top-level types in this package.boolean
boolean
Returns true if this package contains any sub-packages.boolean
hasTypes()
Returns true if this package contains any types.boolean
isEmpty()
boolean
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>
TSets 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 Details
-
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
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
Searches a child package by name.- Parameters:
name
- the simple name of searched package- Returns:
- the found package or null
-
getPackages
Gets the set of included child packages. This method might take linear time (regarding the amount of packages in this package). For emptiness-checks,hasPackages()
should be preferred. -
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
Finds a top-level type by name.- Returns:
- the found type or null
-
getTypes
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,hasTypes()
should be preferred. -
addType
Adds a type to this package. -
removeType
Removes a type from this package. -
setPackages
Sets the children defined in this package- Parameters:
pack
- new set of child packages
-
addPackage
add a subpackage- Parameters:
pack
-- Returns:
- true if this element changed as a result of the call
-
removePackage
remove a subpackage- Parameters:
pack
-- Returns:
- true if this element changed as a result of the call
-
setTypes
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
-
hasTypes
boolean hasTypes()Returns true if this package contains any types. This method is expected to provide constant-time performance and should be preferred overgetTypes()
.isEmpty()
.- Returns:
- true if the package contains any types.
- See Also:
getTypes()
-
hasPackages
boolean hasPackages()Returns true if this package contains any sub-packages. This method is expected to provide constant-time performance and should be preferred overgetPackages()
.isEmpty()
.- Returns:
- true if the package contains any sub-packages
- See Also:
getPackages()
-