Package spoon.reflect.declaration
Interface CtClass<T>
- All Superinterfaces:
Cloneable
,CtCodeElement
,CtElement
,CtFormalTypeDeclarer
,CtModifiable
,CtNamedElement
,CtQueryable
,CtSealable
,CtShadowable
,CtStatement
,CtType<T>
,CtTypeInformation
,CtTypeMember
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Implementing Classes:
CtClassImpl
,CtEnumImpl
,CtRecordImpl
This element represents a class declaration.
// a class definition class Foo { int x; }
- Author:
- Renaud Pawlak
-
Field Summary
Fields inherited from interface spoon.reflect.declaration.CtType
INNERTTYPE_SEPARATOR, NAME_UNKNOWN
-
Method Summary
Modifier and TypeMethodDescriptionAdd an anonymous block to this class.addConstructor(CtConstructor<T> constructor)
Adds a constructor to this class.clone()
Clone the element which calls this method in a new object.Returns 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.boolean
Returntrue
if the referenced type is a anonymous typeCreates an instance of this class.boolean
Remove an anonymous block to this class.void
removeConstructor(CtConstructor<T> constructor)
Removes a constructor from this class.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.Methods inherited from interface spoon.reflect.code.CtCodeElement
partiallyEvaluate
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.CtSealable
addPermittedType, getPermittedTypes, removePermittedType, setPermittedTypes
Methods inherited from interface spoon.reflect.declaration.CtShadowable
isShadow, setShadow
Methods inherited from interface spoon.reflect.code.CtStatement
comment, getLabel, insertAfter, insertAfter, insertBefore, insertBefore
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, setSuperclass, setSuperInterfaces, setTypeMembers, toStringWithImports
Methods inherited from interface spoon.reflect.declaration.CtTypeInformation
getAllExecutables, getAllFields, getDeclaredExecutables, getDeclaredField, getDeclaredFields, getDeclaredOrInheritedField, getModifiers, getQualifiedName, getSuperclass, getSuperInterfaces, getTypeErasure, isAnnotationType, isArray, isClass, isEnum, isGenerics, isInterface, isLocalType, isParameterized, isPrimitive, isSubtypeOf
Methods inherited from interface spoon.reflect.declaration.CtTypeMember
getDeclaringType, getTopLevelType
Methods inherited from interface spoon.reflect.visitor.CtVisitable
accept
Methods inherited from interface spoon.processing.FactoryAccessor
getFactory, setFactory
-
Method Details
-
getAnonymousExecutables
List<CtAnonymousExecutable> getAnonymousExecutables()Returns the anonymous blocks of this class. Derived fromCtType.getTypeMembers()
-
getConstructor
Returns the constructor of the class that takes the given argument types. Derived fromCtType.getTypeMembers()
-
getConstructors
Set<CtConstructor<T>> getConstructors()Returns the constructors of this class. This includes the default constructor if this class has no constructors explicitly declared. Derived fromCtType.getTypeMembers()
-
setAnonymousExecutables
Sets the anonymous blocks of this class. -
addAnonymousExecutable
Add an anonymous block to this class.- Parameters:
e
-- Returns:
- true if this element changed as a result of the call
-
removeAnonymousExecutable
Remove an anonymous block to this class.- Parameters:
e
-- Returns:
- true if this element changed as a result of the call
-
setConstructors
Sets the constructors for this class. -
addConstructor
Adds a constructor to this class. -
removeConstructor
Removes a constructor from this class. -
isAnonymous
boolean isAnonymous()Returntrue
if the referenced type is a anonymous type- Specified by:
isAnonymous
in interfaceCtTypeInformation
-
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 interfaceCtCodeElement
- Specified by:
clone
in interfaceCtElement
- Specified by:
clone
in interfaceCtNamedElement
- Specified by:
clone
in interfaceCtStatement
- Specified by:
clone
in interfaceCtType<T>
-
newInstance
T newInstance()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. -
setLabel
Description copied from interface:CtStatement
Sets the label of this statement.- Specified by:
setLabel
in interfaceCtStatement
-