From 45d7f1f110b5d1d54d7ccc342b5e1a54487c60e9 Mon Sep 17 00:00:00 2001 From: Ethan McCue Date: Mon, 6 May 2024 13:19:07 -0400 Subject: [PATCH] Only use inner class heuristic with class names --- .../internal/compiler/ModuleInfoCompiler.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/moditect/internal/compiler/ModuleInfoCompiler.java b/core/src/main/java/org/moditect/internal/compiler/ModuleInfoCompiler.java index 026527d..0664f90 100644 --- a/core/src/main/java/org/moditect/internal/compiler/ModuleInfoCompiler.java +++ b/core/src/main/java/org/moditect/internal/compiler/ModuleInfoCompiler.java @@ -71,7 +71,7 @@ public static byte[] compileModuleInfo(ModuleDeclaration module, String mainClas ModuleVisitor mv = classWriter.visitModule(module.getNameAsString(), moduleAccess, version); if (mainClass != null) { - mv.visitMainClass(getNameForBinary(mainClass)); + mv.visitMainClass(getNameForBinary(mainClass, Kind.CLASS)); } for (ModuleRequiresDirective requires : module.findAll(ModuleRequiresDirective.class)) { @@ -83,7 +83,7 @@ public static byte[] compileModuleInfo(ModuleDeclaration module, String mainClas for (ModuleExportsDirective export : module.findAll(ModuleExportsDirective.class)) { mv.visitExport( - getNameForBinary(export.getNameAsString()), + getNameForBinary(export.getNameAsString(), Kind.PACKAGE), 0, export.getModuleNames() .stream() @@ -93,20 +93,20 @@ public static byte[] compileModuleInfo(ModuleDeclaration module, String mainClas for (ModuleProvidesDirective provides : module.findAll(ModuleProvidesDirective.class)) { mv.visitProvide( - getNameForBinary(provides.getName()), + getNameForBinary(provides.getName(), Kind.CLASS), provides.getWith() .stream() - .map(ModuleInfoCompiler::getNameForBinary) + .map(name -> getNameForBinary(name, Kind.CLASS)) .toArray(String[]::new)); } for (ModuleUsesDirective uses : module.findAll(ModuleUsesDirective.class)) { - mv.visitUse(getNameForBinary(uses.getName())); + mv.visitUse(getNameForBinary(uses.getName(), Kind.CLASS)); } for (ModuleOpensDirective opens : module.findAll(ModuleOpensDirective.class)) { mv.visitOpen( - getNameForBinary(opens.getNameAsString()), + getNameForBinary(opens.getNameAsString(), Kind.PACKAGE), 0, opens.getModuleNames() .stream() @@ -122,11 +122,16 @@ public static byte[] compileModuleInfo(ModuleDeclaration module, String mainClas return classWriter.toByteArray(); } - private static String getNameForBinary(Name name) { - return getNameForBinary(name.asString()); + private static String getNameForBinary(Name name, Kind kind) { + return getNameForBinary(name.asString(), kind); } - private static String getNameForBinary(String typeName) { + private enum Kind { + CLASS, + PACKAGE + } + + private static String getNameForBinary(String typeName, Kind kind) { Iterator parts = Arrays.asList(typeName.split("\\.")).iterator(); StringBuilder typeNameForBinary = new StringBuilder(); @@ -137,7 +142,7 @@ private static String getNameForBinary(String typeName) { // if the current part is upper-case, we assume it's a class and the following part is a nested class // that's as good as it gets without fully resolving all the type names against the module's classes if (parts.hasNext()) { - if (Character.isUpperCase(part.charAt(0))) { + if (kind == Kind.CLASS && Character.isUpperCase(part.charAt(0))) { typeNameForBinary.append("$"); } else {