Class RemappingReferenceMapper

java.lang.Object
org.spongepowered.asm.mixin.refmap.RemappingReferenceMapper
All Implemented Interfaces:
IReferenceMapper

public final class RemappingReferenceMapper extends Object implements IReferenceMapper
This adapter is designed to address a problem with mixins when "deobfCompile" dependencies are used in a project which is using newer MCP mappings than the ones the imported dependency was compiled with.

Before now, refMaps in deobfCompile dependencies had to be disabled because the obfuscated mappings were no use in a development environment. However there existed no "mcp-to-different-version-of-mcp" mappings to use instead.

This class leverages the fact that mappings are provided into the environment by GradleStart and consumes SRG mappings in the imported refMaps and converts them on-the-fly using srg-to-mcp mappings. This allows refMaps to be normalised to the current MCP environment.

Note that this class takes a naïve approach to remapping on the basis that searge names are unique and can thus be remapped with a straightforward dumb string replacement. Whilst the input environment and mappings are customisable via the appropriate environment vars, this fact should be taken into account if a different mapping environment is to be used.

All lookups are straightforward string replacements using all values in the map, this basically means this is probably pretty slow, but I don't care because the number of mappings processed is usually pretty small (few hundred at most) and this is only used in dev where we don't actually care about speed. Some performance is gained (approx 10ms per lookup) by caching the transformed descriptors.

  • Method Details

    • isDefault

      public boolean isDefault()
      Description copied from interface: IReferenceMapper
      Get whether this mapper is defaulted. Use this flag rather than reference comparison to ReferenceMapper.DEFAULT_MAPPER because of classloader shenanigans
      Specified by:
      isDefault in interface IReferenceMapper
      Returns:
      true if this mapper is a defaulted mapper
    • getResourceName

      public String getResourceName()
      Description copied from interface: IReferenceMapper
      Get the resource name this refmap was loaded from (if available).
      Specified by:
      getResourceName in interface IReferenceMapper
      Returns:
      name of the resource
    • getStatus

      public String getStatus()
      Description copied from interface: IReferenceMapper
      Get a user-readable "status" string for this refmap for use in error messages
      Specified by:
      getStatus in interface IReferenceMapper
      Returns:
      status message
    • getContext

      public String getContext()
      Description copied from interface: IReferenceMapper
      Get the current context
      Specified by:
      getContext in interface IReferenceMapper
      Returns:
      current context key, can be null
    • setContext

      public void setContext​(String context)
      Description copied from interface: IReferenceMapper
      Set the current remap context, can be null
      Specified by:
      setContext in interface IReferenceMapper
      Parameters:
      context - remap context
    • remap

      public String remap​(String className, String reference)
      Description copied from interface: IReferenceMapper
      Remap a reference for the specified owning class in the current context
      Specified by:
      remap in interface IReferenceMapper
      Parameters:
      className - Owner class
      reference - Reference to remap
      Returns:
      remapped reference, returns original reference if not remapped
    • remapWithContext

      public String remapWithContext​(String context, String className, String reference)
      Description copied from interface: IReferenceMapper
      Remap a reference for the specified owning class in the specified context
      Specified by:
      remapWithContext in interface IReferenceMapper
      Parameters:
      context - Remap context to use
      className - Owner class
      reference - Reference to remap
      Returns:
      remapped reference, returns original reference if not remapped
    • of

      public static IReferenceMapper of​(MixinEnvironment env, IReferenceMapper refMap)
      Wrap the specified refmap in a remapping adapter using settings in the supplied environment
      Parameters:
      env - environment to read configuration from
      refMap - refmap to wrap
      Returns:
      wrapped refmap or original refmap is srg data is not available