Class CtClassImpl<T>
java.lang.Object
spoon.support.reflect.declaration.CtElementImpl
spoon.support.reflect.declaration.CtNamedElementImpl
spoon.support.reflect.declaration.CtTypeImpl<T>
spoon.support.reflect.declaration.CtClassImpl<T>
- All Implemented Interfaces:
Serializable
,Cloneable
,FactoryAccessor
,CtCodeElement
,CtStatement
,SourcePositionHolder
,CtClass<T>
,CtElement
,CtFormalTypeDeclarer
,CtModifiable
,CtNamedElement
,CtSealable
,CtShadowable
,CtType<T>
,CtTypeInformation
,CtTypeMember
,CtQueryable
,CtVisitable
- Direct Known Subclasses:
CtEnumImpl
,CtRecordImpl
The implementation for
CtClass
.- 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.CtType
INNERTTYPE_SEPARATOR, NAME_UNKNOWN
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Accepts a visitorAdd an anonymous block to this class.addConstructor(CtConstructor<T> constructor)
Adds a constructor to this class.addPermittedType(CtTypeReference<?> type)
Adds a permitted type to this type.clone()
Clone the element which calls this method in a new object.adding the constructors and static executablesReturns the anonymous blocks of this class.getConstructor(CtTypeReference<?>... parameterTypes)
Returns the constructor of the class that takes the given argument types.Returns the constructors of this class.Gets the executables declared by this type if applicable.getLabel()
Gets the label of this statement if defined.Set<CtTypeReference<?>>
Returns the permitted types for this type.Returns a reference to the type directly extended by this type.<C extends CtStatement>
CinsertAfter(CtStatement statement)
Inserts a statement after the current statement.<C extends CtStatement>
CinsertAfter(CtStatementList statements)
Inserts a statement list before the current statement.<C extends CtStatement>
CinsertBefore(CtStatement statement)
Inserts a statement given as parameter before the current statement (this).<C extends CtStatement>
CinsertBefore(CtStatementList statements)
Inserts a statement list before the current statement.boolean
Returntrue
if the referenced type is an anonymous typeboolean
isClass()
Returns true if this type is a class.boolean
isSubtypeOf(CtTypeReference<?> type)
Checks if this type is a subtype of the given type.Creates an instance of this class.<R extends CtCodeElement>
RPartially evaluates an element and all its sub-elements.boolean
Remove an anonymous block to this class.void
removeConstructor(CtConstructor<T> constructor)
Removes a constructor from this class.removePermittedType(CtTypeReference<?> type)
Adds a permitted type to this type.setAnonymousExecutables(List<CtAnonymousExecutable> anonymousExecutables)
Sets the anonymous blocks of this class.setConstructors(Set<CtConstructor<T>> constructors)
Sets the constructors for this class.<C extends CtStatement>
CSets the label of this statement.setPermittedTypes(Collection<CtTypeReference<?>> permittedTypes)
Sets the permitted types for this type.setSuperclass(CtTypeReference<?> superClass)
Sets the superclass type.Methods inherited from class spoon.support.reflect.declaration.CtTypeImpl
addField, addField, addFieldAtTop, addFormalCtTypeParameter, addFormalCtTypeParameterAt, addMethod, addModifier, addNestedType, addSuperInterface, addTypeMember, addTypeMemberAt, compileAndReplaceSnippets, copyType, getActualClass, getAllFields, getAllMethods, getDeclaredField, getDeclaredFields, getDeclaredOrInheritedField, getDeclaringType, getExtendedModifiers, getField, getFields, getFormalCtTypeParameters, getMethod, getMethod, getMethods, getMethodsAnnotatedWith, getMethodsByName, getModifiers, getNestedType, getNestedTypes, getPackage, getQualifiedName, getReference, getSuperInterfaces, getTopLevelType, getTypeErasure, getTypeMembers, getUsedTypes, getVisibility, hasMethod, hasModifier, hasSameParameters, isAbstract, isAnnotationType, isArray, isEnum, isFinal, isGenerics, isInterface, isLocalType, isNative, isParameterized, isPrimitive, isPrivate, isProtected, isPublic, isShadow, isStatic, isStrictfp, isSynchronized, isTopLevel, isTransient, isVolatile, removeField, removeFormalCtTypeParameter, removeMethod, removeModifier, removeNestedType, removeSuperInterface, removeTypeMember, setExtendedModifiers, setFields, setFormalCtTypeParameters, setMethods, setModifiers, setNestedTypes, setShadow, setSimpleName, setSuperInterfaces, setTypeMembers, setVisibility, toStringWithImports
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, toString, 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, toString, toStringDebug, updateAllParentsBelow
Methods inherited from interface spoon.reflect.declaration.CtFormalTypeDeclarer
addFormalCtTypeParameter, addFormalCtTypeParameterAt, getFormalCtTypeParameters, removeFormalCtTypeParameter, setFormalCtTypeParameters
Methods inherited from interface spoon.reflect.declaration.CtModifiable
addModifier, getExtendedModifiers, getModifiers, getVisibility, hasModifier, isAbstract, isFinal, isNative, isPrivate, isProtected, isPublic, isStatic, isStrictfp, isSynchronized, isTransient, isVolatile, removeModifier, setExtendedModifiers, setModifiers, setVisibility
Methods inherited from interface spoon.reflect.declaration.CtNamedElement
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.code.CtStatement
comment
Methods inherited from interface spoon.reflect.declaration.CtType
addField, addField, addFieldAtTop, addMethod, addNestedType, addSuperInterface, addTypeMember, addTypeMemberAt, compileAndReplaceSnippets, copyType, getActualClass, getAllMethods, getField, getFields, getMethod, getMethod, getMethods, getMethodsAnnotatedWith, getMethodsByName, getNestedType, getNestedTypes, getPackage, getReference, getSimpleName, getTypeMembers, getUsedTypes, hasMethod, isTopLevel, removeField, removeMethod, removeNestedType, removeSuperInterface, removeTypeMember, setFields, setMethods, setNestedTypes, setSuperInterfaces, setTypeMembers, toStringWithImports
Methods inherited from interface spoon.reflect.declaration.CtTypeInformation
getAllFields, getDeclaredField, getDeclaredFields, getDeclaredOrInheritedField, getModifiers, getQualifiedName, getSuperInterfaces, getTypeErasure, isAnnotationType, isArray, isEnum, isGenerics, isInterface, isLocalType, isParameterized, isPrimitive
Methods inherited from interface spoon.reflect.declaration.CtTypeMember
getDeclaringType, getTopLevelType
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
Constructor Details
-
CtClassImpl
public CtClassImpl()
-
-
Method Details
-
accept
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
getAnonymousExecutables
Description copied from interface:CtClass
Returns the anonymous blocks of this class. Derived fromCtType.getTypeMembers()
- Specified by:
getAnonymousExecutables
in interfaceCtClass<T>
-
getConstructor
Description copied from interface:CtClass
Returns the constructor of the class that takes the given argument types. Derived fromCtType.getTypeMembers()
- Specified by:
getConstructor
in interfaceCtClass<T>
-
getConstructors
Description copied from interface:CtClass
Returns the constructors of this class. This includes the default constructor if this class has no constructors explicitly declared. Derived fromCtType.getTypeMembers()
- Specified by:
getConstructors
in interfaceCtClass<T>
-
addAnonymousExecutable
Description copied from interface:CtClass
Add an anonymous block to this class.- Specified by:
addAnonymousExecutable
in interfaceCtClass<T>
- Returns:
- true if this element changed as a result of the call
-
removeAnonymousExecutable
Description copied from interface:CtClass
Remove an anonymous block to this class.- Specified by:
removeAnonymousExecutable
in interfaceCtClass<T>
- Returns:
- true if this element changed as a result of the call
-
getSuperclass
Description copied from interface:CtTypeInformation
Returns a reference to the type directly extended by this type.To get the
CtType
of the super class, useCtTypeReference.getDeclaration()
orCtTypeReference.getTypeDeclaration()
on theCtTypeReference
returned by this method.- Specified by:
getSuperclass
in interfaceCtTypeInformation
- Overrides:
getSuperclass
in classCtTypeImpl<T>
- Returns:
- the type explicitly extended by this type, or
null
if there is none or if the super type is not in the classpath (in noclasspath mode). If a class does not explicitly extend another classnull
is returned (notObject
). For types like enums that implicitly extend a superclass likeEnum
, this method returns that class.
-
setAnonymousExecutables
public <C extends CtClass<T>> C setAnonymousExecutables(List<CtAnonymousExecutable> anonymousExecutables)Description copied from interface:CtClass
Sets the anonymous blocks of this class.- Specified by:
setAnonymousExecutables
in interfaceCtClass<T>
-
setConstructors
Description copied from interface:CtClass
Sets the constructors for this class.- Specified by:
setConstructors
in interfaceCtClass<T>
-
addConstructor
Description copied from interface:CtClass
Adds a constructor to this class.- Specified by:
addConstructor
in interfaceCtClass<T>
-
removeConstructor
Description copied from interface:CtClass
Removes a constructor from this class.- Specified by:
removeConstructor
in interfaceCtClass<T>
-
setSuperclass
Description copied from interface:CtType
Sets the superclass type.- Specified by:
setSuperclass
in interfaceCtType<T>
- Overrides:
setSuperclass
in classCtTypeImpl<T>
-
isClass
public boolean isClass()Description copied from interface:CtTypeInformation
Returns true if this type is a class. Returns false for others (enum, interface, generics, annotation).- Specified by:
isClass
in interfaceCtTypeInformation
- Overrides:
isClass
in classCtTypeImpl<T>
-
isAnonymous
public boolean isAnonymous()Description copied from interface:CtTypeInformation
Returntrue
if the referenced type is an anonymous type- Specified by:
isAnonymous
in interfaceCtClass<T>
- Specified by:
isAnonymous
in interfaceCtTypeInformation
- Overrides:
isAnonymous
in classCtTypeImpl<T>
-
isSubtypeOf
Description copied from interface:CtTypeInformation
Checks if this type is a subtype of the given type.- Specified by:
isSubtypeOf
in interfaceCtTypeInformation
- Parameters:
type
- the type that might be a parent of this type.- Returns:
true
if the referenced type is a subtype of the given type, otherwisefalse
. If this type is the same as the given type (typeX.isSubtypeOf(typeX)
), this method returnstrue
.
-
insertAfter
Description copied from interface:CtStatement
Inserts a statement after the current statement.- Specified by:
insertAfter
in interfaceCtStatement
-
insertAfter
Description copied from interface:CtStatement
Inserts a statement list before the current statement.- Specified by:
insertAfter
in interfaceCtStatement
-
insertBefore
Description copied from interface:CtStatement
Inserts a statement given as parameter before the current statement (this).- Specified by:
insertBefore
in interfaceCtStatement
-
insertBefore
Description copied from interface:CtStatement
Inserts a statement list before the current statement.- Specified by:
insertBefore
in interfaceCtStatement
-
getLabel
Description copied from interface:CtStatement
Gets the label of this statement if defined.- Specified by:
getLabel
in interfaceCtStatement
- Returns:
- the label's name (null if undefined)
-
setLabel
Description copied from interface:CtStatement
Sets the label of this statement.- Specified by:
setLabel
in interfaceCtClass<T>
- Specified by:
setLabel
in interfaceCtStatement
-
partiallyEvaluate
Description copied from interface:CtCodeElement
Partially evaluates an element and all its sub-elements.- Specified by:
partiallyEvaluate
in interfaceCtCodeElement
- Type Parameters:
R
- the type of the returned element- Returns:
- the result of the partial evaluation. The element is always cloned, even if nothing has been evaluated.
- See Also:
VisitorPartialEvaluator
-
getDeclaredExecutables
Description copied from interface:CtTypeInformation
Gets the executables declared by this type if applicable.- Specified by:
getDeclaredExecutables
in interfaceCtTypeInformation
- Overrides:
getDeclaredExecutables
in classCtTypeImpl<T>
-
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 interfaceCtClass<T>
- Specified by:
clone
in interfaceCtCodeElement
- Specified by:
clone
in interfaceCtElement
- Specified by:
clone
in interfaceCtNamedElement
- Specified by:
clone
in interfaceCtStatement
- Specified by:
clone
in interfaceCtType<T>
- Overrides:
clone
in classCtTypeImpl<T>
-
newInstance
Description copied from interface:CtClass
Creates an instance of this class. Requirements: - the class must have a default constructor. - All dependencies (superclass, super-interfaces, imports) must be in the classpath, because the code is actually compiled (otherwise an exception is thrown) If the class has super-interfaces, the object can be cast to one of them. Otherwise, if the class has no super-interfaces, the methods can only be called with reflection. This instance is meant to be used for quick-testing, it uses a throwable classloader that will be garbage-collected with the instance.- Specified by:
newInstance
in interfaceCtClass<T>
-
getAllExecutables
adding the constructors and static executables- Specified by:
getAllExecutables
in interfaceCtTypeInformation
- Overrides:
getAllExecutables
in classCtTypeImpl<T>
-
getPermittedTypes
Description copied from interface:CtSealable
Returns the permitted types for this type.- Specified by:
getPermittedTypes
in interfaceCtSealable
- Returns:
- an unmodifiable view of the permitted types.
-
setPermittedTypes
Description copied from interface:CtSealable
Sets the permitted types for this type. Calling this method does not change the state of theModifierKind.SEALED
for this type. The previously permitted types will be removed.- Specified by:
setPermittedTypes
in interfaceCtSealable
- Parameters:
permittedTypes
- the permitted types to set.- Returns:
- this.
-
addPermittedType
Description copied from interface:CtSealable
Adds a permitted type to this type. Calling this method does not change the state of theModifierKind.SEALED
for this type.- Specified by:
addPermittedType
in interfaceCtSealable
- Parameters:
type
- the type to add as permitted type.- Returns:
- this.
-
removePermittedType
Description copied from interface:CtSealable
Adds a permitted type to this type. Calling this method does not change the state of theModifierKind.SEALED
for this type.- Specified by:
removePermittedType
in interfaceCtSealable
- Parameters:
type
- the type to remove from this type's permitted types.- Returns:
- this.
-