Class ClassInfo

java.lang.Object
org.spongepowered.asm.mixin.transformer.ClassInfo

public final class ClassInfo extends Object
Information about a class, used as a way of keeping track of class hierarchy information needed to support more complex mixin behaviour such as detached superclass and mixin inheritance.
  • Field Details

    • INCLUDE_PRIVATE

      public static final int INCLUDE_PRIVATE
      Include private members when running a member search
      See Also:
    • INCLUDE_STATIC

      public static final int INCLUDE_STATIC
      Include static members when running a member search
      See Also:
    • INCLUDE_ALL

      public static final int INCLUDE_ALL
      Include private and static members when running a member search
      See Also:
    • INCLUDE_INITIALISERS

      public static final int INCLUDE_INITIALISERS
      Include instance and class initialisers when running a method search
      See Also:
  • Method Details

    • getAppliedMixins

      public Set<IMixinInfo> getAppliedMixins()
      Get all mixins which have been successfully applied to this class
    • isMixin

      public boolean isMixin()
      Get whether this class is a mixin
    • isLoadable

      public boolean isLoadable()
      Get whether this class is loadable mixin
    • isPublic

      public boolean isPublic()
      Get whether this class has ACC_PUBLIC
    • isReallyPublic

      public boolean isReallyPublic()
      Get whether this class is really public (only valid for inner classes which may be "public" themselves but aren't actually visible because their enclosing type is package-private for example.
    • isProtected

      public boolean isProtected()
      Get whether this class has ACC_PROTECTED (only valid for inner classes)
    • isPrivate

      public boolean isPrivate()
      Get whether this class has ACC_PRIVATE (only valid for inner classes)
    • isAbstract

      public boolean isAbstract()
      Get whether this class has ACC_ABSTRACT
    • isSynthetic

      public boolean isSynthetic()
      Get whether this class has ACC_SYNTHETIC
    • isProbablyStatic

      public boolean isProbablyStatic()
      Get whether this class is probably static (or is not an inner class)
    • isInner

      public boolean isInner()
      Get whether this class is an inner class
    • isInterface

      public boolean isInterface()
      Get whether this is an interface or not
    • getInterfaces

      public Set<String> getInterfaces()
      Returns the answer to life, the universe and everything
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAccess

      public int getAccess()
    • getName

      public String getName()
      Get the class name (binary name)
    • getClassName

      public String getClassName()
      Get the class name (java format)
    • getSimpleName

      public String getSimpleName()
      Get the class name (simple name, java format)
    • getType

      public org.objectweb.asm.Type getType()
      Get the object type (ASM type)
    • getSuperName

      public String getSuperName()
      Get the superclass name (binary name)
    • getSuperClass

      public ClassInfo getSuperClass()
      Get the superclass info, can return null if the superclass cannot be resolved
    • getOuterName

      public String getOuterName()
      Get the name of the outer class, or null if this is not an inner class
    • getOuterClass

      public ClassInfo getOuterClass()
      Get the outer class info, can return null if the outer class cannot be resolved or if this is not an inner class
    • getSignature

      public ClassSignature getSignature()
      Return the class signature
      Returns:
      signature as a ClassSignature instance
    • getNestHost

      public String getNestHost()
      Return the nest host declared in the class
    • getNestMembers

      public Set<String> getNestMembers()
      Get nest members declared in the class
    • resolveNestHost

      public ClassInfo resolveNestHost()
      Resolve the nest host for inner classes of this class. If the class itself has a nest host, the host is returned so that members can be added to it. If the class itself is a nest host (already has nest members) or is neither a nest host or member (eg. per the specification is already a nest host with itself as the sole member) then this method simply returns this ClassInfo.
    • getMethods

      public Set<ClassInfo.Method> getMethods()
      Get class/interface methods
      Returns:
      read-only view of class methods
    • getInterfaceMethods

      public Set<ClassInfo.Method> getInterfaceMethods(boolean includeMixins)
      If this is an interface, returns a set containing all methods in this interface and all super interfaces. If this is a class, returns a set containing all methods for all interfaces implemented by this class and all super interfaces of those interfaces.
      Parameters:
      includeMixins - Whether to include methods from mixins targeting this class info
      Returns:
      read-only view of class methods
    • hasSuperClass

      public boolean hasSuperClass(Class<?> superClass)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Superclass to search for in the hierarchy
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(Class<?> superClass, ClassInfo.Traversal traversal)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Superclass to search for in the hierarchy
      traversal - Traversal type to allow during this lookup
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(Class<?> superClass, ClassInfo.Traversal traversal, boolean includeInterfaces)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Superclass to search for in the hierarchy
      traversal - Traversal type to allow during this lookup
      includeInterfaces - True to include interfaces in the lookup
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(String superClass)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Name of the superclass to search for in the hierarchy
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(String superClass, ClassInfo.Traversal traversal)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Name of the superclass to search for in the hierarchy
      traversal - Traversal type to allow during this lookup
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(String superClass, ClassInfo.Traversal traversal, boolean includeInterfaces)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Name of the superclass to search for in the hierarchy
      traversal - Traversal type to allow during this lookup
      includeInterfaces - True to include interfaces in the lookup
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(ClassInfo superClass)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Superclass to search for in the hierarchy
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(ClassInfo superClass, ClassInfo.Traversal traversal)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Superclass to search for in the hierarchy
      traversal - Traversal type to allow during this lookup
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • hasSuperClass

      public boolean hasSuperClass(ClassInfo superClass, ClassInfo.Traversal traversal, boolean includeInterfaces)
      Test whether this class has the specified superclass in its hierarchy
      Parameters:
      superClass - Superclass to search for in the hierarchy
      traversal - Traversal type to allow during this lookup
      includeInterfaces - True to include interfaces in the lookup
      Returns:
      true if the specified class appears in the class's hierarchy anywhere
    • findSuperClass

      public ClassInfo findSuperClass(String superClass)
      Search for the specified superclass in this class's hierarchy. If found returns the ClassInfo, otherwise returns null
      Parameters:
      superClass - Superclass name to search for
      Returns:
      Matched superclass or null if not found
    • findSuperClass

      public ClassInfo findSuperClass(String superClass, ClassInfo.Traversal traversal)
      Search for the specified superclass in this class's hierarchy. If found returns the ClassInfo, otherwise returns null
      Parameters:
      superClass - Superclass name to search for
      traversal - Traversal type to allow during this lookup
      Returns:
      Matched superclass or null if not found
    • findSuperClass

      public ClassInfo findSuperClass(String superClass, ClassInfo.Traversal traversal, boolean includeInterfaces)
      Search for the specified superclass in this class's hierarchy. If found returns the ClassInfo, otherwise returns null
      Parameters:
      superClass - Superclass name to search for
      traversal - Traversal type to allow during this lookup
      includeInterfaces - True to include interfaces in the lookup
      Returns:
      Matched superclass or null if not found
    • hasMixinInHierarchy

      public boolean hasMixinInHierarchy()
      Find out whether this (mixin) class has another mixin in its superclass hierarchy. This method always returns false for non-mixin classes.
      Returns:
      true if and only if one or more mixins are found in the hierarchy of this mixin
    • hasMixinTargetInHierarchy

      public boolean hasMixinTargetInHierarchy()
      Find out whether this (non-mixin) class has a mixin targetting any of its superclasses. This method always returns false for mixin classes.
      Returns:
      true if and only if one or more classes in this class's hierarchy are targetted by a mixin
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(org.objectweb.asm.tree.MethodNode method, ClassInfo.SearchType searchType)
      Finds the specified private or protected method in this class's hierarchy
      Parameters:
      method - Method to search for
      searchType - Search strategy to use
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(org.objectweb.asm.tree.MethodNode method, ClassInfo.SearchType searchType, ClassInfo.Traversal traversal)
      Finds the specified private or protected method in this class's hierarchy
      Parameters:
      method - Method to search for
      searchType - Search strategy to use
      traversal - Traversal type to allow during this lookup
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(org.objectweb.asm.tree.MethodNode method, ClassInfo.SearchType searchType, int flags)
      Finds the specified private or protected method in this class's hierarchy
      Parameters:
      method - Method to search for
      searchType - Search strategy to use
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(org.objectweb.asm.tree.MethodNode method, ClassInfo.SearchType searchType, ClassInfo.Traversal traversal, int flags)
      Finds the specified private or protected method in this class's hierarchy
      Parameters:
      method - Method to search for
      searchType - Search strategy to use
      traversal - Traversal type to allow during this lookup
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(org.objectweb.asm.tree.MethodInsnNode method, ClassInfo.SearchType searchType)
      Finds the specified public or protected method in this class's hierarchy
      Parameters:
      method - Method to search for
      searchType - Search strategy to use
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(org.objectweb.asm.tree.MethodInsnNode method, ClassInfo.SearchType searchType, int flags)
      Finds the specified public or protected method in this class's hierarchy
      Parameters:
      method - Method to search for
      searchType - Search strategy to use
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(String name, String desc, ClassInfo.SearchType searchType, int flags)
      Finds the specified public or protected method in this class's hierarchy
      Parameters:
      name - Method name to search for
      desc - Method descriptor
      searchType - Search strategy to use
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(String name, String desc, ClassInfo.SearchType searchType, ClassInfo.Traversal traversal)
      Finds the specified public or protected method in this class's hierarchy
      Parameters:
      name - Method name to search for
      desc - Method descriptor
      searchType - Search strategy to use
      traversal - Traversal type to allow during this lookup
      Returns:
      the method object or null if the method could not be resolved
    • findMethodInHierarchy

      public ClassInfo.Method findMethodInHierarchy(String name, String desc, ClassInfo.SearchType searchType, ClassInfo.Traversal traversal, int flags)
      Finds the specified public or protected method in this class's hierarchy
      Parameters:
      name - Method name to search for
      desc - Method descriptor
      searchType - Search strategy to use
      traversal - Traversal type to allow during this lookup
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(org.objectweb.asm.tree.FieldNode field, ClassInfo.SearchType searchType)
      Finds the specified private or protected field in this class's hierarchy
      Parameters:
      field - Field to search for
      searchType - Search strategy to use
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(org.objectweb.asm.tree.FieldNode field, ClassInfo.SearchType searchType, int flags)
      Finds the specified private or protected field in this class's hierarchy
      Parameters:
      field - Field to search for
      searchType - Search strategy to use
      flags - search flags
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(org.objectweb.asm.tree.FieldInsnNode field, ClassInfo.SearchType searchType)
      Finds the specified public or protected field in this class's hierarchy
      Parameters:
      field - Field to search for
      searchType - Search strategy to use
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(org.objectweb.asm.tree.FieldInsnNode field, ClassInfo.SearchType searchType, int flags)
      Finds the specified public or protected field in this class's hierarchy
      Parameters:
      field - Field to search for
      searchType - Search strategy to use
      flags - search flags
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(String name, String desc, ClassInfo.SearchType searchType)
      Finds the specified public or protected field in this class's hierarchy
      Parameters:
      name - Field name to search for
      desc - Field descriptor
      searchType - Search strategy to use
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(String name, String desc, ClassInfo.SearchType searchType, int flags)
      Finds the specified public or protected field in this class's hierarchy
      Parameters:
      name - Field name to search for
      desc - Field descriptor
      searchType - Search strategy to use
      flags - search flags
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(String name, String desc, ClassInfo.SearchType searchType, ClassInfo.Traversal traversal)
      Finds the specified public or protected field in this class's hierarchy
      Parameters:
      name - Field name to search for
      desc - Field descriptor
      searchType - Search strategy to use
      traversal - Traversal type to allow during this lookup
      Returns:
      the field object or null if the field could not be resolved
    • findFieldInHierarchy

      public ClassInfo.Field findFieldInHierarchy(String name, String desc, ClassInfo.SearchType searchType, ClassInfo.Traversal traversal, int flags)
      Finds the specified public or protected field in this class's hierarchy
      Parameters:
      name - Field name to search for
      desc - Field descriptor
      searchType - Search strategy to use
      traversal - Traversal type to allow during this lookup
      flags - search flags
      Returns:
      the field object or null if the field could not be resolved
    • findMethod

      public ClassInfo.Method findMethod(org.objectweb.asm.tree.MethodNode method)
      Finds the specified public or protected method in this class
      Parameters:
      method - Method to search for
      Returns:
      the method object or null if the method could not be resolved
    • findMethod

      public ClassInfo.Method findMethod(org.objectweb.asm.tree.MethodNode method, int flags)
      Finds the specified public or protected method in this class
      Parameters:
      method - Method to search for
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findMethod

      public ClassInfo.Method findMethod(org.objectweb.asm.tree.MethodInsnNode method)
      Finds the specified public or protected method in this class
      Parameters:
      method - Method to search for
      Returns:
      the method object or null if the method could not be resolved
    • findMethod

      public ClassInfo.Method findMethod(org.objectweb.asm.tree.MethodInsnNode method, int flags)
      Finds the specified public or protected method in this class
      Parameters:
      method - Method to search for
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findMethod

      public ClassInfo.Method findMethod(String name, String desc, int flags)
      Finds the specified public or protected method in this class
      Parameters:
      name - Method name to search for
      desc - Method signature to search for
      flags - search flags
      Returns:
      the method object or null if the method could not be resolved
    • findField

      public ClassInfo.Field findField(org.objectweb.asm.tree.FieldNode field)
      Finds the specified field in this class
      Parameters:
      field - Field to search for
      Returns:
      the field object or null if the field could not be resolved
    • findField

      public ClassInfo.Field findField(org.objectweb.asm.tree.FieldInsnNode field, int flags)
      Finds the specified public or protected method in this class
      Parameters:
      field - Field to search for
      flags - search flags
      Returns:
      the field object or null if the field could not be resolved
    • findField

      public ClassInfo.Field findField(String name, String desc, int flags)
      Finds the specified field in this class
      Parameters:
      name - Field name to search for
      desc - Field signature to search for
      flags - search flags
      Returns:
      the field object or null if the field could not be resolved
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • forName

      public static ClassInfo forName(String className)
      Return a ClassInfo for the specified class name, fetches the ClassInfo from the cache where possible.
      Parameters:
      className - Binary name of the class to look up
      Returns:
      ClassInfo for the specified class name or null if the specified name cannot be resolved for some reason
    • forDescriptor

      public static ClassInfo forDescriptor(String descriptor, ClassInfo.TypeLookup lookup)
      Return a ClassInfo for the specified type descriptor, fetches the ClassInfo from the cache where possible.
      Parameters:
      descriptor - Internal descriptor of the type to inspect
      lookup - Lookup type to use (literal/element)
      Returns:
      ClassInfo for the specified class name or null if the specified name cannot be resolved for some reason
    • forType

      public static ClassInfo forType(org.objectweb.asm.Type type, ClassInfo.TypeLookup lookup)
      Return a ClassInfo for the specified class type, fetches the ClassInfo from the cache where possible and generates the class meta if not.
      Parameters:
      type - Type to look up
      lookup - Lookup type to use (literal/element)
      Returns:
      ClassInfo for the supplied type or null if the supplied type cannot be found or is a primitive type
    • fromCache

      public static ClassInfo fromCache(String className)
      Return a ClassInfo for the specified class name, but only if the class information already exists in the cache. This prevents class loads in the instance that a ClassInfo is only being retrieved for a class which should definitely have already been processed but will be missing in case of an error condition.
      Parameters:
      className - Binary name of the class to look up
      Returns:
      ClassInfo for the specified class name or null if the specified class does not have an entry in the cache
    • fromCache

      public static ClassInfo fromCache(org.objectweb.asm.Type type, ClassInfo.TypeLookup lookup)
      Return a ClassInfo for the specified class type, but only if the class information already exists in the cache. This prevents class loads in the instance that a ClassInfo is only being retrieved for a class which should definitely have already been processed but will be missing in case of an error condition.
      Parameters:
      type - Type to look up
      lookup - Lookup type to use (literal/element)
      Returns:
      ClassInfo for the supplied type or null if the supplied type does not have an entry in the cache
    • getCommonSuperClass

      public static ClassInfo getCommonSuperClass(String type1, String type2)
      ASM logic applied via ClassInfo, returns first common superclass of classes specified by type1 and type2.
      Parameters:
      type1 - First type
      type2 - Second type
      Returns:
      common superclass info
    • getCommonSuperClass

      public static ClassInfo getCommonSuperClass(org.objectweb.asm.Type type1, org.objectweb.asm.Type type2)
      ASM logic applied via ClassInfo, returns first common superclass of classes specified by type1 and type2.
      Parameters:
      type1 - First type
      type2 - Second type
      Returns:
      common superclass info
    • getCommonSuperClassOrInterface

      public static ClassInfo getCommonSuperClassOrInterface(String type1, String type2)
      ASM logic applied via ClassInfo, returns first common superclass of classes specified by type1 and type2.
      Parameters:
      type1 - First type
      type2 - Second type
      Returns:
      common superclass info
    • getCommonSuperClassOrInterface

      public static ClassInfo getCommonSuperClassOrInterface(org.objectweb.asm.Type type1, org.objectweb.asm.Type type2)
      ASM logic applied via ClassInfo, returns first common superclass of classes specified by type1 and type2.
      Parameters:
      type1 - First type
      type2 - Second type
      Returns:
      common superclass info
    • getCommonSuperClassOrInterface

      public static ClassInfo getCommonSuperClassOrInterface(ClassInfo type1, ClassInfo type2)
      ASM logic applied via ClassInfo, returns first common superclass or interface of classes specified by type1 and type2.
      Parameters:
      type1 - First type
      type2 - Second type
      Returns:
      common superclass info