forked from DenWav/primeiron
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inner class AT application (#14)
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/java/net/neoforged/accesstransformer/test/InnerClassModifierTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
public net.neoforged.accesstransformer.testJar.DefaultClass$Inner |