Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inner class AT application #14

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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