Skip to content

Commit

Permalink
Fixes module modifiers in ModuleInfoAsserter
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Jan 19, 2025
1 parent 7b20559 commit 6993090
Showing 1 changed file with 48 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,7 @@ public class ModuleInfoAsserter {

public static ModuleInfoAsserter parse(byte[] moduleinfo) {
var result = new ModuleInfoAsserter();

new ClassReader(moduleinfo).accept(new ClassVisitor(Opcodes.ASM9) {
@Override
public ModuleVisitor visitModule(String name, int access, String version) {
result.moduleName = name;
return new ModuleVisitor(Opcodes.ASM9) {
@Override
public void visitExport(String packaze, int access, String... modules) {
result.exports.add(packaze);
}

@Override
public void visitRequire(String module, int access, String version) {
var modifiers = (access & Opcodes.ACC_TRANSITIVE) != 0 ? "transitive" : "";
result.requires.put(module, modifiers);
}
};
}
}, 0);

new ClassReader(moduleinfo).accept(new ModuleInfoParser(result), 0);
return result;
}

Expand All @@ -53,4 +34,51 @@ public void assertDoesNotRequire(String require) {
assertThat(requires).doesNotContainKey(require);
}

private static final class ModuleInfoParser extends ClassVisitor {

private final ModuleInfoAsserter asserter;

private ModuleInfoParser(ModuleInfoAsserter asserter) {
super(Opcodes.ASM9);
this.asserter = asserter;
}

@Override
public ModuleVisitor visitModule(String name, int access, String version) {
asserter.moduleName = name;
return new ModuleVisitorExtension(asserter);
}
}

private static final class ModuleVisitorExtension extends ModuleVisitor {
private final ModuleInfoAsserter asserter;

private ModuleVisitorExtension(ModuleInfoAsserter asserter) {
super(Opcodes.ASM9);
this.asserter = asserter;
}

@Override
public void visitExport(String packaze, int access, String... modules) {
asserter.exports.add(packaze);
}

@Override
public void visitRequire(String module, int access, String version) {
var modifiers = "";
if ((access & Opcodes.ACC_TRANSITIVE) != 0) {
modifiers += "transitive ";
}
if ((access & Opcodes.ACC_STATIC_PHASE) != 0) {
modifiers += "static ";
}
if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
modifiers += "synthetic ";
}
if ((access & Opcodes.ACC_MANDATED) != 0) {
modifiers += "mandated ";
}
asserter.requires.put(module, modifiers);
}
}
}

0 comments on commit 6993090

Please sign in to comment.