[java-decompiler] IDEA-346312 adapt patch 044

- clean-up
- more tests

GitOrigin-RevId: 0b33a70fbe9e01e38a56fd9311435bbaafcaa4f5
This commit is contained in:
Mikhail Pyltsin
2024-09-09 19:43:00 +02:00
committed by intellij-monorepo-bot
parent fe6b13500a
commit 267ccf6ec7
5 changed files with 142 additions and 5 deletions

View File

@@ -922,14 +922,14 @@ public class NestedClassProcessor {
case Exprent.EXPRENT_VAR -> {
VarExprent varExpr = (VarExprent)expr;
if (varExpr.isDefinition()) {
Stack<VarType> stack = new Stack<>();
stack.push(varExpr.getDefinitionType());
List<VarType> stack = new ArrayList<>();
stack.add(varExpr.getDefinitionType());
while (!stack.isEmpty()) {
VarType varType = stack.pop();
VarType varType = stack.remove(0);
if (classType.equals(varType) || (varType != null && varType.getArrayDim() > 0 && classType.getValue().equals(varType.getValue()))) {
res = true;
} else if (varType != null && varType.isGeneric()) {
((GenericType)varType).getArguments().forEach(stack::push);
stack.addAll(((GenericType)varType).getArguments());
}
}
}

View File

@@ -7,6 +7,7 @@ import org.jetbrains.java.decompiler.main.ClassWriter;
import org.jetbrains.java.decompiler.main.ClassesProcessor.ClassNode;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.main.extern.IFernflowerLogger;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.main.rels.MethodWrapper;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
@@ -68,7 +69,8 @@ public class VarExprent extends Exprent {
try {
return GenericType.parse(lvt.getSignature());
} catch (StringIndexOutOfBoundsException ex) {
ex.printStackTrace();
DecompilerContext.getLogger().writeMessage("Inconsistent data: ",
IFernflowerLogger.Severity.WARN, ex);
}
}
else if (lvt != null) {

View File

@@ -248,5 +248,6 @@ public class SingleClassesTest extends SingleClassesTestBase {
@Test public void testPreserveAssignmentToRecord2() { doTest("pkg/PreserveAssignmentToRecord2"); }
@Test public void testLambda() { doTest("pkg/TestLambda"); }
@Test public void testCustomSyntheticRecords() { doTest("pkg/TestCustomSyntheticRecords"); }
@Test public void testFinally() { doTest("pkg/TestFinally"); }
}

View File

@@ -0,0 +1,103 @@
package pkg;
import java.util.List;
public class TestFinally {
public void test(List<A<String>> a) {
try {
this.testThrow();// 13
} catch (Exception var12) {// 15
var12.printStackTrace();// 16
} catch (Throwable var13) {// 17
throw new RuntimeException(var13);// 18
} finally {
for(A<String> s : a) {// 21
String a2 = s.toString();// 22
System.out.println(a2);// 23
}
}
}// 26
public void testThrow() {
}// 30
public class A<B> {
public A(final TestFinally this$0) {
}// 8
}
}
class 'pkg/TestFinally' {
method 'test (Ljava/util/List;)V' {
0 7
1 7
32 8
34 9
65 10
6e 11
71 13
72 13
73 13
74 13
75 13
76 13
77 13
78 13
83 13
84 13
85 13
86 13
87 13
88 13
89 13
8a 13
8b 13
8c 13
8d 13
8e 13
8f 14
90 14
91 14
92 14
93 14
94 14
95 14
96 15
97 15
98 15
99 15
9a 15
9b 15
9c 15
9d 15
a4 20
}
method 'testThrow ()V' {
0 23
}
}
class 'pkg/TestFinally$A' {
method '<init> (Lpkg/TestFinally;)V' {
4 27
}
}
Lines mapping:
8 <-> 28
13 <-> 8
15 <-> 9
16 <-> 10
17 <-> 11
18 <-> 12
21 <-> 14
22 <-> 15
23 <-> 16
26 <-> 21
30 <-> 24
Not mapped:
24
25

View File

@@ -0,0 +1,31 @@
package pkg;
import java.util.List;
public class TestFinally {
public class A<B>{
}
public void test(List<A<String>> a) {
try {
testThrow();
}catch (Exception e) {
e.printStackTrace();
} catch (Throwable e) {
throw new RuntimeException(e);
}
finally {
for (A<String> s : a) {
String a2 = s.toString();
System.out.println(a2);
}
}
}
public void testThrow() {
}
}