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>, CtRecord
All Known Implementing Classes:
CtClassImpl, CtEnumImpl, CtRecordImpl

public interface CtClass<T> extends CtType<T>, CtStatement
This element represents a class declaration.
     // a class definition
     class Foo {
        int x;
Renaud Pawlak
  • Method Details

    • getAnonymousExecutables

      List<CtAnonymousExecutable> getAnonymousExecutables()
      Returns the anonymous blocks of this class. Derived from CtType.getTypeMembers()
    • getConstructor

      CtConstructor<T> getConstructor(CtTypeReference<?>... parameterTypes)
      Returns the constructor of the class that takes the given argument types. Derived from CtType.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 from CtType.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.
      e -
      true if this element changed as a result of the call
    • removeAnonymousExecutable

      boolean removeAnonymousExecutable(CtAnonymousExecutable e)
      Remove an anonymous block to this class.
      e -
      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()
      Return true if the referenced type is a anonymous type
      Specified by:
      isAnonymous in interface CtTypeInformation
    • 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 methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtCodeElement
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtNamedElement
      Specified by:
      clone in interface CtStatement
      Specified by:
      clone in interface CtType<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 interface CtStatement