[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. 16
      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,15 +308,18 @@ public class ClassWriter {
List<StructModuleAttribute.RequiresEntry> requiresEntries = moduleAttribute.requires;
if (!requiresEntries.isEmpty()) {
for (StructModuleAttribute.RequiresEntry requires : requiresEntries) {
if (!isGenerated(requires.flags)) {
buffer.appendIndent(1).append("requires ").append(requires.moduleName.replace('/', '.')).append(';').appendLineSeparator();
}
newLineNeeded = true;
}
}
}
List<StructModuleAttribute.ExportsEntry> exportsEntries = moduleAttribute.exports;
if (!exportsEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator();
for (StructModuleAttribute.ExportsEntry exports : exportsEntries) {
if (!isGenerated(exports.flags)) {
buffer.appendIndent(1).append("exports ").append(exports.packageName.replace('/', '.'));
List<String> exportToModules = exports.exportToModules;
if (exportToModules.size() > 0) {
@ -324,14 +327,16 @@ public class ClassWriter {
appendFQClassNames(buffer, exportToModules);
}
buffer.append(';').appendLineSeparator();
}
newLineNeeded = true;
}
}
}
List<StructModuleAttribute.OpensEntry> opensEntries = moduleAttribute.opens;
if (!opensEntries.isEmpty()) {
if (newLineNeeded) buffer.appendLineSeparator();
for (StructModuleAttribute.OpensEntry opens : opensEntries) {
if (!isGenerated(opens.flags)) {
buffer.appendIndent(1).append("opens ").append(opens.packageName.replace('/', '.'));
List<String> opensToModules = opens.opensToModules;
if (opensToModules.size() > 0) {
@ -339,9 +344,10 @@ public class ClassWriter {
appendFQClassNames(buffer, opensToModules);
}
buffer.append(';').appendLineSeparator();
}
newLineNeeded = true;
}
}
}
List<String> usesEntries = moduleAttribute.uses;
if (!usesEntries.isEmpty()) {
@ -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) {
StructLineNumberTableAttribute table = method.getAttribute(StructGeneralAttribute.ATTRIBUTE_LINE_NUMBER_TABLE);
tracer.setLineNumberTable(table);

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

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

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

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

Loading…
Cancel
Save