Skip to content

Commit

Permalink
Remap method descriptor even when the method can't be found
Browse files Browse the repository at this point in the history
  • Loading branch information
DenWav committed Nov 19, 2020
1 parent 87b3f39 commit c2b92fc
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/main/java/org/cadixdev/at/impl/AccessTransformSetMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.cadixdev.at.impl;

import org.cadixdev.at.AccessTransformSet;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.model.ClassMapping;
import org.cadixdev.lorenz.model.FieldMapping;
Expand All @@ -46,24 +47,40 @@ static AccessTransformSet remap(AccessTransformSet set, MappingSet mappings) {
AccessTransformSet remapped = AccessTransformSet.create();
set.getClasses().forEach((className, classSet) -> {
Optional<? extends ClassMapping<?, ?>> mapping = mappings.getClassMapping(className);
remap(mapping, classSet, remapped.getOrCreateClass(mapping.map(Mapping::getFullDeobfuscatedName).orElse(className)));
remap(mapping.orElse(null), classSet, remapped.getOrCreateClass(mapping.map(Mapping::getFullDeobfuscatedName).orElse(className)));
});
return remapped;
}

private static void remap(Optional<? extends ClassMapping<?, ?>> mapping,
AccessTransformSet.Class set, AccessTransformSet.Class remapped) {
private static void remap(ClassMapping<?, ?> mapping, AccessTransformSet.Class set, AccessTransformSet.Class remapped) {
remapped.merge(set.get());
remapped.mergeAllFields(set.allFields());
remapped.mergeAllMethods(set.allMethods());

set.getFields().forEach((name, transform) ->
remapped.mergeField(mapping.flatMap(m -> m.getFieldMapping(name))
.map(FieldMapping::getDeobfuscatedName).orElse(name), transform));
if (mapping == null) {
set.getFields().forEach(remapped::mergeField);
set.getMethods().forEach(remapped::mergeMethod);
} else {
set.getFields().forEach((name, transform) ->
remapped.mergeField(
mapping.getFieldMapping(name)
.map(FieldMapping::getDeobfuscatedName)
.orElse(name),
transform
)
);

set.getMethods().forEach((signature, transform) ->
remapped.mergeMethod(mapping.flatMap(m -> m.getMethodMapping(signature))
.map(MethodMapping::getDeobfuscatedSignature).orElse(signature), transform));
set.getMethods().forEach((signature, transform) -> {
remapped.mergeMethod(
mapping.getMethodMapping(signature)
.map(MethodMapping::getDeobfuscatedSignature)
.orElseGet(() -> new MethodSignature(
signature.getName(),
mapping.getMappings().deobfuscate(signature.getDescriptor())
)),
transform
);
});
}
}

}

0 comments on commit c2b92fc

Please sign in to comment.