Class CtPackageImpl
java.lang.Object
spoon.support.reflect.declaration.CtElementImpl
spoon.support.reflect.declaration.CtNamedElementImpl
spoon.support.reflect.declaration.CtPackageImpl
- All Implemented Interfaces:
Serializable
,Cloneable
,FactoryAccessor
,SourcePositionHolder
,CtElement
,CtNamedElement
,CtPackage
,CtShadowable
,CtQueryable
,CtVisitable
- Direct Known Subclasses:
CtModelImpl.CtRootPackage
The implementation for
CtPackage
.- Author:
- Renaud Pawlak
- See Also:
- Serialized Form
-
Field Summary
Fields inherited from class spoon.support.reflect.declaration.CtElementImpl
ERROR_MESSAGE_TO_STRING, factory, LOGGER, parent
Fields inherited from interface spoon.reflect.declaration.CtPackage
PACKAGE_SEPARATOR, PACKAGE_SEPARATOR_CHAR, TOP_LEVEL_PACKAGE_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Accepts a visitor<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 simpleName)
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
isShadow()
When an element isn't present in the factory (created in another factory), this element is considered as "shadow".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> packs)
Sets the children defined in this package<E extends CtShadowable>
EsetShadow(boolean isShadow)
Marks an element as shadow.<T extends CtNamedElement>
TsetSimpleName(String simpleName)
Sets the simple (unqualified) name of this element.<T extends CtPackage>
TSets the types defined in the package.toString()
Methods inherited from class spoon.support.reflect.declaration.CtNamedElementImpl
getSimpleName
Methods inherited from class spoon.support.reflect.declaration.CtElementImpl
addAnnotation, addComment, asIterable, comment, delete, descendantIterator, emptyList, emptySet, equals, filterChildren, getAllMetadata, getAnnotatedChildren, getAnnotation, getAnnotation, getAnnotations, getComments, getDirectChildren, getDocComment, getElements, getFactory, getMetadata, getMetadataKeys, getOriginalSourceFragment, getParent, getParent, getParent, getPath, getPosition, getReferencedTypes, getRoleInParent, getShortRepresentation, getValueByRole, hasAnnotation, hashCode, hasParent, isImplicit, isParentInitialized, map, map, prettyprint, putMetadata, removeAnnotation, removeComment, replace, replace, setAllMetadata, setAnnotations, setComments, setDocComment, setFactory, setImplicit, setParent, setPosition, setPositions, setValueByRole, toStringDebug, unmodifiableList, updateAllParentsBelow
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
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, toStringDebug, updateAllParentsBelow
Methods inherited from interface spoon.reflect.declaration.CtNamedElement
getSimpleName
Methods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, map
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
Field Details
-
packs
-
-
Constructor Details
-
CtPackageImpl
public CtPackageImpl()
-
-
Method Details
-
accept
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
addPackage
Description copied from interface:CtPackage
add a subpackage- Specified by:
addPackage
in interfaceCtPackage
- Returns:
- true if this element changed as a result of the call
-
removePackage
Description copied from interface:CtPackage
remove a subpackage- Specified by:
removePackage
in interfaceCtPackage
- Returns:
- true if this element changed as a result of the call
-
getDeclaringModule
Description copied from interface:CtPackage
Gets the declaring module.- Specified by:
getDeclaringModule
in interfaceCtPackage
-
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 interfaceCtPackage
-
getPackage
Description copied from interface:CtPackage
Searches a child package by name.- Specified by:
getPackage
in interfaceCtPackage
- Parameters:
simpleName
- the simple name of searched package- Returns:
- the found package or null
-
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 interfaceCtPackage
-
setSimpleName
Description copied from interface:CtNamedElement
Sets the simple (unqualified) name of this element.- Specified by:
setSimpleName
in interfaceCtNamedElement
- Overrides:
setSimpleName
in classCtNamedElementImpl
-
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 interfaceCtPackage
- Returns:
- the fully qualified name of this package, or the empty string if this is the unnamed package
-
getType
Description copied from interface:CtPackage
Finds a top-level type by name. -
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. -
setPackages
Description copied from interface:CtPackage
Sets the children defined in this package- Specified by:
setPackages
in interfaceCtPackage
- Parameters:
packs
- new set of child packages
-
setTypes
Description copied from interface:CtPackage
Sets the types defined in the package. -
getReference
Description copied from interface:CtNamedElement
Returns the corresponding reference.- Specified by:
getReference
in interfaceCtNamedElement
- Specified by:
getReference
in interfaceCtPackage
- Overrides:
getReference
in classCtNamedElementImpl
-
addType
Description copied from interface:CtPackage
Adds a type to this package. -
removeType
Description copied from interface:CtPackage
Removes a type from this package.- Specified by:
removeType
in interfaceCtPackage
-
toString
- Specified by:
toString
in interfaceCtElement
- Overrides:
toString
in classCtElementImpl
- 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 callCtTypeReference.getTypeDeclaration()
on a reference of java.lang.Class.- Specified by:
isShadow
in interfaceCtShadowable
- Returns:
- true if the element is a shadow element, otherwise false.
-
setShadow
Description copied from interface:CtShadowable
Marks an element as shadow. To know what is a shadow element, see the javadoc ofCtShadowable.isShadow()
.- Specified by:
setShadow
in interfaceCtShadowable
-
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
- Specified by:
clone
in interfaceCtPackage
- Overrides:
clone
in classCtNamedElementImpl
-
isUnnamedPackage
public boolean isUnnamedPackage()Description copied from interface:CtPackage
Returnstrue
if this is an unnamed Java package. See JLS ยง7.4.2. Unnamed Packages.- Specified by:
isUnnamedPackage
in interfaceCtPackage
-
hasPackageInfo
public boolean hasPackageInfo()- Specified by:
hasPackageInfo
in interfaceCtPackage
- Returns:
- true if the package contains a package-info.java file
-
isEmpty
public boolean isEmpty() -
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 overCtPackage.getTypes()
.isEmpty()
.- Specified by:
hasTypes
in interfaceCtPackage
- 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 overCtPackage.getPackages()
.isEmpty()
.- Specified by:
hasPackages
in interfaceCtPackage
- Returns:
- true if the package contains any sub-packages
- See Also:
CtPackage.getPackages()
-