IDEA-129734 IOOBE on decompiling certain method references

master
Egor.Ushakov 10 years ago
parent 768f82b798
commit 62b876af25
  1. 6
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
  2. BIN
      testData/classes/pkg/TestClassLambda.class
  3. 190
      testData/results/TestClassLambda.dec
  4. 6
      testData/src/pkg/TestClassLambda.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2014 JetBrains s.r.o. * Copyright 2000-2015 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -112,7 +112,9 @@ public class InvocationExprent extends Exprent {
} }
else { else {
// FIXME: remove the first parameter completely from the list. It's the object type for a virtual lambda method. // FIXME: remove the first parameter completely from the list. It's the object type for a virtual lambda method.
instance = lstParameters.get(0); if (!lstParameters.isEmpty()) {
instance = lstParameters.get(0);
}
} }
} }
else if (opcode == CodeConstants.opc_invokestatic) { else if (opcode == CodeConstants.opc_invokestatic) {

@ -1,10 +1,12 @@
package pkg; package pkg;
import java.lang.annotation.Annotation;
import java.util.ArrayList; 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.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.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -13,179 +15,189 @@ public class TestClassLambda {
public int field = 0; public int field = 0;
public void testLambda() { public void testLambda() {
List var1 = Arrays.asList(new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7)});// 27 List var1 = Arrays.asList(new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7)});// 29
int var2 = (int)Math.random();// 28 int var2 = (int)Math.random();// 30
var1.forEach((var2x) -> {// 30 var1.forEach((var2x) -> {// 32
int var3 = 2 * var2x.intValue(); int var3 = 2 * var2x.intValue();
System.out.println(var3 + var2 + this.field); System.out.println(var3 + var2 + this.field);
}); });
} }
public void testLambda1() { public void testLambda1() {
int var1 = (int)Math.random();// 37 int var1 = (int)Math.random();// 39
Runnable var2 = () -> { Runnable var2 = () -> {
System.out.println("hello1" + var1); System.out.println("hello1" + var1);
};// 38 };// 40
Runnable var3 = () -> { Runnable var3 = () -> {
System.out.println("hello2" + var1); System.out.println("hello2" + var1);
};// 39 };// 41
} }
public void testLambda2() { public void testLambda2() {
reduce((var0, var1) -> {// 43 reduce((var0, var1) -> {// 45
return Math.max(var0, var1); return Math.max(var0, var1);
}); });
} }
public void testLambda3() { public void testLambda3() {
reduce(Math::max);// 47 reduce(Math::max);// 49
} }
public void testLambda4() { public void testLambda4() {
reduce(TestClassLambda::localMax);// 51 reduce(TestClassLambda::localMax);// 53
} }
public void testLambda5() { public void testLambda5() {
String var1 = "abcd";// 55 String var1 = "abcd";// 57
function(var1::toString);// 56 function(var1::toString);// 58
} }
public void testLambda6() { public void testLambda6() {
ArrayList var1 = new ArrayList();// 60 ArrayList var1 = new ArrayList();// 62
int var2 = var1.size() * 2;// 61 int var2 = var1.size() * 2;// 63
int var3 = var1.size() * 5;// 62 int var3 = var1.size() * 5;// 64
var1.removeIf((var2x) -> {// 63 var1.removeIf((var2x) -> {// 65
return var2 >= var2x.length() && var2x.length() <= var3; return var2 >= var2x.length() && var2x.length() <= var3;
}); });
} }
public static void testLambda7(Annotation[] var0) {
Arrays.stream(var0).map(Annotation::annotationType);// 69
}
public static OptionalInt reduce(IntBinaryOperator var0) { public static OptionalInt reduce(IntBinaryOperator var0) {
return null;// 67 return null;// 73
} }
public static String function(Supplier<String> var0) { public static String function(Supplier<String> var0) {
return (String)var0.get();// 71 return (String)var0.get();// 77
} }
public static int localMax(int var0, int var1) { public static int localMax(int var0, int var1) {
return 0;// 75 return 0;// 81
} }
public void nestedLambdas() { public void nestedLambdas() {
byte var1 = 5;// 79 byte var1 = 5;// 85
Runnable var2 = () -> { Runnable var2 = () -> {
Runnable var1x = () -> { Runnable var1x = () -> {
System.out.println("hello2" + var1); System.out.println("hello2" + var1);
}; };
System.out.println("hello1" + var1); System.out.println("hello1" + var1);
};// 80 };// 86
} }
} }
class 'pkg/TestClassLambda' { class 'pkg/TestClassLambda' {
method 'testLambda ()V' { method 'testLambda ()V' {
7 15 7 17
8 15 8 17
e 15 e 17
f 15 f 17
15 15 15 17
16 15 16 17
1c 15 1c 17
1d 15 1d 17
23 15 23 17
24 15 24 17
2a 15 2a 17
2c 15 2c 17
33 15 33 17
35 15 35 17
39 15 39 17
3c 15 3c 17
3d 16 3d 18
40 16 40 18
41 16 41 18
4a 17 4a 19
} }
method 'testLambda1 ()V' { method 'testLambda1 ()V' {
0 24 0 26
3 24 3 26
4 24 4 26
b 27 b 29
12 30 12 32
} }
method 'testLambda2 ()V' { method 'testLambda2 ()V' {
5 34 5 36
} }
method 'testLambda3 ()V' { method 'testLambda3 ()V' {
5 40 5 42
} }
method 'testLambda4 ()V' { method 'testLambda4 ()V' {
5 44 5 46
} }
method 'testLambda5 ()V' { method 'testLambda5 ()V' {
0 48 0 50
2 48 2 50
e 49 e 51
} }
method 'testLambda6 ()V' { method 'testLambda6 ()V' {
7 53 7 55
9 54 9 56
e 54 e 56
f 54 f 56
10 54 10 56
12 55 12 57
17 55 17 57
18 55 18 57
19 55 19 57
22 56 22 58
}
method 'testLambda7 ([Ljava/lang/annotation/Annotation;)V' {
1 64
9 64
} }
method 'reduce (Ljava/util/function/IntBinaryOperator;)Ljava/util/OptionalInt;' { method 'reduce (Ljava/util/function/IntBinaryOperator;)Ljava/util/OptionalInt;' {
0 62 0 68
1 62 1 68
} }
method 'function (Ljava/util/function/Supplier;)Ljava/lang/String;' { method 'function (Ljava/util/function/Supplier;)Ljava/lang/String;' {
1 66 1 72
6 66 6 72
9 66 9 72
} }
method 'localMax (II)I' { method 'localMax (II)I' {
0 70 0 76
1 70 1 76
} }
method 'nestedLambdas ()V' { method 'nestedLambdas ()V' {
0 74 0 80
1 74 1 80
8 80 8 86
} }
} }
Lines mapping: Lines mapping:
27 <-> 16 29 <-> 18
28 <-> 17 30 <-> 19
30 <-> 18 32 <-> 20
37 <-> 25 39 <-> 27
38 <-> 28 40 <-> 30
39 <-> 31 41 <-> 33
43 <-> 35 45 <-> 37
47 <-> 41 49 <-> 43
51 <-> 45 53 <-> 47
55 <-> 49 57 <-> 51
56 <-> 50 58 <-> 52
60 <-> 54
61 <-> 55
62 <-> 56 62 <-> 56
63 <-> 57 63 <-> 57
67 <-> 63 64 <-> 58
71 <-> 67 65 <-> 59
75 <-> 71 69 <-> 65
79 <-> 75 73 <-> 69
80 <-> 81 77 <-> 73
81 <-> 77
85 <-> 81
86 <-> 87

@ -15,7 +15,9 @@
*/ */
package pkg; package pkg;
import java.lang.annotation.Annotation;
import java.util.*; import java.util.*;
import java.util.Arrays;
import java.util.function.IntBinaryOperator; import java.util.function.IntBinaryOperator;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -63,6 +65,10 @@ public class TestClassLambda {
list.removeIf(s -> (bottom >= s.length() && s.length() <= top)); list.removeIf(s -> (bottom >= s.length() && s.length() <= top));
} }
public static void testLambda7(Annotation[] annotations) {
Arrays.stream(annotations).map(Annotation::annotationType);
}
public static OptionalInt reduce(IntBinaryOperator op) { public static OptionalInt reduce(IntBinaryOperator op) {
return null; return null;
} }

Loading…
Cancel
Save