Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/org/jetbrains/java/decompiler/main/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,24 @@ public boolean writeMethod(ClassNode node, StructMethod mt, int methodIndex, Tex
GenericsChecker checker = new GenericsChecker();

ClassNode currentNode = node;
while (currentNode != null) {
loop: while (currentNode != null) {
if (currentNode.enclosingMethod != null) {
StructMethod enclosingMethod = currentNode.parent.classStruct.getMethod(currentNode.enclosingMethod);
if (enclosingMethod != null && enclosingMethod.getSignature() != null) {
checker = checker.copy(enclosingMethod.getSignature().typeParameters, enclosingMethod.getSignature().typeParameterBounds);
if (enclosingMethod != null) {
if (enclosingMethod.getSignature() != null) {
checker = checker.copy(enclosingMethod.getSignature().typeParameters, enclosingMethod.getSignature().typeParameterBounds);
}

if (currentNode.parent != null) {
for (ClassNode child : currentNode.parent.nested) {
if (child.type == ClassNode.Type.LAMBDA && currentNode.enclosingMethod.equals(child.lambdaInformation.content_method_key)) {
// Lambdas lose context because anonymous classes within them are children of the lambda's parent,
// instead of the fake lambda ClassNode generated by Vineflower
currentNode = child;
continue loop;
}
}
}
}
}

Expand Down
80 changes: 63 additions & 17 deletions testData/results/pkg/TestNestedGenerics1.dec
Original file line number Diff line number Diff line change
@@ -1,40 +1,86 @@
package pkg;

import java.util.function.Function;
import java.util.function.Supplier;

public class TestNestedGenerics1 {
public static <T, R> R test(T t) {
Function<T, R> instance = new Function<T, R>() {// 7
Function<T, R> instance = new Function<T, R>() {// 8
public R apply(T t) {
return null;// 10
return null;// 11
}
};
return (R)instance.apply(t);// 13
return (R)instance.apply(t);// 14
}

public static <T, R> R testInLambda(T t, R r) {
Supplier<Function<T, R>> functionMaker = () -> new Function<T, R>() {// 18
public R apply(T t) {
return r;// 21
}
};
return (R)((Function)functionMaker.get()).apply(t);// 25
}
}

class 'pkg/TestNestedGenerics1' {
method 'test (Ljava/lang/Object;)Ljava/lang/Object;' {
7 6
8 11
9 11
a 11
b 11
c 11
d 11
e 11
f 11
7 7
8 12
9 12
a 12
b 12
c 12
d 12
e 12
f 12
}

method 'testInLambda (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;' {
6 16
7 21
8 21
9 21
a 21
b 21
c 21
d 21
e 21
f 21
10 21
11 21
12 21
13 21
14 21
15 21
16 21
}

method 'lambda$testInLambda$0 (Ljava/lang/Object;)Ljava/util/function/Function;' {
8 16
}
}

class 'pkg/TestNestedGenerics1$1' {
method 'apply (Ljava/lang/Object;)Ljava/lang/Object;' {
0 8
1 8
0 9
1 9
}
}

class 'pkg/TestNestedGenerics1$2' {
method 'apply (Ljava/lang/Object;)Ljava/lang/Object;' {
1 18
2 18
3 18
4 18
}
}

Lines mapping:
7 <-> 7
10 <-> 9
13 <-> 12
8 <-> 8
11 <-> 10
14 <-> 13
18 <-> 17
21 <-> 19
25 <-> 22
12 changes: 12 additions & 0 deletions testData/src/java8/pkg/TestNestedGenerics1.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pkg;

import java.util.function.Function;
import java.util.function.Supplier;

public class TestNestedGenerics1 {
public static <T, R> R test(T t) {
Expand All @@ -12,4 +13,15 @@ public R apply(T t) {
};
return instance.apply(t);
}

public static <T, R> R testInLambda(T t, R r) {
Supplier<Function<T, R>> functionMaker = () -> new Function<T, R>() {
@Override
public R apply(T t) {
return r;
}
};

return functionMaker.get().apply(t);
}
}