Interface ReflectionRemapper


@DefaultQualifier(org.checkerframework.checker.nullness.qual.NonNull.class) public interface ReflectionRemapper
Interface providing methods for remapping class, method, and field names from one mappings namespace to another.

Particularly useful for reflection, as it's not remapped by bytecode remapping.

The various standard ReflectionRemappers can be created using the provided static factory methods.

  • Method Details

    • remapClassName

      String remapClassName(String className)
      Remaps a Mojang-mapped class name to its current runtime name.
      Parameters:
      className - fully qualified class name
      Returns:
      fully qualified runtime class name
    • remapFieldName

      String remapFieldName(Class<?> holdingClass, String fieldName)
      Remaps a Mojang-mapped field name to its current runtime name.
      Parameters:
      holdingClass - class declaring the field
      fieldName - field name
      Returns:
      runtime field name
    • remapMethodName

      String remapMethodName(Class<?> holdingClass, String methodName, Class<?>... paramTypes)
      Remaps a Mojang-mapped method name to its current runtime name.
      Parameters:
      holdingClass - class declaring the method
      methodName - method name
      paramTypes - parameter types
      Returns:
      runtime method name
    • remapClassOrArrayName

      default String remapClassOrArrayName(String name)
      Remaps a Mojang-mapped class or array name (as given to Class.forName(String)) to its current runtime name using remapClassName(String).
      Parameters:
      name - class or array name
      Returns:
      remapped name
    • withClassNamePreprocessor

      default ReflectionRemapper withClassNamePreprocessor(UnaryOperator<String> preprocessor)
      Creates a new reflection remapper that processes class names using the provided operator before remapping them with this remapper.

      This may be useful when class names must be mangled to avoid relocation.

      Parameters:
      preprocessor - class name preprocessor
      Returns:
      delegating reflection remapper
    • noop

      static ReflectionRemapper noop()
      Returns a noop ReflectionRemapper instance which simply passes through the given names without remapping.
      Returns:
      noop reflection remapper
    • forMappings

      static ReflectionRemapper forMappings(InputStream mappings, String fromNamespace, String toNamespace)
      Creates a new ReflectionRemapper from the given mappings.

      Note that this does not close the provided InputStream.

      Parameters:
      mappings - mappings
      fromNamespace - from namespace
      toNamespace - to namespace
      Returns:
      reflection remapper
    • forMappings

      static ReflectionRemapper forMappings(Path mappings, String fromNamespace, String toNamespace)
      Creates a new ReflectionRemapper from the given mappings.
      Parameters:
      mappings - mappings
      fromNamespace - from namespace
      toNamespace - to namespace
      Returns:
      reflection remapper
    • forPaperReobfMappings

      static ReflectionRemapper forPaperReobfMappings(Path mappings)
      Creates a new ReflectionRemapper using the provided Paper reobfuscation mappings.

      If the current environment is detected to be Mojang-mapped, noop() will be returned rather than reading the mappings and creating an actual remapping ReflectionRemapper.

      Parameters:
      mappings - reobf mappings
      Returns:
      reflection remapper
    • forPaperReobfMappings

      static ReflectionRemapper forPaperReobfMappings(InputStream mappings)
      Creates a new ReflectionRemapper using the provided Paper reobfuscation mappings.

      If the current environment is detected to be Mojang-mapped, noop() will be returned rather than reading the mappings and creating an actual remapping ReflectionRemapper.

      Note that this does not close the provided InputStream.

      Parameters:
      mappings - reobf mappings
      Returns:
      reflection remapper
    • forReobfMappingsInPaperJar

      static ReflectionRemapper forReobfMappingsInPaperJar()
      Creates a new ReflectionRemapper using the reobf mappings file inside reobfuscated Paper jars.

      If the current environment is detected to be Mojang-mapped, noop() will be returned rather than reading the mappings and creating an actual remapping ReflectionRemapper.

      Returns:
      reflection remapper