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
public class CtPackageImpl extends CtNamedElementImpl implements CtPackage
The implementation forCtPackage
.- Author:
- Renaud Pawlak
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ElementNameMap<CtPackage>
packs
-
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
Constructors Constructor Description CtPackageImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(CtVisitor v)
Accepts a visitor<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 simpleName)
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
isShadow()
When an element isn't present in the factory (created in another factory), this element is considered as "shadow".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> 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>
TsetTypes(Set<CtType<?>> types)
Sets the types defined in the package.String
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 Detail
-
packs
protected ElementNameMap<CtPackage> packs
-
-
Method Detail
-
accept
public void accept(CtVisitor v)
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
addPackage
public <T extends CtPackage> T addPackage(CtPackage pack)
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
public boolean removePackage(CtPackage pack)
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
public CtModule getDeclaringModule()
Description copied from interface:CtPackage
Gets the declaring module.- Specified by:
getDeclaringModule
in interfaceCtPackage
-
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 interfaceCtPackage
-
getPackage
public CtPackage getPackage(String simpleName)
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
public Set<CtPackage> getPackages()
Description copied from interface:CtPackage
Gets the set of included child packages.- Specified by:
getPackages
in interfaceCtPackage
-
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 interfaceCtNamedElement
- Overrides:
setSimpleName
in classCtNamedElementImpl
-
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 interfaceCtPackage
- 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.
-
getTypes
public Set<CtType<?>> getTypes()
Description copied from interface:CtPackage
Returns the set of the top-level types in this package.
-
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 interfaceCtPackage
- 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.
-
getReference
public CtPackageReference 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
public <T extends CtPackage> T addType(CtType<?> type)
Description copied from interface:CtPackage
Adds a type to this package.
-
removeType
public void removeType(CtType<?> type)
Description copied from interface:CtPackage
Removes a type from this package.- Specified by:
removeType
in interfaceCtPackage
-
toString
public String 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
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 ofCtShadowable.isShadow()
.- Specified by:
setShadow
in interfaceCtShadowable
-
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 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
-
-