Class RuntimeEnumExtender

java.lang.Object
net.neoforged.fml.common.asm.enumextension.RuntimeEnumExtender
All Implemented Interfaces:
ClassProcessor

@Internal public class RuntimeEnumExtender extends Object implements ClassProcessor
Transforms enums implementing IExtensibleEnum to add additional entries loaded from files provided by mods
  • Field Details

    • MARKER_IFACE

      private static final Type MARKER_IFACE
    • INDEXED_ANNOTATION

      private static final Type INDEXED_ANNOTATION
    • NAMED_ANNOTATION

      private static final Type NAMED_ANNOTATION
    • RESERVED_ANNOTATION

      private static final Type RESERVED_ANNOTATION
    • ENUM_PROXY

      private static final Type ENUM_PROXY
    • NET_CHECK

      private static final Type NET_CHECK
    • EXT_INFO

      private static final Type EXT_INFO
    • EXT_INFO_GETTER_DESC

      private static final String EXT_INFO_GETTER_DESC
    • EXT_INFO_CTOR_DESC

      private static final String EXT_INFO_CTOR_DESC
    • NETWORKED_ANNOTATION

      private static final Type NETWORKED_ANNOTATION
    • EXTENDER

      private static final Type EXTENDER
    • ARRAYS

      private static final Type ARRAYS
    • ENUM_FLAGS

      private static final int ENUM_FLAGS
      See Also:
    • ARRAY_FLAGS

      private static final int ARRAY_FLAGS
      See Also:
    • EXT_INFO_FLAGS

      private static final int EXT_INFO_FLAGS
      See Also:
    • prototypes

      private static Map<String,List<EnumPrototype>> prototypes
  • Constructor Details

    • RuntimeEnumExtender

      public RuntimeEnumExtender()
  • Method Details

    • name

      public ProcessorName name()
      Description copied from interface: ClassProcessor
      Returns a unique identifier for this processor.
      Specified by:
      name in interface ClassProcessor
      Returns:
      a unique identifier for this processor
    • runsBefore

      public Set<ProcessorName> runsBefore()
      Description copied from interface: ClassProcessor
      Returns processors that this processor must run before.
      Specified by:
      runsBefore in interface ClassProcessor
      Returns:
      processors that this processor must run before
    • orderingHint

      public ClassProcessor.OrderingHint orderingHint()
      Description copied from interface: ClassProcessor
      Returns a hint for how this processor should be ordered relative to other processors. Note that this is a comparatively weak hint; ClassProcessor.runsBefore() and ClassProcessor.runsAfter() take precedence, and processors don't have "phases" of any sort.
      Specified by:
      orderingHint in interface ClassProcessor
      Returns:
      a hint for how this processor should be ordered relative to other processors
    • handlesClass

      public boolean handlesClass(ClassProcessor.SelectionContext context)
      Description copied from interface: ClassProcessor
      Returns whether the processor wants to recieve the class.
      Specified by:
      handlesClass in interface ClassProcessor
      Parameters:
      context - the context of the class to consider
      Returns:
      whether the processor wants to recieve the class
    • processClass

      Description copied from interface: ClassProcessor
      Each class that the processor has opted to recieve is passed to this method for processing.
      Specified by:
      processClass in interface ClassProcessor
      Parameters:
      context - the context of the class to process
      Returns:
      the ClassProcessor.ComputeFlags indicating how the class should be rewritten.
    • findFirstStaticMethodCall

      public static org.objectweb.asm.tree.MethodInsnNode findFirstStaticMethodCall(org.objectweb.asm.tree.MethodNode method, String owner, String name, String descriptor)
      Finds the first static method call in the given method matching the given owner, name and descriptor
      Parameters:
      method - the method to search in
      owner - the method call's owner to search for
      name - the method call's name
      descriptor - the method call's descriptor
      Returns:
      the found method call node, null if none matched after the given index
    • findFirstInstructionBefore

      public static org.objectweb.asm.tree.AbstractInsnNode findFirstInstructionBefore(org.objectweb.asm.tree.MethodNode method, int opCode, int startIndex)
      Finds the first instruction with matching opcode before the given index in reverse search
      Parameters:
      method - the method to search in
      opCode - the opcode to search for
      startIndex - the index at which to start searching (inclusive)
      Returns:
      the found instruction node or null if none matched before the given startIndex
    • tryFindMethod

      private static Optional<org.objectweb.asm.tree.MethodNode> tryFindMethod(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.MethodNode> predicate)
    • findMethod

      private static org.objectweb.asm.tree.MethodNode findMethod(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.MethodNode> predicate)
    • findField

      private static org.objectweb.asm.tree.FieldNode findField(org.objectweb.asm.tree.ClassNode classNode, Predicate<org.objectweb.asm.tree.FieldNode> predicate)
    • clearMethod

      private static void clearMethod(org.objectweb.asm.tree.MethodNode mth)
    • getVanillaEntryCount

      private static int getVanillaEntryCount(org.objectweb.asm.tree.ClassNode classNode, Type classType)
    • getParameterIndexFromAnnotation

      private static int getParameterIndexFromAnnotation(org.objectweb.asm.tree.ClassNode classNode, Type annoType)
    • isAllowedConstructor

      private static boolean isAllowedConstructor(org.objectweb.asm.tree.MethodNode mth)
    • findValuesArrayCreation

      private static org.objectweb.asm.tree.AbstractInsnNode findValuesArrayCreation(Type classType, org.objectweb.asm.tree.MethodNode clinit)
    • findValuesArrayStore

      private static org.objectweb.asm.tree.FieldInsnNode findValuesArrayStore(Type classType, org.objectweb.asm.tree.ClassNode classNode, org.objectweb.asm.tree.MethodNode mth, String owner)
    • createEnumEntries

      private static List<org.objectweb.asm.tree.FieldNode> createEnumEntries(Type classType, ListGeneratorAdapter generator, Set<String> ctors, int idParamIdx, int nameParamIdx, int vanillaEntryCount, List<EnumPrototype> prototypes)
    • loadConstructorParams

      private static void loadConstructorParams(ListGeneratorAdapter generator, int idParamIdx, int nameParamIdx, int ordinal, EnumPrototype proto)
    • buildExtensionInfo

      private static void buildExtensionInfo(org.objectweb.asm.tree.ClassNode classNode, Type classType, ListGeneratorAdapter generator, org.objectweb.asm.tree.FieldNode infoField, int vanillaCount, int moddedCount)
    • returnValuesToExtender

      private static void returnValuesToExtender(Type classType, ListGeneratorAdapter generator, List<EnumPrototype> protos, List<org.objectweb.asm.tree.FieldNode> entries)
    • appendValuesArray

      private static void appendValuesArray(Type classType, ListGeneratorAdapter generator, List<org.objectweb.asm.tree.FieldNode> enumEntries)
    • loadEnumPrototypes

      public static void loadEnumPrototypes(Map<IModInfo,JarResource> paths)
    • validateNameParameter

      public static String validateNameParameter(String fieldName, String owningMod)