Class AccessorInfo

All Implemented Interfaces:
IInjectionPointContext, IMessageSink

public class AccessorInfo
extends SpecialMethodInfo
Information about an accessor
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  AccessorInfo.AccessorName
    Accessor Name struct
    static class  AccessorInfo.AccessorType
    Accessor types
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass
    Annotation class
    protected org.objectweb.asm.Type[] argTypes
    Accessor method argument types (raw, from method)
    protected AccessorGenerator generator
    Generator which will be responsible for actually generating the accessor method body
    protected boolean isStatic
    Accessor method staticness
    protected org.objectweb.asm.Type returnType
    Accessor method return type (raw, from method)
    protected java.lang.String specifiedName
    Name specified in the attached annotation, can be null
    protected ITargetSelector target
    Computed information about the target field or method, name and descriptor
    protected org.objectweb.asm.tree.FieldNode targetField
    For accessors, stores the discovered target field
    protected org.objectweb.asm.tree.MethodNode targetMethod
    For invokers, stores the discovered target method
    protected AccessorInfo.AccessorType type
    Type of accessor to generate, computed based on the signature of the target method.

    Fields inherited from class org.spongepowered.asm.mixin.struct.SpecialMethodInfo

    annotationType, classNode, methodName, mixin

    Fields inherited from class org.spongepowered.asm.mixin.struct.AnnotatedMethodInfo

    annotation, logger, method
  • Constructor Summary

    Constructors
    Modifier Constructor Description
      AccessorInfo​(MixinTargetContext mixin, org.objectweb.asm.tree.MethodNode method)  
    protected AccessorInfo​(MixinTargetContext mixin, org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)  
  • Method Summary

    Modifier and Type Method Description
    protected <TNode> TNode findTarget​(java.util.List<ElementNode<TNode>> nodes)
    Generified candidate search, since the search logic is the same for both fields and methods.
    org.objectweb.asm.tree.MethodNode generate()
    Second pass, generate the actual accessor method for this accessor.
    org.objectweb.asm.Type[] getArgTypes()
    Get the argument types of the annotated method
    org.objectweb.asm.Type getReturnType()
    Get the return type of the annotated method
    ITargetSelector getTarget()
    Get the inflected/specified target member for this accessor
    org.objectweb.asm.tree.FieldNode getTargetField()
    For field accessors, returns the target field, returns null for invokers
    org.objectweb.asm.Type getTargetFieldType()
    For field accessors, returns the field type, returns null for invokers
    org.objectweb.asm.tree.MethodNode getTargetMethod()
    For invokers, returns the target method, returns null for field accessors
    protected java.lang.String getTargetName​(java.lang.String name)  
    protected java.lang.String inflectTarget()
    Uses the name of this accessor method and the calculated accessor type to try and inflect the name of the target field or method.
    static java.lang.String inflectTarget​(java.lang.String name, AccessorInfo.AccessorType type, java.lang.String description, IMixinContext context, boolean verbose)
    Uses the name of an accessor method and the accessor type to try and inflect the name of the target field or method.
    static java.lang.String inflectTarget​(AccessorInfo.AccessorName name, AccessorInfo.AccessorType type, java.lang.String description, IMixinContext context, boolean verbose)
    Uses the name of an accessor method and the accessor type to try and inflect the name of the target field or method.
    protected ITargetSelector initTarget()  
    protected org.objectweb.asm.Type initTargetFieldType()  
    protected AccessorInfo.AccessorType initType()  
    boolean isStatic()
    Get whether the accessor itself is static
    void locate()
    First pass, locate the target field in the class.
    static AccessorInfo of​(MixinTargetContext mixin, org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> type)
    Return a wrapper AccessorInfo of the correct type based on the method passed in.
    java.lang.String toString()  
    void validate()
    Called immediately after locate, initialises the generator for this accessor and runs validation.

    Methods inherited from class org.spongepowered.asm.mixin.struct.SpecialMethodInfo

    getClassInfo, getClassNode, getMethodName

    Methods inherited from class org.spongepowered.asm.mixin.struct.AnnotatedMethodInfo

    addMessage, getAnnotation, getContext, getMethod

    Methods inherited from class java.lang.Object

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

    • annotationClass

      protected final java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass
      Annotation class
    • argTypes

      protected final org.objectweb.asm.Type[] argTypes
      Accessor method argument types (raw, from method)
    • returnType

      protected final org.objectweb.asm.Type returnType
      Accessor method return type (raw, from method)
    • isStatic

      protected final boolean isStatic
      Accessor method staticness
    • specifiedName

      protected final java.lang.String specifiedName
      Name specified in the attached annotation, can be null
    • type

      protected final AccessorInfo.AccessorType type
      Type of accessor to generate, computed based on the signature of the target method.
    • target

      protected final ITargetSelector target
      Computed information about the target field or method, name and descriptor
    • targetField

      protected org.objectweb.asm.tree.FieldNode targetField
      For accessors, stores the discovered target field
    • targetMethod

      protected org.objectweb.asm.tree.MethodNode targetMethod
      For invokers, stores the discovered target method
    • generator

      protected AccessorGenerator generator
      Generator which will be responsible for actually generating the accessor method body
  • Constructor Details

    • AccessorInfo

      public AccessorInfo​(MixinTargetContext mixin, org.objectweb.asm.tree.MethodNode method)
    • AccessorInfo

      protected AccessorInfo​(MixinTargetContext mixin, org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
  • Method Details

    • initType

      protected AccessorInfo.AccessorType initType()
    • initTargetFieldType

      protected org.objectweb.asm.Type initTargetFieldType()
    • initTarget

      protected ITargetSelector initTarget()
    • getTargetName

      protected java.lang.String getTargetName​(java.lang.String name)
    • inflectTarget

      protected java.lang.String inflectTarget()
      Uses the name of this accessor method and the calculated accessor type to try and inflect the name of the target field or method. This allows a method named getFoo to be inflected to a target named foo for example.
    • inflectTarget

      public static java.lang.String inflectTarget​(java.lang.String name, AccessorInfo.AccessorType type, java.lang.String description, IMixinContext context, boolean verbose)
      Uses the name of an accessor method and the accessor type to try and inflect the name of the target field or method. This allows a method named getFoo to be inflected to a target named foo for example.
      Parameters:
      name - Name of the accessor method
      type - Type of accessor being processed, this is calculated from the method signature (void methods being setters, methods with return types being getters)
      description - description of the accessor to include in error messages
      context - Mixin context
      verbose - Emit warnings when accessor prefix doesn't match type
      Returns:
      inflected target member name or null if name cannot be inflected
    • inflectTarget

      public static java.lang.String inflectTarget​(AccessorInfo.AccessorName name, AccessorInfo.AccessorType type, java.lang.String description, IMixinContext context, boolean verbose)
      Uses the name of an accessor method and the accessor type to try and inflect the name of the target field or method. This allows a method named getFoo to be inflected to a target named foo for example.
      Parameters:
      name - Name of the accessor method
      type - Type of accessor being processed, this is calculated from the method signature (void methods being setters, methods with return types being getters)
      description - description of the accessor to include in error messages
      context - Mixin context
      verbose - Emit warnings when accessor prefix doesn't match type
      Returns:
      inflected target member name or null if name cannot be inflected
    • getTarget

      public final ITargetSelector getTarget()
      Get the inflected/specified target member for this accessor
    • getTargetFieldType

      public final org.objectweb.asm.Type getTargetFieldType()
      For field accessors, returns the field type, returns null for invokers
    • getTargetField

      public final org.objectweb.asm.tree.FieldNode getTargetField()
      For field accessors, returns the target field, returns null for invokers
    • getTargetMethod

      public final org.objectweb.asm.tree.MethodNode getTargetMethod()
      For invokers, returns the target method, returns null for field accessors
    • getReturnType

      public final org.objectweb.asm.Type getReturnType()
      Get the return type of the annotated method
    • getArgTypes

      public final org.objectweb.asm.Type[] getArgTypes()
      Get the argument types of the annotated method
    • isStatic

      public boolean isStatic()
      Get whether the accessor itself is static
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • locate

      public void locate()
      First pass, locate the target field in the class. This is done after all other mixins are applied so that mixin-added fields and methods can be targetted.
    • validate

      public void validate()
      Called immediately after locate, initialises the generator for this accessor and runs validation.
    • generate

      public org.objectweb.asm.tree.MethodNode generate()
      Second pass, generate the actual accessor method for this accessor. The method still respects intrinsic/mixinmerged rules so is not guaranteed to be added to the target class
      Returns:
      generated accessor method
    • findTarget

      protected <TNode> TNode findTarget​(java.util.List<ElementNode<TNode>> nodes)
      Generified candidate search, since the search logic is the same for both fields and methods.
      Type Parameters:
      TNode - node type
      Parameters:
      nodes - Node list to search (method/field list)
      Returns:
      best match
    • of

      public static AccessorInfo of​(MixinTargetContext mixin, org.objectweb.asm.tree.MethodNode method, java.lang.Class<? extends java.lang.annotation.Annotation> type)
      Return a wrapper AccessorInfo of the correct type based on the method passed in.
      Parameters:
      mixin - mixin context which owns this accessor
      method - annotated method
      type - annotation type to process
      Returns:
      parsed AccessorInfo