[java decompiler] separating `module-info` sections

GitOrigin-RevId: 63c315cd01502cbdd76a1ef2c86b3634ce6250fd
master
Roman Shevchenko 4 years ago committed by intellij-monorepo-bot
parent f40b96ebcf
commit 37bb6cf4d8
  1. 75
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 4
      testData/results/module-info.dec

@ -286,44 +286,63 @@ public class ClassWriter {
} }
private static void writeModuleInfoBody(TextBuffer buffer, StructModuleAttribute moduleAttribute) { private static void writeModuleInfoBody(TextBuffer buffer, StructModuleAttribute moduleAttribute) {
for (StructModuleAttribute.RequiresEntry requires : moduleAttribute.requires) { boolean newLineNeeded = false;
buffer.appendIndent(1).append("requires ").append(requires.moduleName.replace('/', '.')).append(';').appendLineSeparator();
}
for (StructModuleAttribute.ExportsEntry exports : moduleAttribute.exports) {
buffer.appendIndent(1).append("exports ").append(exports.packageName.replace('/', '.'));
List<String> exportToModules = exports.exportToModules; List<StructModuleAttribute.RequiresEntry> requiresEntries = moduleAttribute.requires;
if (exportToModules.size() > 0) { if (!requiresEntries.isEmpty()) {
buffer.append(" to").appendLineSeparator(); for (StructModuleAttribute.RequiresEntry requires : requiresEntries) {
appendFQClassNames(buffer, exportToModules); buffer.appendIndent(1).append("requires ").append(requires.moduleName.replace('/', '.')).append(';').appendLineSeparator();
} }
newLineNeeded = true;
buffer.append(';').appendLineSeparator();
} }
for (StructModuleAttribute.OpensEntry opens : moduleAttribute.opens) { List<StructModuleAttribute.ExportsEntry> exportsEntries = moduleAttribute.exports;
buffer.appendIndent(1).append("opens ").append(opens.packageName.replace('/', '.')); if (!exportsEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator();
List<String> opensToModules = opens.opensToModules; for (StructModuleAttribute.ExportsEntry exports : exportsEntries) {
if (opensToModules.size() > 0) { buffer.appendIndent(1).append("exports ").append(exports.packageName.replace('/', '.'));
buffer.append(" to").appendLineSeparator(); List<String> exportToModules = exports.exportToModules;
appendFQClassNames(buffer, opensToModules); if (exportToModules.size() > 0) {
buffer.append(" to").appendLineSeparator();
appendFQClassNames(buffer, exportToModules);
}
buffer.append(';').appendLineSeparator();
} }
newLineNeeded = true;
}
buffer.append(';').appendLineSeparator(); List<StructModuleAttribute.OpensEntry> opensEntries = moduleAttribute.opens;
if (!opensEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator();
for (StructModuleAttribute.OpensEntry opens : opensEntries) {
buffer.appendIndent(1).append("opens ").append(opens.packageName.replace('/', '.'));
List<String> opensToModules = opens.opensToModules;
if (opensToModules.size() > 0) {
buffer.append(" to").appendLineSeparator();
appendFQClassNames(buffer, opensToModules);
}
buffer.append(';').appendLineSeparator();
}
newLineNeeded = true;
} }
for (String uses : moduleAttribute.uses) { List<String> usesEntries = moduleAttribute.uses;
buffer.appendIndent(1).append("uses ").append(ExprProcessor.buildJavaClassName(uses)).append(';').appendLineSeparator(); if (!usesEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator();
for (String uses : usesEntries) {
buffer.appendIndent(1).append("uses ").append(ExprProcessor.buildJavaClassName(uses)).append(';').appendLineSeparator();
}
newLineNeeded = true;
} }
for (StructModuleAttribute.ProvidesEntry provides : moduleAttribute.provides) { List<StructModuleAttribute.ProvidesEntry> providesEntries = moduleAttribute.provides;
buffer.appendIndent(1).append("provides ").append(ExprProcessor.buildJavaClassName(provides.interfaceName)).append(" with").appendLineSeparator(); if (!providesEntries.isEmpty()) {
@SuppressWarnings({"SSBasedInspection", "RedundantSuppression"}) List<String> javaNames = if (newLineNeeded) buffer.appendLineSeparator();
provides.implementationNames.stream().map(ExprProcessor::buildJavaClassName).collect(Collectors.toList()); for (StructModuleAttribute.ProvidesEntry provides : providesEntries) {
appendFQClassNames(buffer, javaNames); buffer.appendIndent(1).append("provides ").append(ExprProcessor.buildJavaClassName(provides.interfaceName)).append(" with").appendLineSeparator();
buffer.append(';').appendLineSeparator(); appendFQClassNames(buffer, provides.implementationNames.stream().map(ExprProcessor::buildJavaClassName).collect(Collectors.toList()));
buffer.append(';').appendLineSeparator();
}
} }
} }

@ -1,13 +1,17 @@
@Deprecated @Deprecated
module sample.module { module sample.module {
requires java.base; requires java.base;
exports sample.pkg1; exports sample.pkg1;
exports sample.pkg2 to exports sample.pkg2 to
java.base; java.base;
opens sample.pkg1; opens sample.pkg1;
opens sample.pkg2 to opens sample.pkg2 to
java.base; java.base;
uses java.util.spi.ToolProvider; uses java.util.spi.ToolProvider;
provides sample.pkg1.TestService with provides sample.pkg1.TestService with
sample.pkg1.TestServiceImpl; sample.pkg1.TestServiceImpl;
} }

Loading…
Cancel
Save