Skip to content

Commit

Permalink
Fix Kotlin CCE, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Jan 10, 2025
1 parent b6a48d4 commit e67b23a
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ public TextBuffer toJava(int indent) {
String value = constExprent.getValue().toString();
VarType type = new VarType(value, !value.startsWith("["));
buf.append(KTypes.getKotlinType(type));
} else {
FieldExprent fieldExprent = (FieldExprent) operand;
} else if (operand instanceof FieldExprent fieldExprent) {
String primitiveType = fieldExprent.getClassname();
VarType type = new VarType(primitiveType, true);
buf.append(KTypes.getKotlinType(type));
} else {
// TODO: can end up being 'this.getClass()::class'!
buf.append(operand.toJava());
}
return buf.append("::class");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ protected Path getClassFile(DecompilerTestFixture fixture, TestDefinition.Versio
Path reg = fixture.getTestDataDir().resolve("classes/" + version.directory + "/" + name + ".class");
Path kt = fixture.getTestDataDir().resolve("classes/" + version.directory + "/" + name + "Kt.class");

int x = 0;

return reg.toFile().exists() ? reg : kt;
}

Expand Down
21 changes: 21 additions & 0 deletions plugins/kotlin/testData/results/pkg/TestReflection.dec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class TestReflection {
System.out.println(<unknownclass>.INSTANCE as KFunction);// 24
(f as Function1).invoke(new TestReflection());// 25
}// 26

public fun testThis() {
System.out.println(this.getClass()::class);// 29 30
}// 31
}

class 'pkg/TestReflection' {
Expand Down Expand Up @@ -112,6 +116,20 @@ class 'pkg/TestReflection' {
1d 27
1f 28
}

method 'testThis ()V' {
0 31
1 31
2 31
3 31
8 31
9 31
a 31
c 31
d 31
e 31
f 32
}
}

Lines mapping:
Expand All @@ -129,3 +147,6 @@ Lines mapping:
24 <-> 27
25 <-> 28
26 <-> 29
29 <-> 32
30 <-> 32
31 <-> 33
5 changes: 5 additions & 0 deletions plugins/kotlin/testData/src/kt/pkg/TestReflection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ class TestReflection {
println(f)
f(TestReflection())
}

fun testThis() {
val x = this::class
println(x)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public static void validateSingleStatement(Statement stat) {
return;
}

if (stat.type == Statement.StatementType.BASIC_BLOCK) {
if (stat.getAllSuccessorEdges().isEmpty()) {
throw new IllegalStateException("Basic block " + stat + " has no edges");
}
}

switch (stat.type) {
case IF:
validateIfStatement((IfStatement) stat);
Expand Down
2 changes: 2 additions & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ private void registerDefault() {
register(JAVA_8, "TestBoxingSuperclass");
// TODO: shouldBeOne is completely deleted
register(JAVA_8, "TestLVTReassignment");
register(JAVA_8, "TestCatchVariable");
register(JAVA_8, "TestExtraneousImports");
}

private void registerEntireClassPath() {
Expand Down
92 changes: 92 additions & 0 deletions testData/results/pkg/TestCatchVariable.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package pkg;

import java.io.IOException;

public class TestCatchVariable {
public void test1() {
try {
System.out.println("Hello world!");// 8
} catch (Exception var2) {// 9
var2.printStackTrace();// 10
}
}// 12

public void test2() {
try {
System.out.println("Hello world!");// 16
} catch (Throwable var2) {// 17
var2.printStackTrace();// 18
}
}// 20

public void test3() {
try {
throw new IOException();// 24
} catch (IOException var2) {// 25
var2.printStackTrace();// 26
}
}// 28
}

class 'pkg/TestCatchVariable' {
method 'test1 ()V' {
0 7
1 7
2 7
3 7
4 7
5 7
6 7
7 7
b 8
c 9
d 9
e 9
f 9
10 11
}

method 'test2 ()V' {
0 15
1 15
2 15
3 15
4 15
5 15
6 15
7 15
b 16
c 17
d 17
e 17
f 17
10 19
}

method 'test3 ()V' {
7 23
8 24
9 25
a 25
b 25
c 25
d 27
}
}

Lines mapping:
8 <-> 8
9 <-> 9
10 <-> 10
12 <-> 12
16 <-> 16
17 <-> 17
18 <-> 18
20 <-> 20
24 <-> 24
25 <-> 25
26 <-> 26
28 <-> 28
Not mapped:
11
19
49 changes: 49 additions & 0 deletions testData/results/pkg/TestExtraneousImports.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package pkg;

import java.util.Map;

public class TestExtraneousImports {
public void myMethod(Map<String, String> map) {
map.entrySet().forEach(entry -> System.out.println((String)entry.getValue()));// 7
}// 8
}

class 'pkg/TestExtraneousImports' {
method 'myMethod (Ljava/util/Map;)V' {
0 6
1 6
2 6
3 6
4 6
5 6
b 6
c 6
d 6
e 6
f 6
10 7
}

method 'lambda$myMethod$0 (Ljava/util/Map$Entry;)V' {
0 6
1 6
2 6
3 6
4 6
5 6
6 6
7 6
8 6
9 6
a 6
b 6
c 6
d 6
e 6
f 6
}
}

Lines mapping:
7 <-> 7
8 <-> 8
29 changes: 29 additions & 0 deletions testData/src/java8/pkg/TestCatchVariable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pkg;

import java.io.IOException;

public class TestCatchVariable {
public void test1() {
try {
System.out.println("Hello world!");
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void test2() {
try {
System.out.println("Hello world!");
} catch (Throwable t) {
t.printStackTrace();
}
}

public void test3() {
try {
throw new IOException();
} catch (IOException ioEx) {
ioEx.printStackTrace();
}
}
}
9 changes: 9 additions & 0 deletions testData/src/java8/pkg/TestExtraneousImports.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pkg;

import java.util.Map;

public class TestExtraneousImports {
public void myMethod(Map<String, String> map) {
map.entrySet().forEach(entry -> System.out.println(entry.getValue()));
}
}

0 comments on commit e67b23a

Please sign in to comment.