IDEA-172200 Decompiler switch-on-enum multiple switches in same class generates wrong cases for all but the first switch-on-enum
This commit is contained in:
@@ -37,8 +37,9 @@ public class SwitchHelper {
|
|||||||
List<List<Exprent>> caseValues = switchStatement.getCaseValues();
|
List<List<Exprent>> caseValues = switchStatement.getCaseValues();
|
||||||
Map<Exprent, Exprent> mapping = new HashMap<>(caseValues.size());
|
Map<Exprent, Exprent> mapping = new HashMap<>(caseValues.size());
|
||||||
ArrayExprent array = (ArrayExprent)value;
|
ArrayExprent array = (ArrayExprent)value;
|
||||||
|
FieldExprent arrayField = (FieldExprent)array.getArray();
|
||||||
ClassesProcessor.ClassNode classNode =
|
ClassesProcessor.ClassNode classNode =
|
||||||
DecompilerContext.getClassProcessor().getMapRootClasses().get(((FieldExprent)array.getArray()).getClassname());
|
DecompilerContext.getClassProcessor().getMapRootClasses().get(arrayField.getClassname());
|
||||||
if (classNode != null) {
|
if (classNode != null) {
|
||||||
MethodWrapper wrapper = classNode.getWrapper().getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
|
MethodWrapper wrapper = classNode.getWrapper().getMethodWrapper(CodeConstants.CLINIT_NAME, "()V");
|
||||||
if (wrapper != null) {
|
if (wrapper != null) {
|
||||||
@@ -48,7 +49,7 @@ public class SwitchHelper {
|
|||||||
if (exprent instanceof AssignmentExprent) {
|
if (exprent instanceof AssignmentExprent) {
|
||||||
AssignmentExprent assignment = (AssignmentExprent)exprent;
|
AssignmentExprent assignment = (AssignmentExprent)exprent;
|
||||||
Exprent left = assignment.getLeft();
|
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());
|
mapping.put(assignment.getRight(), ((InvocationExprent)((ArrayExprent)left).getIndex()).getInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
BIN
testData/classes/pkg/TestSwitchOnEnum$Example$A.class
Normal file
BIN
testData/classes/pkg/TestSwitchOnEnum$Example$A.class
Normal file
Binary file not shown.
BIN
testData/classes/pkg/TestSwitchOnEnum$Example$B.class
Normal file
BIN
testData/classes/pkg/TestSwitchOnEnum$Example$B.class
Normal file
Binary file not shown.
BIN
testData/classes/pkg/TestSwitchOnEnum$Example.class
Normal file
BIN
testData/classes/pkg/TestSwitchOnEnum$Example.class
Normal file
Binary file not shown.
Binary file not shown.
@@ -15,6 +15,37 @@ public class TestSwitchOnEnum {
|
|||||||
return 0;// 20
|
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' {
|
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:
|
Lines mapping:
|
||||||
14 <-> 9
|
14 <-> 9
|
||||||
16 <-> 11
|
16 <-> 11
|
||||||
18 <-> 13
|
18 <-> 13
|
||||||
20 <-> 15
|
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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user