IDEA-172200 Decompiler switch-on-enum multiple switches in same class generates wrong cases for all but the first switch-on-enum

master
Egor.Ushakov 8 years ago
parent bbc76e7cb4
commit 17d4894848
  1. 5
      src/org/jetbrains/java/decompiler/modules/decompiler/SwitchHelper.java
  2. BIN
      testData/classes/pkg/TestSwitchOnEnum$1.class
  3. BIN
      testData/classes/pkg/TestSwitchOnEnum$Example$A.class
  4. BIN
      testData/classes/pkg/TestSwitchOnEnum$Example$B.class
  5. BIN
      testData/classes/pkg/TestSwitchOnEnum$Example.class
  6. BIN
      testData/classes/pkg/TestSwitchOnEnum.class
  7. 62
      testData/results/TestSwitchOnEnum.dec
  8. 26
      testData/src/pkg/TestSwitchOnEnum.java

@ -37,8 +37,9 @@ public class SwitchHelper {
List<List<Exprent>> caseValues = switchStatement.getCaseValues();
Map<Exprent, Exprent> mapping = new HashMap<>(caseValues.size());
ArrayExprent array = (ArrayExprent)value;
FieldExprent arrayField = (FieldExprent)array.getArray();
ClassesProcessor.ClassNode classNode =
DecompilerContext.getClassProcessor().getMapRootClasses().get(((FieldExprent)array.getArray()).getClassname());
DecompilerContext.getClassProcessor().getMapRootClasses().get(arrayField.getClassname());
if (classNode != null) {
MethodWrapper wrapper = classNode.getWrapper().getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
if (wrapper != null) {
@ -48,7 +49,7 @@ public class SwitchHelper {
if (exprent instanceof AssignmentExprent) {
AssignmentExprent assignment = (AssignmentExprent)exprent;
Exprent left = assignment.getLeft();
if (isEnumArray(left)) {
if (left.type == Exprent.EXPRENT_ARRAY && ((ArrayExprent)left).getArray().equals(arrayField)) {
mapping.put(assignment.getRight(), ((InvocationExprent)((ArrayExprent)left).getIndex()).getInstance());
}
}

@ -15,6 +15,37 @@ public class TestSwitchOnEnum {
return 0;// 20
}
}
static class Example {
void test(TestSwitchOnEnum.Example.A a, TestSwitchOnEnum.Example.B b) {
switch(a) {// 30
case A1:
System.out.println("A1");// 32
break;// 33
case A2:
System.out.println("A2");// 35
}
switch(b) {// 38
case B1:
System.out.println("B1");// 40
break;// 41
case B2:
System.out.println("B2");// 43
}
}// 46
static enum B {
B1,
B2;
}
static enum A {
A1,
A2;
}
}
}
class 'pkg/TestSwitchOnEnum' {
@ -29,8 +60,39 @@ class 'pkg/TestSwitchOnEnum' {
}
}
class 'pkg/TestSwitchOnEnum$Example' {
method 'test (Lpkg/TestSwitchOnEnum$Example$A;Lpkg/TestSwitchOnEnum$Example$B;)V' {
8 20
24 22
27 22
29 22
2c 23
2f 25
32 25
34 25
3f 28
58 30
5b 30
5d 30
60 31
63 33
66 33
68 33
6b 36
}
}
Lines mapping:
14 <-> 9
16 <-> 11
18 <-> 13
20 <-> 15
30 <-> 21
32 <-> 23
33 <-> 24
35 <-> 26
38 <-> 29
40 <-> 31
41 <-> 32
43 <-> 34
46 <-> 37

@ -19,4 +19,30 @@ public class TestSwitchOnEnum {
}
return 0;
}
static class Example {
enum A { A1, A2}
enum B { B1, B2}
void test(A a, B b){
switch (a){
case A1:
System.out.println("A1");
break;
case A2:
System.out.println("A2");
break;
}
switch (b){
case B1:
System.out.println("B1");
break;
case B2:
System.out.println("B2");
break;
}
}
}
}

Loading…
Cancel
Save