Class ReferenceMapper

java.lang.Object
org.spongepowered.asm.mixin.refmap.ReferenceMapper
All Implemented Interfaces:
Serializable, IReferenceMapper

public final class ReferenceMapper extends Object implements IReferenceMapper, Serializable
Stores runtime information allowing field, method and type references which cannot be hard remapped by the reobfuscation process to be remapped in a "soft" manner at runtime. Refmaps are generated by the Annotation Processor at compile time and must be bundled with an obfuscated binary to allow obfuscated references in injectors and other String-defined targets to be remapped to the target obfsucation environment as appropriate. If the refmap is absent the environment is assumed to be deobfuscated (eg. dev-time) and injections and other transformations will fail if this is not the case.
See Also:
  • Field Details

    • DEFAULT_RESOURCE

      public static final String DEFAULT_RESOURCE
      Resource to attempt to load if no source is specified explicitly
      See Also:
    • DEFAULT_MAPPER

      public static final ReferenceMapper DEFAULT_MAPPER
      Passthrough mapper, used as failover
  • Constructor Details

    • ReferenceMapper

      public ReferenceMapper()
      Create an empty refmap
  • 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 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
    • addMapping

      public String addMapping(String context, String className, String reference, String newReference)
      Add a mapping to this refmap
      Parameters:
      context - Obfuscation context, can be null
      className - Class which owns this mapping, cannot be null
      reference - Reference to remap, cannot be null
      newReference - Remapped value, cannot be null
      Returns:
      replaced value, per the contract of Map.put(K, V)
    • write

      public void write(Appendable writer)
      Write this refmap out to the specified writer
      Parameters:
      writer - Writer to write to
    • read

      public static ReferenceMapper read(String resourcePath)
      Read a new refmap from the specified resource
      Parameters:
      resourcePath - Resource to read from
      Returns:
      new refmap or DEFAULT_MAPPER if reading fails
    • read

      public static ReferenceMapper read(Reader reader, String name)
      Read a new refmap instance from the specified reader
      Parameters:
      reader - Reader to read from
      name - Name of the resource being read from
      Returns:
      new refmap