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.booleanReturntrueif the referenced type is a anonymous typeCreates an instance of this class.booleanRemove an anonymous block to this class.voidremoveConstructor(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
partiallyEvaluateMethods 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.CtSealable
addPermittedType, getPermittedTypes, removePermittedType, setPermittedTypesMethods inherited from interface spoon.reflect.declaration.CtShadowable
isShadow, setShadowMethods inherited from interface spoon.reflect.code.CtStatement
comment, getLabel, insertAfter, insertAfter, insertBefore, insertBeforeMethods 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, toStringWithImportsMethods 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, isSubtypeOfMethods inherited from interface spoon.reflect.declaration.CtTypeMember
getDeclaringType, getTopLevelTypeMethods inherited from interface spoon.reflect.visitor.CtVisitable
acceptMethods 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()Returntrueif the referenced type is a anonymous type- Specified by:
isAnonymousin interfaceCtTypeInformation
-
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 interfaceCtCodeElement- Specified by:
clonein interfaceCtElement- Specified by:
clonein interfaceCtNamedElement- Specified by:
clonein interfaceCtStatement- Specified by:
clonein 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:CtStatementSets the label of this statement.- Specified by:
setLabelin interfaceCtStatement
-