[java-decompiler] fixes enum constant initializer decompilation (IDEA-154547)

master
Roman Shevchenko 9 years ago
parent a57e42690b
commit 1ac2304d60
  1. 6
      src/org/jetbrains/java/decompiler/main/InitializerProcessor.java
  2. BIN
      testData/classes/pkg/TestEnum$2.class
  3. BIN
      testData/classes/pkg/TestEnum$Type.class
  4. BIN
      testData/classes/pkg/TestEnum.class
  5. 28
      testData/results/TestEnum.dec
  6. 10
      testData/src/pkg/TestEnum.java

@ -117,7 +117,8 @@ public class InitializerProcessor {
StructClass cl = wrapper.getClassStruct();
Statement firstData = Statements.findFirstData(root);
if (firstData != null) {
boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE);
boolean inlineInitializers = cl.hasModifier(CodeConstants.ACC_INTERFACE) || cl.hasModifier(CodeConstants.ACC_ENUM);
while (!firstData.getExprents().isEmpty()) {
Exprent exprent = firstData.getExprents().get(0);
@ -131,8 +132,7 @@ public class InitializerProcessor {
cl.hasField(fExpr.getName(), fExpr.getDescriptor().descriptorString)) {
// interfaces fields should always be initialized inline
if (isInterface || isExprentIndependent(assignExpr.getRight(), method)) {
if (inlineInitializers || isExprentIndependent(assignExpr.getRight(), method)) {
String keyField = InterpreterUtil.makeUniqueKey(fExpr.getName(), fExpr.getDescriptor().descriptorString);
if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) {
wrapper.getStaticFieldInitializers().addWithKey(assignExpr.getRight(), keyField);

@ -6,8 +6,8 @@ public enum TestEnum {
public void m() {
}// 22
},
E3("-"),
E4("+") {
E3("-", TestEnum.Type.ODD),
E4("+", TestEnum.Type.EVEN) {
public void m() {
}// 27
};
@ -15,14 +15,19 @@ public enum TestEnum {
private String s;
public void m() {
}// 30
}// 32
private TestEnum() {
this("?");// 34
this("?", (TestEnum.Type)null);// 36
}
private TestEnum(@Deprecated String var3) {
this.s = var3;// 35
private TestEnum(@Deprecated String var3, TestEnum.Type var4) {
this.s = var3;// 37
}
private static enum Type {
ODD,
EVEN;
}
}
@ -46,10 +51,11 @@ class 'pkg/TestEnum' {
method '<init> (Ljava/lang/String;I)V' {
3 20
5 20
8 21
6 20
9 21
}
method '<init> (Ljava/lang/String;ILjava/lang/String;)V' {
method '<init> (Ljava/lang/String;ILjava/lang/String;Lpkg/TestEnum$Type;)V' {
8 24
b 25
}
@ -58,6 +64,6 @@ class 'pkg/TestEnum' {
Lines mapping:
22 <-> 7
27 <-> 12
30 <-> 18
34 <-> 21
35 <-> 25
32 <-> 18
36 <-> 21
37 <-> 25

@ -21,16 +21,18 @@ public enum TestEnum {
@Override
public void m() { }
},
E3("-"),
E4("+") {
E3("-", Type.ODD),
E4("+", Type.EVEN) {
@Override
public void m() { }
};
private enum Type {ODD, EVEN}
public void m() { }
private String s;
private TestEnum() { this("?"); }
private TestEnum(@Deprecated String s) { this.s = s; }
private TestEnum() { this("?", null); }
private TestEnum(@Deprecated String s, Type t) { this.s = s; }
}

Loading…
Cancel
Save