Package-level declarations

Several utilities and general definitions, forming the base of this library.

Loading (mappings) files

TypeSnippet
Any type of MappingsFormatcom.grappenmaker.mappings.MappingsLoader.loadMappings
An AccessWidenerloadAccessWidener
CompactedMappingsCompactedMappingsFormat.parse

Writing (mappings) files

TypeSnippet
Any type of MappingsFormatMappings.write
An AccessWidenerAccessWidener.write
CompactedMappingscom.grappenmaker.mappings.format.CompactedMappings.writeBytes

Mappings transformations

NameDescription
Mappings.renameNamespacesRenames namespaces
Mappings.reorderNamespacesReorders/duplicates namespaces
Mappings.joinJoins two Mappings objects together
Mappings.filterNamespacesFilters certain namespaces by a set of allowed names, or a predicate
Mappings.deduplicateNamespacesRemoves 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

Link copied to clipboard
typealias ClasspathLoader = (name: String) -> ByteArray?

An alias for a function that returns class file buffers given an internal/JVMS class name

Link copied to clipboard

Provides default implementations for the classpath loaders in com.grappenmaker.mappings.remap.MappingsRemapper

Link copied to clipboard

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).

Link copied to clipboard

An InheritanceProvider that delegates to a ClasspathLoader, loader, to extract inheritance information

Link copied to clipboard

An InheritanceProvider that delegates to another given InheritanceProvider, delegate, and remembers its results.

Properties

Link copied to clipboard
const val INHERITABLE_MASK: Int = 26

Represents the bitmask of access flags that a member may not have to be considered inheritable, see InheritanceProvider.getDeclaredMethods

Functions

Link copied to clipboard
fun Mappings.asASMMapping(from: String, to: String, includeMethods: Boolean = true, includeFields: Boolean = true): Map<String, String>

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.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Wraps this into a InheritanceProvider that uses this to extract inheritance information

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Returns an asm SimpleRemapper for remapping references between namespaces from and to disregarding inheritance and lambdas. For proper remapping, you should use the com.grappenmaker.mappings.remap.MappingsRemapper.

Link copied to clipboard

Converts these com.grappenmaker.mappings.format.Mappings to SRGMappings, enabling XSRG when extended is true.

Link copied to clipboard

Converts these Mappings to TinyMappings, enabling Tiny v2 when v2 is true.

Link copied to clipboard

Converts these Mappings to TSRGMappings, enabling TSRG v2 when v2 is true.

Link copied to clipboard

Removes all duplicate namespace usages in this Mappings.

Link copied to clipboard

Transforms this com.grappenmaker.mappings.format.Mappings structure to a generic mappings implementation that maps between from and to.

Link copied to clipboard
inline fun Mappings.filterClasses(predicate: (MappedClass) -> Boolean): Mappings

Filters classes matching the predicate

Link copied to clipboard
inline fun Mappings.filterMethods(predicate: (owner: MappedClass, method: MappedMethod) -> Boolean): Mappings

Filters methods matching the predicate

Link copied to clipboard
inline fun Mappings.filterNamespaces(allowDuplicates: Boolean = false, predicate: (String) -> Boolean): Mappings

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.

fun Mappings.filterNamespaces(allowed: Set<String>, allowDuplicates: Boolean = false): Mappings
fun Mappings.filterNamespaces(vararg allowed: String, allowDuplicates: Boolean = false): Mappings

Filters these Mappings to only contain namespaces that are in allowed. If allowDuplicates is true, the returned Mappings will also have duplicate namespaces removed.

Link copied to clipboard

Returns whether the methods represented by this com.grappenmaker.mappings.format.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 and , respectively)

Link copied to clipboard
fun Iterable<Mappings>.join(intermediateNamespace: String, requireMatch: Boolean = false): Mappings

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.

fun Mappings.join(otherMappings: Mappings, intermediateNamespace: String, requireMatch: Boolean = false): Mappings

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

Link copied to clipboard

Maps classes according to the given block

Link copied to clipboard
inline fun Mappings.mapMethods(block: (owner: MappedClass, method: MappedMethod) -> MappedMethod): Mappings

Maps methods according to the given block

Link copied to clipboard

Wraps this into a new provider that remembers the results of calls

Composes this to a new classpath loader, that caches the results of this

Link copied to clipboard

Composes this to a new classpath loader, that caches the results of this inside of a given memo

Link copied to clipboard

Returns the index of a namespace named name, but throws an IllegalStateException when name is not in the com.grappenmaker.mappings.format.Mappings.namespaces.

Link copied to clipboard

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.

fun Mappings.recoverFieldDescriptors(bytesProvider: (name: String) -> ByteArray?): Mappings

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.

@JvmName(name = "recoverDescsByNode")
fun Mappings.recoverFieldDescriptors(nodeProvider: (name: String) -> ClassNode?): Mappings

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.

Link copied to clipboard

Composes this to create a new classpath loader, that maps bytes given by this using a remapper

Link copied to clipboard

Composes this to create a new classpath loader, that maps names before passing them to this between namespaces from and to using given mappings. It also alters the returned class file's class name references to match the to namespace. Method and field names remain untouched.

Link copied to clipboard

Returns new Mappings that are identical to these Mappings, except the comments will be removed

Link copied to clipboard
fun Mappings.removeRedundancy(inheritanceProvider: InheritanceProvider, removeDuplicateMethods: Boolean = false): Mappings

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.

fun Mappings.removeRedundancy(file: JarFile, removeDuplicateMethods: Boolean = false): Mappings

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.

fun Mappings.removeRedundancy(removeDuplicateMethods: Boolean = false, loader: ClasspathLoader): Mappings

Removes redundant or straight up incorrect data from this Mappings object, by looking at the inheritance information present in class files, presented by the loader.

Link copied to clipboard

Swaps out the names for the namespaces in this Mappings data structure.

Link copied to clipboard

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.

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.

Link copied to clipboard

Writes a Sequence of lines to an output stream, separated by newlines