Skip to content

Commit

Permalink
Fix inner class AT application (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored Nov 23, 2024
1 parent 8274f92 commit 90f1408
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class InnerClassAccessTransformer extends AccessTransformer<ClassNode> {

public InnerClassAccessTransformer(final Target.InnerClassTarget target, final Transformation transformation) {
super(target, transformation);
this.innerName = target.innerName();
this.innerName = target.innerName().replace('.', '/');
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.neoforged.accesstransformer.test;

import net.neoforged.accesstransformer.api.AccessTransformerEngine;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class InnerClassModifierTest {
@BeforeAll
public static void setup() {
Configurator.setRootLevel(Level.DEBUG);
}

/**
* Validate that the INNERCLASS metadata is correctly updated on the outer class.
*/
@Test
public void testInnerClassModifierChangedOnParent() throws Exception {
AccessTransformerEngine engine = AccessTransformerEngine.newEngine();
engine.loadATFromResource("innerclass_at.cfg");
Type outerClass = Type.getObjectType("net.neoforged.accesstransformer.testJar.DefaultClass".replace('.', '/'));
Type innerClass = Type.getObjectType("net.neoforged.accesstransformer.testJar.DefaultClass$Inner".replace('.', '/'));
assertTrue(engine.containsClassTarget(outerClass));
assertTrue(engine.containsClassTarget(innerClass));
final ClassNode outerNode = new ClassNode();
try (InputStream is = Files.newInputStream(Path.of("build/classes/java/testJars/" + outerClass.getInternalName() + ".class"))) {
final ClassReader classReader = new ClassReader(is);
classReader.accept(outerNode, 0);
}
engine.transform(outerNode, outerClass);
outerNode.innerClasses.forEach(node -> {
assertTrue((node.access & Opcodes.ACC_PUBLIC) != 0);
});
}
}
2 changes: 2 additions & 0 deletions src/test/resources/innerclass_at.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

public net.neoforged.accesstransformer.testJar.DefaultClass$Inner

0 comments on commit 90f1408

Please sign in to comment.