Class ReferenceMapper
- java.lang.Object
-
- org.spongepowered.asm.mixin.refmap.ReferenceMapper
-
- All Implemented Interfaces:
java.io.Serializable,IReferenceMapper
public final class ReferenceMapper extends java.lang.Object implements IReferenceMapper, java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ReferenceMapperDEFAULT_MAPPERPassthrough mapper, used as failoverstatic java.lang.StringDEFAULT_RESOURCEResource to attempt to load if no source is specified explicitly
-
Constructor Summary
Constructors Constructor Description ReferenceMapper()Create an empty refmap
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringaddMapping(java.lang.String context, java.lang.String className, java.lang.String reference, java.lang.String newReference)Add a mapping to this refmapjava.lang.StringgetContext()Get the current contextjava.lang.StringgetResourceName()Get the resource name this refmap was loaded from (if available).java.lang.StringgetStatus()Get a user-readable "status" string for this refmap for use in error messagesbooleanisDefault()Get whether this mapper is defaulted.static ReferenceMapperread(java.io.Reader reader, java.lang.String name)Read a new refmap instance from the specified readerstatic ReferenceMapperread(java.lang.String resourcePath)Read a new refmap from the specified resourcejava.lang.Stringremap(java.lang.String className, java.lang.String reference)Remap a reference for the specified owning class in the current contextjava.lang.StringremapWithContext(java.lang.String context, java.lang.String className, java.lang.String reference)Remap a reference for the specified owning class in the specified contextvoidsetContext(java.lang.String context)Set the current remap context, can be nullvoidwrite(java.lang.Appendable writer)Write this refmap out to the specified writer
-
-
-
Field Detail
-
DEFAULT_RESOURCE
public static final java.lang.String DEFAULT_RESOURCE
Resource to attempt to load if no source is specified explicitly- See Also:
- Constant Field Values
-
DEFAULT_MAPPER
public static final ReferenceMapper DEFAULT_MAPPER
Passthrough mapper, used as failover
-
-
Method Detail
-
isDefault
public boolean isDefault()
Description copied from interface:IReferenceMapperGet whether this mapper is defaulted. Use this flag rather than reference comparison toDEFAULT_MAPPERbecause of classloader shenanigans- Specified by:
isDefaultin interfaceIReferenceMapper- Returns:
- true if this mapper is a defaulted mapper
-
getResourceName
public java.lang.String getResourceName()
Description copied from interface:IReferenceMapperGet the resource name this refmap was loaded from (if available).- Specified by:
getResourceNamein interfaceIReferenceMapper- Returns:
- name of the resource
-
getStatus
public java.lang.String getStatus()
Description copied from interface:IReferenceMapperGet a user-readable "status" string for this refmap for use in error messages- Specified by:
getStatusin interfaceIReferenceMapper- Returns:
- status message
-
getContext
public java.lang.String getContext()
Description copied from interface:IReferenceMapperGet the current context- Specified by:
getContextin interfaceIReferenceMapper- Returns:
- current context key, can be null
-
setContext
public void setContext(java.lang.String context)
Description copied from interface:IReferenceMapperSet the current remap context, can be null- Specified by:
setContextin interfaceIReferenceMapper- Parameters:
context- remap context
-
remap
public java.lang.String remap(java.lang.String className, java.lang.String reference)Description copied from interface:IReferenceMapperRemap a reference for the specified owning class in the current context- Specified by:
remapin interfaceIReferenceMapper- Parameters:
className- Owner classreference- Reference to remap- Returns:
- remapped reference, returns original reference if not remapped
-
remapWithContext
public java.lang.String remapWithContext(java.lang.String context, java.lang.String className, java.lang.String reference)Description copied from interface:IReferenceMapperRemap a reference for the specified owning class in the specified context- Specified by:
remapWithContextin interfaceIReferenceMapper- Parameters:
context- Remap context to useclassName- Owner classreference- Reference to remap- Returns:
- remapped reference, returns original reference if not remapped
-
addMapping
public java.lang.String addMapping(java.lang.String context, java.lang.String className, java.lang.String reference, java.lang.String newReference)Add a mapping to this refmap- Parameters:
context- Obfuscation context, can be nullclassName- Class which owns this mapping, cannot be nullreference- Reference to remap, cannot be nullnewReference- Remapped value, cannot be null- Returns:
- replaced value, per the contract of
Map.put(K, V)
-
write
public void write(java.lang.Appendable writer)
Write this refmap out to the specified writer- Parameters:
writer- Writer to write to
-
read
public static ReferenceMapper read(java.lang.String resourcePath)
Read a new refmap from the specified resource- Parameters:
resourcePath- Resource to read from- Returns:
- new refmap or
DEFAULT_MAPPERif reading fails
-
read
public static ReferenceMapper read(java.io.Reader reader, java.lang.String name)
Read a new refmap instance from the specified reader- Parameters:
reader- Reader to read fromname- Name of the resource being read from- Returns:
- new refmap
-
-