Commit 63729dc5 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch 'jamierocks/asm-pr/inner-class-remapping'

parents fa06d420 2db91a42
Pipeline #2836 passed with stage
in 6 minutes and 40 seconds
......@@ -168,7 +168,7 @@ public class ClassRemapper extends ClassVisitor {
super.visitInnerClass(
remapper.mapType(name),
outerName == null ? null : remapper.mapType(outerName),
innerName,
innerName == null ? null : remapper.mapInnerClassName(name, outerName, innerName),
access);
}
......
......@@ -236,6 +236,26 @@ public abstract class Remapper {
return new SignatureRemapper(signatureVisitor, this);
}
/**
* Maps an inner class name to its new name. The default implementation of this method provides a
* strategy that will work for inner classes produced by Java, but not necessarily other
* languages. Subclasses can override.
*
* @param name the fully-qualified internal name of the inner class.
* @param ownerName the internal name of the owner class of the inner class.
* @param innerName the internal name of the inner class.
* @return the new inner name of the inner class.
*/
public String mapInnerClassName(
final String name, final String ownerName, final String innerName) {
final String remappedInnerName = this.mapType(name);
if (remappedInnerName.contains("$")) {
return remappedInnerName.substring(remappedInnerName.lastIndexOf('$') + 1);
} else {
return innerName;
}
}
/**
* Maps a method name to its new name. The default implementation of this method returns the given
* name, unchanged. Subclasses can override.
......
......@@ -63,6 +63,30 @@ public class ClassRemapperTest extends AsmTest {
assertEquals("new/pkg/C", classNode.name);
}
@Test
public void testRenameInnerClass() {
ClassNode classNode = new ClassNode();
ClassRemapper remapper =
new ClassRemapper(
classNode,
new Remapper() {
@Override
public String map(final String internalName) {
if ("a".equals(internalName)) {
return "pkg/Demo";
}
if ("a$g".equals(internalName)) {
return "pkg/Demo$Container";
}
return internalName;
}
});
remapper.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "a", null, "java/lang/Object", null);
remapper.visitInnerClass("a$g", "a", "g", Opcodes.ACC_PUBLIC);
assertEquals("pkg/Demo", classNode.innerClasses.get(0).outerName);
assertEquals("Container", classNode.innerClasses.get(0).innerName);
}
@Test
public void testRenameModuleHashes() {
ClassNode classNode = new ClassNode();
......@@ -70,7 +94,6 @@ public class ClassRemapperTest extends AsmTest {
new ClassRemapper(
classNode,
new Remapper() {
@Override
public String mapModuleName(final String name) {
return "new." + name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment