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
,CtShadowable
,CtType<T>
,CtTypeInformation
,CtTypeMember
,CtQueryable
,CtVisitable
- Direct Known Subclasses:
CtEnumImpl
public class CtClassImpl<T> extends CtTypeImpl<T> implements CtClass<T>
The implementation forCtClass
.- 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
Constructors Constructor Description CtClassImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(CtVisitor v)
Accepts a visitor<C extends CtClass<T>>
CaddAnonymousExecutable(CtAnonymousExecutable e)
Add an anonymous block to this class.<C extends CtClass<T>>
CaddConstructor(CtConstructor<T> constructor)
Adds a constructor to this class.CtClass<T>
clone()
Clone the element which calls this method in a new object.Collection<CtExecutableReference<?>>
getAllExecutables()
adding the constructors and static executablesList<CtAnonymousExecutable>
getAnonymousExecutables()
Returns the anonymous blocks of this class.CtConstructor<T>
getConstructor(CtTypeReference<?>... parameterTypes)
Returns the constructor of the class that takes the given argument types.Set<CtConstructor<T>>
getConstructors()
Returns the constructors of this class.Collection<CtExecutableReference<?>>
getDeclaredExecutables()
Gets the executables declared by this type if applicable.String
getLabel()
Gets the label of this statement if defined.CtTypeReference<?>
getSuperclass()
Returns the class type directly extended by this class.<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
isAnonymous()
Returntrue
if the referenced type is a anonymous typeboolean
isClass()
Returns true if this type is a class.boolean
isSubtypeOf(CtTypeReference<?> type)
Returns true if the referenced type is a sub-type of the given type.T
newInstance()
Creates an instance of this class.<R extends CtCodeElement>
RpartiallyEvaluate()
Partially evaluates an element and all its sub-elements.boolean
removeAnonymousExecutable(CtAnonymousExecutable e)
Remove an anonymous block to this class.void
removeConstructor(CtConstructor<T> constructor)
Removes a constructor from this class.<C extends CtClass<T>>
CsetAnonymousExecutables(List<CtAnonymousExecutable> anonymousExecutables)
Sets the anonymous blocks of this class.<C extends CtClass<T>>
CsetConstructors(Set<CtConstructor<T>> constructors)
Sets the constructors for this class.<C extends CtStatement>
CsetLabel(String label)
Sets the label of this statement.<C extends CtType<T>>
CsetSuperclass(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, setSuperInterfaces, setTypeMembers, setVisibility, toStringWithImports
-
Methods inherited from class spoon.support.reflect.declaration.CtNamedElementImpl
getSimpleName, setSimpleName
-
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
-
-
-
-
Method Detail
-
accept
public void accept(CtVisitor v)
Description copied from interface:CtVisitable
Accepts a visitor- Specified by:
accept
in interfaceCtVisitable
-
getAnonymousExecutables
public List<CtAnonymousExecutable> getAnonymousExecutables()
Description copied from interface:CtClass
Returns the anonymous blocks of this class. Derived fromCtType.getTypeMembers()
- Specified by:
getAnonymousExecutables
in interfaceCtClass<T>
-
getConstructor
public CtConstructor<T> getConstructor(CtTypeReference<?>... parameterTypes)
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
public Set<CtConstructor<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
public <C extends CtClass<T>> C addAnonymousExecutable(CtAnonymousExecutable e)
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
public boolean removeAnonymousExecutable(CtAnonymousExecutable e)
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
public CtTypeReference<?> getSuperclass()
Description copied from interface:CtTypeInformation
Returns the class type directly extended by this class. getSuperClass().getDeclaration()/getTypeDeclaration() returns the corresponding CtType (if in the source folder of Spoon).- Specified by:
getSuperclass
in interfaceCtTypeInformation
- Overrides:
getSuperclass
in classCtTypeImpl<T>
- Returns:
- the class type directly extended by this class, or null if there is none or if the super class is not in the classpath (in noclasspath mode)
-
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
public <C extends CtClass<T>> C setConstructors(Set<CtConstructor<T>> constructors)
Description copied from interface:CtClass
Sets the constructors for this class.- Specified by:
setConstructors
in interfaceCtClass<T>
-
addConstructor
public <C extends CtClass<T>> C addConstructor(CtConstructor<T> constructor)
Description copied from interface:CtClass
Adds a constructor to this class.- Specified by:
addConstructor
in interfaceCtClass<T>
-
removeConstructor
public void removeConstructor(CtConstructor<T> constructor)
Description copied from interface:CtClass
Removes a constructor from this class.- Specified by:
removeConstructor
in interfaceCtClass<T>
-
setSuperclass
public <C extends CtType<T>> C setSuperclass(CtTypeReference<?> superClass)
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 a anonymous type- Specified by:
isAnonymous
in interfaceCtClass<T>
- Specified by:
isAnonymous
in interfaceCtTypeInformation
- Overrides:
isAnonymous
in classCtTypeImpl<T>
-
isSubtypeOf
public boolean isSubtypeOf(CtTypeReference<?> type)
Description copied from interface:CtTypeInformation
Returns true if the referenced type is a sub-type of the given type. Returns true is type is self, it means: typeX.isSubtypeOf(typeX) is true too- Specified by:
isSubtypeOf
in interfaceCtTypeInformation
-
insertAfter
public <C extends CtStatement> C insertAfter(CtStatement statement)
Description copied from interface:CtStatement
Inserts a statement after the current statement.- Specified by:
insertAfter
in interfaceCtStatement
-
insertAfter
public <C extends CtStatement> C insertAfter(CtStatementList statements)
Description copied from interface:CtStatement
Inserts a statement list before the current statement.- Specified by:
insertAfter
in interfaceCtStatement
-
insertBefore
public <C extends CtStatement> C insertBefore(CtStatement statement)
Description copied from interface:CtStatement
Inserts a statement given as parameter before the current statement (this).- Specified by:
insertBefore
in interfaceCtStatement
-
insertBefore
public <C extends CtStatement> C insertBefore(CtStatementList statements)
Description copied from interface:CtStatement
Inserts a statement list before the current statement.- Specified by:
insertBefore
in interfaceCtStatement
-
getLabel
public String 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
public <C extends CtStatement> C setLabel(String label)
Description copied from interface:CtStatement
Sets the label of this statement.- Specified by:
setLabel
in interfaceCtClass<T>
- Specified by:
setLabel
in interfaceCtStatement
-
partiallyEvaluate
public <R extends CtCodeElement> R partiallyEvaluate()
Description copied from interface:CtCodeElement
Partially evaluates an element and all its sub-elements.- Specified by:
partiallyEvaluate
in interfaceCtCodeElement
- Type Parameters:
R
- the returned element- Returns:
- the result of the partial evaluation
-
getDeclaredExecutables
public Collection<CtExecutableReference<?>> 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
public CtClass<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
public 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
public Collection<CtExecutableReference<?>> getAllExecutables()
adding the constructors and static executables- Specified by:
getAllExecutables
in interfaceCtTypeInformation
- Overrides:
getAllExecutables
in classCtTypeImpl<T>
-
-