Skip to content

Commit

Permalink
fix 'CONSTANT_Package at entry 10 has illegal character: '.''
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Apr 21, 2022
1 parent 64fa6e0 commit 27452f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {
}

group = "org.glavo"
version = "1.4" + "-SNAPSHOT"
version = "1.4"// + "-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/glavo/mic/ModuleInfoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ModuleInfoCompiler(int targetCompatibility, String moduleVersion, String
this.mainClass = mainClass;
}

private static String[] nameListToArray(NodeList<Name> list) {
private static String[] moduleNameListToArray(NodeList<Name> list) {
if (list.isEmpty()) {
return EMPTY_STRING_ARRAY;
}
Expand All @@ -53,6 +53,18 @@ private static String[] nameListToArray(NodeList<Name> list) {
return res;
}

private static String[] packageNameListToArray(NodeList<Name> list) {
if (list.isEmpty()) {
return EMPTY_STRING_ARRAY;
}

String[] res = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
res[i] = list.get(i).asString().replace('.', '/');
}
return res;
}

public void compile(Path source, Path target) throws IOException {
try (Reader reader = Files.newBufferedReader(source);
OutputStream output = Files.newOutputStream(target)) {
Expand Down Expand Up @@ -80,21 +92,21 @@ public void compile(Reader source, OutputStream target) throws IOException {
for (ModuleDirective directive : md.getDirectives()) {
if (directive.isModuleExportsDirective()) {
ModuleExportsDirective export = directive.asModuleExportsDirective();
moduleVisitor.visitExport(export.getNameAsString(), 0, nameListToArray(export.getModuleNames()));
moduleVisitor.visitExport(export.getNameAsString().replace('.', '/'), 0, moduleNameListToArray(export.getModuleNames()));
} else if (directive.isModuleOpensDirective()) {
ModuleOpensDirective open = directive.asModuleOpensDirective();
moduleVisitor.visitOpen(open.getNameAsString(), 0, nameListToArray(open.getModuleNames()));
moduleVisitor.visitOpen(open.getNameAsString().replace('.', '/'), 0, moduleNameListToArray(open.getModuleNames()));
} else if (directive.isModuleProvidesDirective()) {
ModuleProvidesDirective provides = directive.asModuleProvidesDirective();
moduleVisitor.visitProvide(provides.getNameAsString(), nameListToArray(provides.getWith()));
moduleVisitor.visitProvide(provides.getNameAsString().replace('.', '/'), packageNameListToArray(provides.getWith()));
} else if (directive.isModuleRequiresDirective()) {
ModuleRequiresDirective requires = directive.asModuleRequiresDirective();
if (!requires.getNameAsString().equals("java.base")) {
moduleVisitor.visitRequire(requires.getNameAsString(), 0, null);
}
} else if (directive.isModuleUsesDirective()) {
ModuleUsesDirective uses = directive.asModuleUsesDirective();
moduleVisitor.visitUse(uses.getNameAsString());
moduleVisitor.visitUse(uses.getNameAsString().replace('.', '/'));
} else {
throw new AssertionError("Unknown module directive: " + directive);
}
Expand Down

0 comments on commit 27452f1

Please sign in to comment.