IDEA-204310: Decompiler adds redundant imports for lambdas

master
md_5 6 years ago committed by Egor Ushakov
parent ca01d9877b
commit 8f2a97adc3
  1. 3
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java
  2. 271
      testData/results/TestClassLambda.dec

@ -143,7 +143,8 @@ public class NewExprent extends Exprent {
if (anonymous) { if (anonymous) {
ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(newType.value); ClassNode child = DecompilerContext.getClassProcessor().getMapRootClasses().get(newType.value);
if (!enumConst) { // IDEA-204310 - avoid backtracking later on for lambdas (causes spurious imports)
if (!enumConst && (!lambda || DecompilerContext.getOption(IFernflowerPreferences.LAMBDA_TO_ANONYMOUS_CLASS))) {
String enclosing = null; String enclosing = null;
if (!lambda && constructor != null) { if (!lambda && constructor != null) {

@ -5,10 +5,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntBinaryOperator; import java.util.function.IntBinaryOperator;
import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
public class TestClassLambda { public class TestClassLambda {
@ -90,43 +87,51 @@ public class TestClassLambda {
class 'pkg/TestClassLambda' { class 'pkg/TestClassLambda' {
method 'lambda$testLambda$0 (ILjava/lang/Integer;)V' { method 'lambda$testLambda$0 (ILjava/lang/Integer;)V' {
0 20 0 17
2 20 2 17
5 20 5 17
6 20 6 17
7 21 7 18
c 21 c 18
e 21 e 18
11 21 11 18
12 21 12 18
15 22 15 19
} }
method 'testLambda ()V' { method 'testLambda ()V' {
7 17 7 14
8 17 8 14
e 17 e 14
f 17 f 14
15 17 15 14
16 17 16 14
1c 17 1c 14
1d 17 1d 14
23 17 23 14
24 17 24 14
2a 17 2a 14
2c 17 2c 14
33 17 33 14
35 17 35 14
39 17 39 14
3c 17 3c 14
3d 18 3d 15
40 18 40 15
41 18 41 15
4a 19 4a 16
4f 23 4f 20
} }
method 'lambda$testLambda1$1 (I)V' { method 'lambda$testLambda1$1 (I)V' {
0 25
a 25
13 25
16 25
19 26
}
method 'lambda$testLambda1$2 (I)V' {
0 28 0 28
a 28 a 28
13 28 13 28
@ -134,153 +139,145 @@ class 'pkg/TestClassLambda' {
19 29 19 29
} }
method 'lambda$testLambda1$2 (I)V' {
0 31
a 31
13 31
16 31
19 32
}
method 'testLambda1 ()V' { method 'testLambda1 ()V' {
0 26 0 23
3 26 3 23
4 26 4 23
b 29 b 26
12 32 12 29
13 33 13 30
} }
method 'lambda$testLambda2$3 (II)I' { method 'lambda$testLambda2$3 (II)I' {
2 37 2 34
5 37 5 34
} }
method 'testLambda2 ()V' { method 'testLambda2 ()V' {
5 36 5 33
9 39 9 36
} }
method 'testLambda3 ()V' { method 'testLambda3 ()V' {
5 42 5 39
9 43 9 40
} }
method 'testLambda4 ()V' { method 'testLambda4 ()V' {
5 46 5 43
9 47 9 44
} }
method 'testLambda5 ()V' { method 'testLambda5 ()V' {
0 50 0 47
2 50 2 47
e 51 e 48
12 52 12 49
} }
method 'lambda$testLambda6$4 (IILjava/lang/String;)Z' { method 'lambda$testLambda6$4 (IILjava/lang/String;)Z' {
2 59 2 56
5 59 5 56
9 59 9 56
d 59 d 56
15 59 15 56
} }
method 'testLambda6 ()V' { method 'testLambda6 ()V' {
7 55 7 52
9 56 9 53
e 56 e 53
f 56 f 53
10 56 10 53
12 57 12 54
17 57 17 54
18 57 18 54
19 57 19 54
22 58 22 55
28 61 28 58
} }
method 'testLambda7 ([Ljava/lang/annotation/Annotation;)V' { method 'testLambda7 ([Ljava/lang/annotation/Annotation;)V' {
1 64 1 61
9 64 9 61
f 65 f 62
} }
method 'reduce (Ljava/util/function/IntBinaryOperator;)Ljava/util/OptionalInt;' { method 'reduce (Ljava/util/function/IntBinaryOperator;)Ljava/util/OptionalInt;' {
0 68 0 65
1 68 1 65
} }
method 'function (Ljava/util/function/Supplier;)Ljava/lang/String;' { method 'function (Ljava/util/function/Supplier;)Ljava/lang/String;' {
1 72 1 69
6 72 6 69
9 72 9 69
} }
method 'localMax (II)I' { method 'localMax (II)I' {
0 76 0 73
1 76 1 73
} }
method 'lambda$null$5 (I)V' { method 'lambda$null$5 (I)V' {
0 83 0 80
a 83 a 80
13 83 13 80
16 83 16 80
19 84 19 81
} }
method 'lambda$nestedLambdas$6 (I)V' { method 'lambda$nestedLambdas$6 (I)V' {
6 84 6 81
7 85 7 82
11 85 11 82
1a 85 1a 82
1d 85 1d 82
20 86 20 83
} }
method 'nestedLambdas ()V' { method 'nestedLambdas ()V' {
0 80 0 77
1 80 1 77
8 86 8 83
9 87 9 84
} }
} }
Lines mapping: Lines mapping:
29 <-> 18 29 <-> 15
30 <-> 19 30 <-> 16
32 <-> 20 32 <-> 17
33 <-> 21 33 <-> 18
34 <-> 22 34 <-> 19
35 <-> 23 35 <-> 20
36 <-> 24 36 <-> 21
39 <-> 27 39 <-> 24
40 <-> 30 40 <-> 27
41 <-> 33 41 <-> 30
42 <-> 34 42 <-> 31
45 <-> 37 45 <-> 34
46 <-> 40 46 <-> 37
49 <-> 43 49 <-> 40
50 <-> 44 50 <-> 41
53 <-> 47 53 <-> 44
54 <-> 48 54 <-> 45
57 <-> 51 57 <-> 48
58 <-> 52 58 <-> 49
59 <-> 53 59 <-> 50
62 <-> 56 62 <-> 53
63 <-> 57 63 <-> 54
64 <-> 58 64 <-> 55
65 <-> 59 65 <-> 56
66 <-> 62 66 <-> 59
69 <-> 65 69 <-> 62
70 <-> 66 70 <-> 63
73 <-> 69 73 <-> 66
77 <-> 73 77 <-> 70
81 <-> 77 81 <-> 74
85 <-> 81 85 <-> 78
86 <-> 87 86 <-> 84
87 <-> 85 87 <-> 82
88 <-> 86 88 <-> 83
89 <-> 87 89 <-> 84
90 <-> 88 90 <-> 85

Loading…
Cancel
Save