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, parentFields inherited from interface spoon.reflect.declaration.CtType
INNERTTYPE_SEPARATOR, NAME_UNKNOWN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAccepts 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.booleanReturntrueif the referenced type is an anonymous typebooleanisClass()Returns true if this type is a class.booleanisSubtypeOf(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.booleanRemove an anonymous block to this class.voidremoveConstructor(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, toStringWithImportsMethods inherited from class spoon.support.reflect.declaration.CtNamedElementImpl
getSimpleNameMethods 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, updateAllParentsBelowMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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, updateAllParentsBelowMethods inherited from interface spoon.reflect.declaration.CtFormalTypeDeclarer
addFormalCtTypeParameter, addFormalCtTypeParameterAt, getFormalCtTypeParameters, removeFormalCtTypeParameter, setFormalCtTypeParametersMethods 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, setVisibilityMethods inherited from interface spoon.reflect.declaration.CtNamedElement
setSimpleNameMethods inherited from interface spoon.reflect.visitor.chain.CtQueryable
filterChildren, map, mapMethods inherited from interface spoon.reflect.declaration.CtShadowable
isShadow, setShadowMethods inherited from interface spoon.reflect.code.CtStatement
commentMethods 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, toStringWithImportsMethods inherited from interface spoon.reflect.declaration.CtTypeInformation
getAllFields, getDeclaredField, getDeclaredFields, getDeclaredOrInheritedField, getModifiers, getQualifiedName, getSuperInterfaces, getTypeErasure, isAnnotationType, isArray, isEnum, isGenerics, isInterface, isLocalType, isParameterized, isPrimitiveMethods inherited from interface spoon.reflect.declaration.CtTypeMember
getDeclaringType, getTopLevelTypeMethods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
Constructor Details
-
CtClassImpl
public CtClassImpl()
-
-
Method Details
-
accept
Description copied from interface:CtVisitableAccepts a visitor- Specified by:
acceptin interfaceCtVisitable
-
getAnonymousExecutables
Description copied from interface:CtClassReturns the anonymous blocks of this class. Derived fromCtType.getTypeMembers()- Specified by:
getAnonymousExecutablesin interfaceCtClass<T>
-
getConstructor
Description copied from interface:CtClassReturns the constructor of the class that takes the given argument types. Derived fromCtType.getTypeMembers()- Specified by:
getConstructorin interfaceCtClass<T>
-
getConstructors
Description copied from interface:CtClassReturns the constructors of this class. This includes the default constructor if this class has no constructors explicitly declared. Derived fromCtType.getTypeMembers()- Specified by:
getConstructorsin interfaceCtClass<T>
-
addAnonymousExecutable
Description copied from interface:CtClassAdd an anonymous block to this class.- Specified by:
addAnonymousExecutablein interfaceCtClass<T>- Returns:
- true if this element changed as a result of the call
-
removeAnonymousExecutable
Description copied from interface:CtClassRemove an anonymous block to this class.- Specified by:
removeAnonymousExecutablein interfaceCtClass<T>- Returns:
- true if this element changed as a result of the call
-
getSuperclass
Description copied from interface:CtTypeInformationReturns a reference to the type directly extended by this type.To get the
CtTypeof the super class, useCtTypeReference.getDeclaration()orCtTypeReference.getTypeDeclaration()on theCtTypeReferencereturned by this method.- Specified by:
getSuperclassin interfaceCtTypeInformation- Overrides:
getSuperclassin classCtTypeImpl<T>- Returns:
- the type explicitly extended by this type, or
nullif there is none or if the super type is not in the classpath (in noclasspath mode). If a class does not explicitly extend another classnullis 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:CtClassSets the anonymous blocks of this class.- Specified by:
setAnonymousExecutablesin interfaceCtClass<T>
-
setConstructors
Description copied from interface:CtClassSets the constructors for this class.- Specified by:
setConstructorsin interfaceCtClass<T>
-
addConstructor
Description copied from interface:CtClassAdds a constructor to this class.- Specified by:
addConstructorin interfaceCtClass<T>
-
removeConstructor
Description copied from interface:CtClassRemoves a constructor from this class.- Specified by:
removeConstructorin interfaceCtClass<T>
-
setSuperclass
Description copied from interface:CtTypeSets the superclass type.- Specified by:
setSuperclassin interfaceCtType<T>- Overrides:
setSuperclassin classCtTypeImpl<T>
-
isClass
public boolean isClass()Description copied from interface:CtTypeInformationReturns true if this type is a class. Returns false for others (enum, interface, generics, annotation).- Specified by:
isClassin interfaceCtTypeInformation- Overrides:
isClassin classCtTypeImpl<T>
-
isAnonymous
public boolean isAnonymous()Description copied from interface:CtTypeInformationReturntrueif the referenced type is an anonymous type- Specified by:
isAnonymousin interfaceCtClass<T>- Specified by:
isAnonymousin interfaceCtTypeInformation- Overrides:
isAnonymousin classCtTypeImpl<T>
-
isSubtypeOf
Description copied from interface:CtTypeInformationChecks if this type is a subtype of the given type.- Specified by:
isSubtypeOfin interfaceCtTypeInformation- Parameters:
type- the type that might be a parent of this type.- Returns:
trueif 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:CtStatementInserts a statement after the current statement.- Specified by:
insertAfterin interfaceCtStatement
-
insertAfter
Description copied from interface:CtStatementInserts a statement list before the current statement.- Specified by:
insertAfterin interfaceCtStatement
-
insertBefore
Description copied from interface:CtStatementInserts a statement given as parameter before the current statement (this).- Specified by:
insertBeforein interfaceCtStatement
-
insertBefore
Description copied from interface:CtStatementInserts a statement list before the current statement.- Specified by:
insertBeforein interfaceCtStatement
-
getLabel
Description copied from interface:CtStatementGets the label of this statement if defined.- Specified by:
getLabelin interfaceCtStatement- Returns:
- the label's name (null if undefined)
-
setLabel
Description copied from interface:CtStatementSets the label of this statement.- Specified by:
setLabelin interfaceCtClass<T>- Specified by:
setLabelin interfaceCtStatement
-
partiallyEvaluate
Description copied from interface:CtCodeElementPartially evaluates an element and all its sub-elements.- Specified by:
partiallyEvaluatein 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:CtTypeInformationGets the executables declared by this type if applicable.- Specified by:
getDeclaredExecutablesin interfaceCtTypeInformation- Overrides:
getDeclaredExecutablesin classCtTypeImpl<T>
-
clone
Description copied from interface:CtElementClone 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:
clonein interfaceCtClass<T>- Specified by:
clonein interfaceCtCodeElement- Specified by:
clonein interfaceCtElement- Specified by:
clonein interfaceCtNamedElement- Specified by:
clonein interfaceCtStatement- Specified by:
clonein interfaceCtType<T>- Overrides:
clonein classCtTypeImpl<T>
-
newInstance
Description copied from interface:CtClassCreates 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:
newInstancein interfaceCtClass<T>
-
getAllExecutables
adding the constructors and static executables- Specified by:
getAllExecutablesin interfaceCtTypeInformation- Overrides:
getAllExecutablesin classCtTypeImpl<T>
-
getPermittedTypes
Description copied from interface:CtSealableReturns the permitted types for this type.- Specified by:
getPermittedTypesin interfaceCtSealable- Returns:
- an unmodifiable view of the permitted types.
-
setPermittedTypes
Description copied from interface:CtSealableSets the permitted types for this type. Calling this method does not change the state of theModifierKind.SEALEDfor this type. The previously permitted types will be removed.- Specified by:
setPermittedTypesin interfaceCtSealable- Parameters:
permittedTypes- the permitted types to set.- Returns:
- this.
-
addPermittedType
Description copied from interface:CtSealableAdds a permitted type to this type. Calling this method does not change the state of theModifierKind.SEALEDfor this type.- Specified by:
addPermittedTypein interfaceCtSealable- Parameters:
type- the type to add as permitted type.- Returns:
- this.
-
removePermittedType
Description copied from interface:CtSealableAdds a permitted type to this type. Calling this method does not change the state of theModifierKind.SEALEDfor this type.- Specified by:
removePermittedTypein interfaceCtSealable- Parameters:
type- the type to remove from this type's permitted types.- Returns:
- this.
-