java.lang.Object
io.github.sugarcubes.cloner.enhancement.ClassHierarchy

public abstract class ClassHierarchy extends Object
Classes as the build tools or the cloner agent see them: which classes get copy constructors in this enhancement (the classes of a build, or the classes which a class loader loads) and which superclasses have them.

A class gets a copy constructor if it is enhanced, matches the masks, is a class (not an interface, an enum, an annotation, a module or package descriptor), and its superclass is Object, Record or a class with a copy constructor: the constructor calls the copy constructor of the superclass.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Internal name of java.lang.Object.
    static final String
    Internal name of java.lang.Record.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract ClassInfo
    find(String name)
    Finds the class.
    boolean
    Tells whether the class has a copy constructor or gets it in this enhancement.
    static boolean
    Tells whether the class is a class, the only kind which gets copy constructors.
    protected abstract boolean
    Tells whether the class is enhanced: compiled in this build, or loaded after the agent started.
    Tells whether instances of the class are serializable.
    boolean
    Tells whether the class matches the masks.
    Tells why the cloner never copies instances of the class, so it needs no copy constructor: singletons of Kotlin (object, data object, companion object, lambda classes capturing nothing) and Scala (object, case object, cases of Scala 3 enums), meta classes of Groovy, which the cloner shares; Kotlin file facades and synthetic classes, which have no instances; jobs of Kotlin coroutines and futures of Scala, which the cloner does not copy.
    Explains why an enhanced class which matches the masks cannot get a copy constructor.
    Explains why an enhanced class which matches the masks and is a class cannot get a copy constructor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ClassHierarchy

      protected ClassHierarchy(ClassMasks targets)
      Constructor.
      Parameters:
      targets - classes which get copy constructors
  • Method Details

    • find

      protected abstract ClassInfo find(String name)
      Finds the class.
      Parameters:
      name - internal name
      Returns:
      class information or null if the class is not found
    • isLocal

      protected abstract boolean isLocal(String name)
      Tells whether the class is enhanced: compiled in this build, or loaded after the agent started.
      Parameters:
      name - internal name
      Returns:
      true for enhanced classes
    • isTarget

      public boolean isTarget(String name)
      Tells whether the class matches the masks.
      Parameters:
      name - internal name
      Returns:
      true if it matches
    • neverCopied

      public Optional<String> neverCopied(String name)
      Tells why the cloner never copies instances of the class, so it needs no copy constructor: singletons of Kotlin (object, data object, companion object, lambda classes capturing nothing) and Scala (object, case object, cases of Scala 3 enums), meta classes of Groovy, which the cloner shares; Kotlin file facades and synthetic classes, which have no instances; jobs of Kotlin coroutines and futures of Scala, which the cloner does not copy.
      Parameters:
      name - internal name
      Returns:
      the reason or empty if instances of the class may be copied
    • isClass

      public static boolean isClass(ClassInfo info)
      Tells whether the class is a class, the only kind which gets copy constructors.
      Parameters:
      info - class
      Returns:
      false for interfaces, enums, annotations, module and package descriptors
    • targetProblem

      public Optional<String> targetProblem(String name)
      Explains why an enhanced class which matches the masks and is a class cannot get a copy constructor.
      Parameters:
      name - internal name
      Returns:
      problem or empty if the class gets a copy constructor, is not a target or not a class
    • problem

      public Optional<String> problem(String name)
      Explains why an enhanced class which matches the masks cannot get a copy constructor.
      Parameters:
      name - internal name
      Returns:
      problem or empty if the class gets a copy constructor
    • hasCopyConstructor

      public boolean hasCopyConstructor(String name)
      Tells whether the class has a copy constructor or gets it in this enhancement.
      Parameters:
      name - internal name
      Returns:
      true if instances of subclasses can call it
    • isSerializable

      public Boolean isSerializable(String name)
      Tells whether instances of the class are serializable.
      Parameters:
      name - internal name
      Returns:
      true or false, null if a supertype is not found