KmRemap

internal class KmRemap(val r: Remapper)

Rewrites a @Metadata proto so it agrees with the bytecode r just rewrote. One walk serves both directions: the direction is r's business and none of this walk's.

No direction flag, because member names go through Remapper.mapMethodName / Remapper.mapFieldName and ASM's base answers those with the name it was given — a class-only remapper opts out by not overriding them. The snippet weave does override them, and must: it renames an override in bytecode (getDescriptionId ->method_7876), and a proto still spelling the mojmap name is the same disagreement one level down.

Constructors

Link copied to clipboard
constructor(r: Remapper)

Properties

Link copied to clipboard
private val r: Remapper

Functions

Link copied to clipboard
private fun mapClassName(name: ClassName): ClassName?

The ClassName form of Remapper.map: metadata separates nested classes with '.' where bytecode uses '$', and a leading '.' marks a local class, which is never a mapped name. Null when unmapped — the identity a Remapper answers with instead is not a usable "no" for a caller that must leave the field untouched.

Link copied to clipboard

Both halves of a method signature, each read off the ORIGINAL: the name is looked up BY the old descriptor, so mapping the descriptor first would ask the tables about a signature that never existed.

Link copied to clipboard
fun rename(c: KmClass, owner: String)

Rename c's own name, its annotations, supertypes, constructors, enum entries and every member. owner is the class file c came from, in the source namespace member lookups key on. Passed in, not derived from c's name: a named local class's (Mcp_eval_17.MyPos) does not even spell its class file (Mcp_eval_17$1$MyPos).

fun rename(p: KmPackage, owner: String)

Rename every member of a file facade or multi-file part. owner is the facade class the members live on — a KmPackage does not carry it, and member lookups need it.

Link copied to clipboard

The proto keeps annotations of its own: type-use ones live nowhere else, and the compiler reads declaration ones from here in preference to the class file. Their ARGUMENTS name classes just as their own type does.

Link copied to clipboard

else takes the literals, and whatever argument kind a later metadata version adds: passing one through costs a stale name inside an annotation, throwing on it would cost the whole class.

Link copied to clipboard
private fun renameMembers(owner: String, fns: List<KmFunction>, props: List<KmProperty>, tas: List<KmTypeAlias>, locals: List<KmProperty>)

The type-bearing members of a class or package body — the shape openMembers walks for visibility, plus locals, the delegates declared inside a function body (val x by lazy {}), which carry a type of their own and reach the proto through no other list. The JVM signatures go too: they are what the backend and kotlin-reflect link against, so leaving them in the old namespace while the Kotlin types moved would split the two views of one member.

Link copied to clipboard
Link copied to clipboard
private fun renameProperty(owner: String, p: KmProperty)
Link copied to clipboard
private fun renameType(t: KmType)

Rewrite every classifier reachable from t. Types nest through arguments, abbreviation, outer type and the flexible upper bound, so touching the classifier alone would miss most of a generic signature.

Link copied to clipboard