Package-level declarations
Several utilities and general definitions, forming the base of this library.
Loading (mappings) files
Type | Snippet |
---|---|
Any type of MappingsFormat | MappingsLoader.loadMappings |
An AccessWidener | loadAccessWidener |
CompactedMappings | CompactedMappingsFormat.parse |
Writing (mappings) files
Type | Snippet |
---|---|
Any type of MappingsFormat | Mappings.write |
An AccessWidener | AccessWidener.write |
CompactedMappings | CompactedMappings.write |
Mappings transformations
Name | Description |
---|---|
Mappings.renameNamespaces | Renames namespaces |
Mappings.reorderNamespaces | Reorders/duplicates namespaces |
Mappings.join | Joins two Mappings objects together |
Mappings.filterNamespaces | Filters certain namespaces by a set of allowed names, or a predicate |
Mappings.deduplicateNamespaces | Removes duplicate namespaces |
Common Mappings operations
// Parsing mappings
val lines = File("/path/to/some/mappings/file").readLines()
// The mappings format is automatically detected
val mappings = MappingsLoader.loadMappings(lines)
// Using mappings
val remapper = MappingsRemapper(
mappings,
from = "fromNamespace",
to = "toNamespace",
loader = ClasspathLoaders.fromSystemLoader()
)
val reader = ClassReader(bytes)
val writer = ClassWriter(reader)
reader.accept(LambdaAwareRemapper(writer, remapper), 0)
// Or remapping a ClassNode
val node = ClassNode()
reader.accept(node)
node.remap(remapper)
// Or for remapping a full jar
remapJar(mappings, inputFile, outputFile, "fromNamespace", "toNamespace")
// Transforming mappings
val extracted = mappings.extractNamespaces("newFrom", "newTo")
val renamed = mappings.renameNamespaces("newFirst", "newSecond", "newThird")
val reordered = mappings.reorderNamespaces("c", "b", "a")
val joined = mappings.join(otherMappings, "intermediary")
val filtered = mappings.filterNamespaces("b", "c")
val tinyMappings = mappings.asTinyMappings(v2 = true)
// Writing mappings
File("/path/to/some/mappings/file").writeText(tinyMappings.write().joinToString("\n"))
Types
An alias for a function that returns class file buffers given an internal/JVMS class name
Provides default implementations for the classpath loaders in MappingsRemapper
Represents an empty mappings object, with no data.
Represents a generic type of mapping that is not deserialized from anything, nor can be serialized to a mappings file. It does not carry format-specific metadata, and is used as an intermediate value for transforming mappings.
Represents an entry point for tasks like remapping and transformations to gather inheritance information from the classpath. Its simple design allows implementations to fetch information from different kinds of resources, like the classpath (see LoaderInheritanceProvider).
An InheritanceProvider that delegates to a ClasspathLoader, loader, to extract inheritance information
Represents a mapped local variable. This is different to a MappedParameter, because it carries data about LVT and usage in the bytecode.
Represents a mapped method
Represents a mapped parameter of a MappedMethod, which is different from a MappedLocal (see docs)
Represents any type of mappings. The names in all of the Mapped entities are in the order of the namespaces, and should have equal length arrays.
Represents a generic mappings format
The entry point for loading Mappings.
An InheritanceProvider that delegates to another given InheritanceProvider, delegate, and remembers its results.
Properties
Represents the bitmask of access flags that a member may not have to be considered inheritable, see InheritanceProvider.getDeclaredMethods
Functions
Returns a simple mapping representing all of the Mappings, mapping between the namespaces from and to. If includeMethods is true, then methods will be included in the mapping. If includeFields is true, then fields will be included in the mapping.
Converts these Mappings to CompactedMappings.
Converts these Mappings to CSRGMappings
Converts these Mappings to EnigmaMappings
Converts these Mappings to GenericMappings
Wraps this into a InheritanceProvider that uses this to extract inheritance information
Converts these Mappings to ProguardMappings.
Converts these Mappings to RecafMappings
Returns an asm SimpleRemapper for remapping references between namespaces from and to disregarding inheritance and lambdas. For proper remapping, you should use the MappingsRemapper.
Converts these Mappings to SRGMappings, enabling XSRG when extended is true.
Converts these Mappings to TinyMappings, enabling Tiny v2 when v2 is true.
Converts these Mappings to TSRGMappings, enabling TSRG v2 when v2 is true.
Removes all duplicate namespace usages in this Mappings.
Filters classes matching the predicate
Filters methods matching the predicate
Filters these Mappings to only contain namespaces that are in allowed. If allowDuplicates is true, the returned Mappings will also have duplicate namespaces removed.
Filters these Mappings to only contain namespaces for which the predicate returns true
. If allowDuplicates is true, the returned Mappings will also have duplicate namespaces removed.
Returns whether the methods represented by this MappedMethod is a data method, that is, if this method is hashCode, toString, equals or an initializer, like a constructor or init {} block (this means that the jvm names are
Joins together an Iterable of Mappings, producing new Mappings that contain all entries from all Mappings. Note: all namespaces are kept, in order to be able to reduce the mappings nicely without a lot of overhead. If you want to exclude certain namespaces, use Mappings.filterNamespaces. If this Iterable would be considered empty (its Iterator.hasNext would return false on the first iteration), EmptyMappings is returned.
Joins together this Mappings with otherMappings, by matching on intermediateNamespace, producing new Mappings that contain all entries from this Mappings and otherMappings. If requireMatch is true, this method will throw an exception when no method or field or class is found
Maps classes according to the given block
Maps methods according to the given block
Wraps this into a new provider that remembers the results of calls
Returns the index of a namespace named name, but throws an IllegalStateException when name is not in the Mappings.namespaces.
See recoverFieldDescriptors. file is a jar file resource (caller is responsible for closing it) that contains the classes that are referenced in the generic overload.
Attempts to recover field descriptors that are missing because the original mappings format did not specify them. bytesProvider is responsible for providing all of the classes that might be referenced in this Mappings object, such that the descriptors can be recovered based on named (fields can be uniquely identified by an owner-name pair). When field descriptors were not found, field mappings will not be passed onto the new Mappings as field mappings without descriptors will be considered invalid.
Attempts to recover field descriptors that are missing because the original mappings format did not specify them. nodeProvider is responsible for providing all of the ClassNodes that might be referenced in this Mappings object, such that the descriptors can be recovered based on named (fields can be uniquely identified by an owner-name pair). When field descriptors were not found, field mappings will not be passed onto the new Mappings as field mappings without descriptors will be considered invalid.
Removes redundant or straight up incorrect data from this Mappings object, by looking at the inheritance information present in class files, presented by the inheritanceProvider.
See removeRedundancy. file is a jar file resource (caller is responsible for closing it) that contains the classes that are referenced in the generic overload. Calls with identical names are being cached by this function, the caller is not responsible for this.
Swaps out the names for the namespaces in this Mappings data structure.
Swaps out the names for the namespaces in this Mappings data structure, by reordering. Duplicate names are allowed, in which case mapped entries are duplicated to fit the new order. If a name in Mappings.namespaces does not appear in order, its mapping entries will be missing in the returned Mappings.
Swaps out the names for the namespaces in this Mappings data structure, by reordering. Duplicate names are allowed, in which case mapped entries are duplicated to fit the new order. If a name in Mappings.namespaces does not appear in order, its mapping entries will be missing in the returned Mappings. If a namespace in order does not exist in this Mappings, an IllegalArgumentException will be thrown.