Skip to content

Commit e67b23a

Browse files
committed
Fix Kotlin CCE, add more tests
1 parent b6a48d4 commit e67b23a

File tree

10 files changed

+219
-2
lines changed

10 files changed

+219
-2
lines changed

plugins/kotlin/src/main/java/org/vineflower/kotlin/expr/KFunctionExprent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ public TextBuffer toJava(int indent) {
9797
String value = constExprent.getValue().toString();
9898
VarType type = new VarType(value, !value.startsWith("["));
9999
buf.append(KTypes.getKotlinType(type));
100-
} else {
101-
FieldExprent fieldExprent = (FieldExprent) operand;
100+
} else if (operand instanceof FieldExprent fieldExprent) {
102101
String primitiveType = fieldExprent.getClassname();
103102
VarType type = new VarType(primitiveType, true);
104103
buf.append(KTypes.getKotlinType(type));
104+
} else {
105+
// TODO: can end up being 'this.getClass()::class'!
106+
buf.append(operand.toJava());
105107
}
106108
return buf.append("::class");
107109
}

plugins/kotlin/src/test/java/org/vineflower/kotlin/KotlinTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ protected Path getClassFile(DecompilerTestFixture fixture, TestDefinition.Versio
1515
Path reg = fixture.getTestDataDir().resolve("classes/" + version.directory + "/" + name + ".class");
1616
Path kt = fixture.getTestDataDir().resolve("classes/" + version.directory + "/" + name + "Kt.class");
1717

18+
int x = 0;
19+
1820
return reg.toFile().exists() ? reg : kt;
1921
}
2022

plugins/kotlin/testData/results/pkg/TestReflection.dec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class TestReflection {
2727
System.out.println(<unknownclass>.INSTANCE as KFunction);// 24
2828
(f as Function1).invoke(new TestReflection());// 25
2929
}// 26
30+
31+
public fun testThis() {
32+
System.out.println(this.getClass()::class);// 29 30
33+
}// 31
3034
}
3135

3236
class 'pkg/TestReflection' {
@@ -112,6 +116,20 @@ class 'pkg/TestReflection' {
112116
1d 27
113117
1f 28
114118
}
119+
120+
method 'testThis ()V' {
121+
0 31
122+
1 31
123+
2 31
124+
3 31
125+
8 31
126+
9 31
127+
a 31
128+
c 31
129+
d 31
130+
e 31
131+
f 32
132+
}
115133
}
116134

117135
Lines mapping:
@@ -129,3 +147,6 @@ Lines mapping:
129147
24 <-> 27
130148
25 <-> 28
131149
26 <-> 29
150+
29 <-> 32
151+
30 <-> 32
152+
31 <-> 33

plugins/kotlin/testData/src/kt/pkg/TestReflection.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ class TestReflection {
2424
println(f)
2525
f(TestReflection())
2626
}
27+
28+
fun testThis() {
29+
val x = this::class
30+
println(x)
31+
}
2732
}

src/org/jetbrains/java/decompiler/modules/decompiler/ValidationHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ public static void validateSingleStatement(Statement stat) {
203203
return;
204204
}
205205

206+
if (stat.type == Statement.StatementType.BASIC_BLOCK) {
207+
if (stat.getAllSuccessorEdges().isEmpty()) {
208+
throw new IllegalStateException("Basic block " + stat + " has no edges");
209+
}
210+
}
211+
206212
switch (stat.type) {
207213
case IF:
208214
validateIfStatement((IfStatement) stat);

test/org/jetbrains/java/decompiler/SingleClassesTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,8 @@ private void registerDefault() {
712712
register(JAVA_8, "TestBoxingSuperclass");
713713
// TODO: shouldBeOne is completely deleted
714714
register(JAVA_8, "TestLVTReassignment");
715+
register(JAVA_8, "TestCatchVariable");
716+
register(JAVA_8, "TestExtraneousImports");
715717
}
716718

717719
private void registerEntireClassPath() {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package pkg;
2+
3+
import java.io.IOException;
4+
5+
public class TestCatchVariable {
6+
public void test1() {
7+
try {
8+
System.out.println("Hello world!");// 8
9+
} catch (Exception var2) {// 9
10+
var2.printStackTrace();// 10
11+
}
12+
}// 12
13+
14+
public void test2() {
15+
try {
16+
System.out.println("Hello world!");// 16
17+
} catch (Throwable var2) {// 17
18+
var2.printStackTrace();// 18
19+
}
20+
}// 20
21+
22+
public void test3() {
23+
try {
24+
throw new IOException();// 24
25+
} catch (IOException var2) {// 25
26+
var2.printStackTrace();// 26
27+
}
28+
}// 28
29+
}
30+
31+
class 'pkg/TestCatchVariable' {
32+
method 'test1 ()V' {
33+
0 7
34+
1 7
35+
2 7
36+
3 7
37+
4 7
38+
5 7
39+
6 7
40+
7 7
41+
b 8
42+
c 9
43+
d 9
44+
e 9
45+
f 9
46+
10 11
47+
}
48+
49+
method 'test2 ()V' {
50+
0 15
51+
1 15
52+
2 15
53+
3 15
54+
4 15
55+
5 15
56+
6 15
57+
7 15
58+
b 16
59+
c 17
60+
d 17
61+
e 17
62+
f 17
63+
10 19
64+
}
65+
66+
method 'test3 ()V' {
67+
7 23
68+
8 24
69+
9 25
70+
a 25
71+
b 25
72+
c 25
73+
d 27
74+
}
75+
}
76+
77+
Lines mapping:
78+
8 <-> 8
79+
9 <-> 9
80+
10 <-> 10
81+
12 <-> 12
82+
16 <-> 16
83+
17 <-> 17
84+
18 <-> 18
85+
20 <-> 20
86+
24 <-> 24
87+
25 <-> 25
88+
26 <-> 26
89+
28 <-> 28
90+
Not mapped:
91+
11
92+
19
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package pkg;
2+
3+
import java.util.Map;
4+
5+
public class TestExtraneousImports {
6+
public void myMethod(Map<String, String> map) {
7+
map.entrySet().forEach(entry -> System.out.println((String)entry.getValue()));// 7
8+
}// 8
9+
}
10+
11+
class 'pkg/TestExtraneousImports' {
12+
method 'myMethod (Ljava/util/Map;)V' {
13+
0 6
14+
1 6
15+
2 6
16+
3 6
17+
4 6
18+
5 6
19+
b 6
20+
c 6
21+
d 6
22+
e 6
23+
f 6
24+
10 7
25+
}
26+
27+
method 'lambda$myMethod$0 (Ljava/util/Map$Entry;)V' {
28+
0 6
29+
1 6
30+
2 6
31+
3 6
32+
4 6
33+
5 6
34+
6 6
35+
7 6
36+
8 6
37+
9 6
38+
a 6
39+
b 6
40+
c 6
41+
d 6
42+
e 6
43+
f 6
44+
}
45+
}
46+
47+
Lines mapping:
48+
7 <-> 7
49+
8 <-> 8
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package pkg;
2+
3+
import java.io.IOException;
4+
5+
public class TestCatchVariable {
6+
public void test1() {
7+
try {
8+
System.out.println("Hello world!");
9+
} catch (Exception ex) {
10+
ex.printStackTrace();
11+
}
12+
}
13+
14+
public void test2() {
15+
try {
16+
System.out.println("Hello world!");
17+
} catch (Throwable t) {
18+
t.printStackTrace();
19+
}
20+
}
21+
22+
public void test3() {
23+
try {
24+
throw new IOException();
25+
} catch (IOException ioEx) {
26+
ioEx.printStackTrace();
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package pkg;
2+
3+
import java.util.Map;
4+
5+
public class TestExtraneousImports {
6+
public void myMethod(Map<String, String> map) {
7+
map.entrySet().forEach(entry -> System.out.println(entry.getValue()));
8+
}
9+
}

0 commit comments

Comments
 (0)