[java decompiler] skipping generated `module-info` statements

GitOrigin-RevId: c2f9cfd88f57e7d59cca54ec090f67f29377ff23
master
Roman Shevchenko 4 years ago committed by intellij-monorepo-bot
parent e130aa6896
commit 9cd86f9640
  1. 42
      src/org/jetbrains/java/decompiler/main/ClassWriter.java
  2. 22
      src/org/jetbrains/java/decompiler/struct/attr/StructModuleAttribute.java
  3. BIN
      testData/classes/java9/module-info.class
  4. 4
      testData/results/module-info.dec
  5. 2
      testData/src/java9/sample.module/TestModuleAnno.java
  6. 4
      testData/src/java9/sample.module/module-info.java

@ -308,39 +308,45 @@ public class ClassWriter {
List<StructModuleAttribute.RequiresEntry> requiresEntries = moduleAttribute.requires; List<StructModuleAttribute.RequiresEntry> requiresEntries = moduleAttribute.requires;
if (!requiresEntries.isEmpty()) { if (!requiresEntries.isEmpty()) {
for (StructModuleAttribute.RequiresEntry requires : requiresEntries) { for (StructModuleAttribute.RequiresEntry requires : requiresEntries) {
buffer.appendIndent(1).append("requires ").append(requires.moduleName.replace('/', '.')).append(';').appendLineSeparator(); if (!isGenerated(requires.flags)) {
buffer.appendIndent(1).append("requires ").append(requires.moduleName.replace('/', '.')).append(';').appendLineSeparator();
newLineNeeded = true;
}
} }
newLineNeeded = true;
} }
List<StructModuleAttribute.ExportsEntry> exportsEntries = moduleAttribute.exports; List<StructModuleAttribute.ExportsEntry> exportsEntries = moduleAttribute.exports;
if (!exportsEntries.isEmpty()) { if (!exportsEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator(); if (newLineNeeded) buffer.appendLineSeparator();
for (StructModuleAttribute.ExportsEntry exports : exportsEntries) { for (StructModuleAttribute.ExportsEntry exports : exportsEntries) {
buffer.appendIndent(1).append("exports ").append(exports.packageName.replace('/', '.')); if (!isGenerated(exports.flags)) {
List<String> exportToModules = exports.exportToModules; buffer.appendIndent(1).append("exports ").append(exports.packageName.replace('/', '.'));
if (exportToModules.size() > 0) { List<String> exportToModules = exports.exportToModules;
buffer.append(" to").appendLineSeparator(); if (exportToModules.size() > 0) {
appendFQClassNames(buffer, exportToModules); buffer.append(" to").appendLineSeparator();
appendFQClassNames(buffer, exportToModules);
}
buffer.append(';').appendLineSeparator();
newLineNeeded = true;
} }
buffer.append(';').appendLineSeparator();
} }
newLineNeeded = true;
} }
List<StructModuleAttribute.OpensEntry> opensEntries = moduleAttribute.opens; List<StructModuleAttribute.OpensEntry> opensEntries = moduleAttribute.opens;
if (!opensEntries.isEmpty()) { if (!opensEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator(); if (newLineNeeded) buffer.appendLineSeparator();
for (StructModuleAttribute.OpensEntry opens : opensEntries) { for (StructModuleAttribute.OpensEntry opens : opensEntries) {
buffer.appendIndent(1).append("opens ").append(opens.packageName.replace('/', '.')); if (!isGenerated(opens.flags)) {
List<String> opensToModules = opens.opensToModules; buffer.appendIndent(1).append("opens ").append(opens.packageName.replace('/', '.'));
if (opensToModules.size() > 0) { List<String> opensToModules = opens.opensToModules;
buffer.append(" to").appendLineSeparator(); if (opensToModules.size() > 0) {
appendFQClassNames(buffer, opensToModules); buffer.append(" to").appendLineSeparator();
appendFQClassNames(buffer, opensToModules);
}
buffer.append(';').appendLineSeparator();
newLineNeeded = true;
} }
buffer.append(';').appendLineSeparator();
} }
newLineNeeded = true;
} }
List<String> usesEntries = moduleAttribute.uses; List<String> usesEntries = moduleAttribute.uses;
@ -363,6 +369,10 @@ public class ClassWriter {
} }
} }
private static boolean isGenerated(int flags) {
return (flags & (CodeConstants.ACC_SYNTHETIC | CodeConstants.ACC_MANDATED)) != 0;
}
private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) { private static void addTracer(StructClass cls, StructMethod method, BytecodeMappingTracer tracer) {
StructLineNumberTableAttribute table = method.getAttribute(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE); StructLineNumberTableAttribute table = method.getAttribute(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
tracer.setLineNumberTable(table); tracer.setLineNumberTable(table);

@ -45,11 +45,11 @@ public class StructModuleAttribute extends StructGeneralAttribute {
List<RequiresEntry> requires = new ArrayList<>(requiresCount); List<RequiresEntry> requires = new ArrayList<>(requiresCount);
for (int i = 0; i < requiresCount; i++) { for (int i = 0; i < requiresCount; i++) {
int moduleNameIndex = data.readUnsignedShort(); int moduleNameIndex = data.readUnsignedShort();
int moduleFlags = data.readUnsignedShort(); int requiresFlags = data.readUnsignedShort();
int versionIndex = data.readUnsignedShort(); int versionIndex = data.readUnsignedShort();
String moduleName = pool.getPrimitiveConstant(moduleNameIndex).getString(); String moduleName = pool.getPrimitiveConstant(moduleNameIndex).getString();
String version = versionIndex == 0 ? null : pool.getPrimitiveConstant(versionIndex).getString(); String version = versionIndex == 0 ? null : pool.getPrimitiveConstant(versionIndex).getString();
requires.add(new RequiresEntry(moduleName, moduleFlags, version)); requires.add(new RequiresEntry(moduleName, requiresFlags, version));
} }
return requires; return requires;
} }
@ -119,36 +119,36 @@ public class StructModuleAttribute extends StructGeneralAttribute {
public static final class RequiresEntry { public static final class RequiresEntry {
public final String moduleName; public final String moduleName;
public final int moduleFlags; public final int flags;
public final String moduleVersion; public final String moduleVersion;
public RequiresEntry(String moduleName, int moduleFlags, String moduleVersion) { public RequiresEntry(String moduleName, int flags, String moduleVersion) {
this.moduleName = moduleName; this.moduleName = moduleName;
this.moduleFlags = moduleFlags; this.flags = flags;
this.moduleVersion = moduleVersion; this.moduleVersion = moduleVersion;
} }
} }
public static final class ExportsEntry { public static final class ExportsEntry {
public final String packageName; public final String packageName;
public final int exportsFlags; public final int flags;
public final List<String> exportToModules; public final List<String> exportToModules;
public ExportsEntry(String packageName, int exportsFlags, List<String> exportToModules) { public ExportsEntry(String packageName, int flags, List<String> exportToModules) {
this.packageName = packageName; this.packageName = packageName;
this.exportsFlags = exportsFlags; this.flags = flags;
this.exportToModules = exportToModules; this.exportToModules = exportToModules;
} }
} }
public static final class OpensEntry { public static final class OpensEntry {
public final String packageName; public final String packageName;
public final int opensFlags; public final int flags;
public final List<String> opensToModules; public final List<String> opensToModules;
public OpensEntry(String packageName, int exportsFlags, List<String> exportToModules) { public OpensEntry(String packageName, int flags, List<String> exportToModules) {
this.packageName = packageName; this.packageName = packageName;
this.opensFlags = exportsFlags; this.flags = flags;
this.opensToModules = exportToModules; this.opensToModules = exportToModules;
} }
} }

@ -1,8 +1,8 @@
import pkg.test1.TestModuleAnno; import sample.pkg1.TestModuleAnno;
@TestModuleAnno("...") @TestModuleAnno("...")
module sample.module { module sample.module {
requires java.base; requires java.desktop;
exports sample.pkg1; exports sample.pkg1;
exports sample.pkg2 to exports sample.pkg2 to

@ -1,4 +1,4 @@
package pkg.test1; package sample.pkg1;
import java.lang.annotation.*; import java.lang.annotation.*;

@ -1,8 +1,8 @@
import pkg.test1.TestModuleAnno; import sample.pkg1.TestModuleAnno;
@TestModuleAnno("...") @TestModuleAnno("...")
module sample.module { module sample.module {
requires java.base; requires java.desktop;
uses java.util.spi.ToolProvider; uses java.util.spi.ToolProvider;

Loading…
Cancel
Save