diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index 7e868ec194..7943275599 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -1180,6 +1180,13 @@ public boolean writeMethod(ClassNode node, StructMethod mt, int methodIndex, Tex ClassNode currentNode = node; 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); + } + } + GenericClassDescriptor parentSignature = currentNode.classStruct.getSignature(); if (parentSignature != null) { checker = checker.copy(parentSignature.getChecker()); diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index ed1e934ed5..e3613cc060 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -730,6 +730,8 @@ private void registerDefault() { register(JAVA_17, "TestSwitchOnEnumFake"); register(JAVA_16, "TestSwitchExpressionReturnType"); register(JAVA_8, "TestGenericMapping"); + register(JAVA_8, "TestNestedGenerics1"); + register(JAVA_11, "TestNestedGenerics2"); registerRaw(CUSTOM, "TestCorruptedSignatures").setExpectedFileName("Signatures.java"); } diff --git a/testData/results/pkg/TestNestedGenerics1.dec b/testData/results/pkg/TestNestedGenerics1.dec new file mode 100644 index 0000000000..c5e787a03c --- /dev/null +++ b/testData/results/pkg/TestNestedGenerics1.dec @@ -0,0 +1,40 @@ +package pkg; + +import java.util.function.Function; + +public class TestNestedGenerics1 { + public static R test(T t) { + Function instance = new Function() {// 7 + public R apply(T t) { + return null;// 10 + } + }; + return (R)instance.apply(t);// 13 + } +} + +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 + } +} + +class 'pkg/TestNestedGenerics1$1' { + method 'apply (Ljava/lang/Object;)Ljava/lang/Object;' { + 0 8 + 1 8 + } +} + +Lines mapping: +7 <-> 7 +10 <-> 9 +13 <-> 12 diff --git a/testData/results/pkg/TestNestedGenerics2.dec b/testData/results/pkg/TestNestedGenerics2.dec new file mode 100644 index 0000000000..303f27246b --- /dev/null +++ b/testData/results/pkg/TestNestedGenerics2.dec @@ -0,0 +1,36 @@ +package pkg; + +public class TestNestedGenerics2 { + public static R test(T t) { + var instance = new Object() {// 5 + R run(T t) { + return null;// 7 + } + }; + return (R)instance.run(t);// 10 + } +} + +class 'pkg/TestNestedGenerics2' { + method 'test (Ljava/lang/Object;)Ljava/lang/Object;' { + 7 4 + 8 9 + 9 9 + a 9 + b 9 + c 9 + d 9 + } +} + +class 'pkg/TestNestedGenerics2$1' { + method 'run (Ljava/lang/Object;)Ljava/lang/Object;' { + 0 6 + 1 6 + } +} + +Lines mapping: +5 <-> 5 +7 <-> 7 +10 <-> 10 diff --git a/testData/src/java11/pkg/TestNestedGenerics2.java b/testData/src/java11/pkg/TestNestedGenerics2.java new file mode 100644 index 0000000000..6db69fac2e --- /dev/null +++ b/testData/src/java11/pkg/TestNestedGenerics2.java @@ -0,0 +1,12 @@ +package pkg; + +public class TestNestedGenerics2 { + public static R test(T t) { + var instance = new Object() { + R run(T t) { + return null; + } + }; + return instance.run(t); + } +} diff --git a/testData/src/java8/pkg/TestNestedGenerics1.java b/testData/src/java8/pkg/TestNestedGenerics1.java new file mode 100644 index 0000000000..f980168e4b --- /dev/null +++ b/testData/src/java8/pkg/TestNestedGenerics1.java @@ -0,0 +1,15 @@ +package pkg; + +import java.util.function.Function; + +public class TestNestedGenerics1 { + public static R test(T t) { + Function instance = new Function() { + @Override + public R apply(T t) { + return null; + } + }; + return instance.apply(t); + } +}