Package spoon.reflect.declaration
Interface CtClass<T>
-
- All Superinterfaces:
Cloneable
,CtCodeElement
,CtElement
,CtFormalTypeDeclarer
,CtModifiable
,CtNamedElement
,CtQueryable
,CtShadowable
,CtStatement
,CtType<T>
,CtTypeInformation
,CtTypeMember
,CtVisitable
,FactoryAccessor
,Serializable
,SourcePositionHolder
- All Known Subinterfaces:
CtEnum<T>
- All Known Implementing Classes:
CtClassImpl
,CtEnumImpl
public interface CtClass<T> extends CtType<T>, CtStatement
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <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.List<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.boolean
isAnonymous()
Returntrue
if the referenced type is a anonymous typeT
newInstance()
Creates an instance of this class.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> e)
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.-
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.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 Detail
-
getAnonymousExecutables
List<CtAnonymousExecutable> getAnonymousExecutables()
Returns the anonymous blocks of this class. Derived fromCtType.getTypeMembers()
-
getConstructor
CtConstructor<T> getConstructor(CtTypeReference<?>... parameterTypes)
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
<C extends CtClass<T>> C setAnonymousExecutables(List<CtAnonymousExecutable> e)
Sets the anonymous blocks of this class.
-
addAnonymousExecutable
<C extends CtClass<T>> C addAnonymousExecutable(CtAnonymousExecutable e)
Add an anonymous block to this class.- Parameters:
e
-- Returns:
- true if this element changed as a result of the call
-
removeAnonymousExecutable
boolean removeAnonymousExecutable(CtAnonymousExecutable e)
Remove an anonymous block to this class.- Parameters:
e
-- Returns:
- true if this element changed as a result of the call
-
setConstructors
<C extends CtClass<T>> C setConstructors(Set<CtConstructor<T>> constructors)
Sets the constructors for this class.
-
addConstructor
<C extends CtClass<T>> C addConstructor(CtConstructor<T> constructor)
Adds a constructor to this class.
-
removeConstructor
void removeConstructor(CtConstructor<T> constructor)
Removes a constructor from this class.
-
isAnonymous
boolean isAnonymous()
Returntrue
if the referenced type is a anonymous type- Specified by:
isAnonymous
in interfaceCtTypeInformation
-
clone
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 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
<C extends CtStatement> C setLabel(String label)
Description copied from interface:CtStatement
Sets the label of this statement.- Specified by:
setLabel
in interfaceCtStatement
-
-