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

Only use inner class heuristic with class names #250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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<String> parts = Arrays.asList(typeName.split("\\.")).iterator();
StringBuilder typeNameForBinary = new StringBuilder();

Expand All @@ -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 {
Expand Down