Skip to content

Commit 9e7e264

Browse files
authored
Delegate semicolons to plugins when possible (#471)
* Delegate statement semicolon appending to plugins when possible * Update Kotlin tests (now without semicolons) * Add cautionary tale
1 parent a64ce58 commit 9e7e264

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+605
-575
lines changed

plugins/kotlin/src/main/java/org/vineflower/kotlin/KotlinChooser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public boolean isLanguage(StructClass cl) {
4343
StructAnnotationAttribute attr = cl.getAttribute((Key<StructAnnotationAttribute>) key);
4444
for (AnnotationExprent anno : attr.getAnnotations()) {
4545
if (anno.getClassName().equals("kotlin/Metadata")) {
46-
setContextVariables(cl);
46+
// Line removed as it slows down decompilation significantly, and it doesn't seem to break anything
47+
//TODO double-check if it breaks anything
48+
// setContextVariables(cl);
4749
return true;
4850
}
4951
}

plugins/kotlin/src/main/java/org/vineflower/kotlin/KotlinWriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public KotlinWriter() {
9393
javadocProvider = (IFabricJavadocProvider) DecompilerContext.getProperty(IFabricJavadocProvider.PROPERTY_NAME);
9494
}
9595

96+
@Override
97+
public boolean endsWithSemicolon(Exprent expr) {
98+
return false;
99+
}
100+
96101
private boolean invokeProcessors(TextBuffer buffer, ClassNode node) {
97102
ClassWrapper wrapper = node.getWrapper();
98103
if (wrapper == null) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package pkg
33
public class TestAnyType {
44
public fun test(param: Any): Int {
55
if (param is java.lang.String) {// 5
6-
return (param as java.lang.String).length();// 6
6+
return (param as java.lang.String).length()// 6
77
} else {
8-
System.out.println(param);// 9
9-
return 0;// 11
8+
System.out.println(param)// 9
9+
return 0// 11
1010
}
1111
}
1212
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ package pkg
22

33
public class TestBitwiseFunctions {
44
public fun and(a: Int, b: Int): Int {
5-
return a and b;// 5
5+
return a and b// 5
66
}
77

88
public fun or(a: Int, b: Int): Int {
9-
return a or b;// 9
9+
return a or b// 9
1010
}
1111

1212
public fun xor(a: Int, b: Int): Int {
13-
return a xor b;// 13
13+
return a xor b// 13
1414
}
1515

1616
public fun shl(a: Int, b: Int): Int {
17-
return a shl b;// 17
17+
return a shl b// 17
1818
}
1919

2020
public fun shr(a: Int, b: Int): Int {
21-
return a shr b;// 21
21+
return a shr b// 21
2222
}
2323

2424
public fun ushr(a: Int, b: Int): Int {
25-
return a ushr b;// 25
25+
return a ushr b// 25
2626
}
2727
}
2828

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package pkg
22

33
public class TestClassDec {
44
public fun pkg.TestClassDec.Vec2iVal.dot(v: pkg.TestClassDec.Vec2iVal): Int {
5-
return `$this$dot`.getX() * v.getX() + `$this$dot`.getY() * v.getY();// 11
5+
return `$this$dot`.getX() * v.getX() + `$this$dot`.getY() * v.getY()// 11
66
}
77

88
public fun test() {
9-
new TestClassDec.EmptyDec();
10-
val vec: TestClassDec.Vec2iVal = new TestClassDec.Vec2iVal(1, 2);// 16
11-
val vec1: TestClassDec.Vec2iVal = new TestClassDec.Vec2iVal(2, 4);// 17
12-
System.out.println(vec.getX());// 19
13-
System.out.println(this.dot(vec, vec1));// 20
9+
new TestClassDec.EmptyDec()
10+
val vec: TestClassDec.Vec2iVal = new TestClassDec.Vec2iVal(1, 2)// 16
11+
val vec1: TestClassDec.Vec2iVal = new TestClassDec.Vec2iVal(2, 4)// 17
12+
System.out.println(vec.getX())// 19
13+
System.out.println(this.dot(vec, vec1))// 20
1414
}// 21
1515

1616
public class EmptyDec
@@ -22,8 +22,8 @@ public class TestClassDec {
2222
public final val y: Int
2323

2424
init {
25-
this.x = x;// 7
26-
this.y = y;
25+
this.x = x// 7
26+
this.y = y
2727
}
2828
}
2929

@@ -35,8 +35,8 @@ public class TestClassDec {
3535
internal set
3636

3737
init {
38-
this.x = x;// 6
39-
this.y = y;
38+
this.x = x// 6
39+
this.y = y
4040
}
4141
}
4242
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ public class TestClassicStringInterpolation {
44
public final val x: Int = 5// 16
55

66
public fun stringInterpolation(x: Int, y: String) {
7-
System.out.println("$x $y");// 5
7+
System.out.println("$x $y")// 5
88
}// 6
99

1010
public fun testConstant(x: Int) {
11-
System.out.println("$x 5");// 9
11+
System.out.println("$x 5")// 9
1212
}// 10
1313

1414
public fun testExpression(x: Int) {
15-
System.out.println("$x ${x + 1}");// 13
15+
System.out.println("$x ${x + 1}")// 13
1616
}// 14
1717

1818
public fun testProperty() {
19-
System.out.println("${this.x}!");// 18
19+
System.out.println("${this.x}!")// 18
2020
}// 19
2121

2222
public fun testLiteralClass() {
23-
System.out.println("${TestClassicStringInterpolation::class.java}!");// 22
23+
System.out.println("${TestClassicStringInterpolation::class.java}!")// 22
2424
}// 23
2525
}
2626

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package pkg
22

33
public class TestCompanionObject {
44
public fun notInCompanion() {
5-
System.out.println("notInCompanion");// 5
5+
System.out.println("notInCompanion")// 5
66
}// 6
77

88
@JvmStatic
99
@JvmSynthetic
1010
fun `access$getCompanionVal$cp`(): java.lang.String {
11-
return companionVal;
11+
return companionVal
1212
}
1313

1414
@JvmStatic
1515
@JvmSynthetic
1616
fun `access$getCompanionValJvmStatic$cp`(): java.lang.String {
17-
return companionValJvmStatic;// 3
17+
return companionValJvmStatic// 3
1818
}
1919

2020
public companion object {
@@ -24,11 +24,11 @@ public class TestCompanionObject {
2424
public final val companionValJvmStatic: String
2525

2626
public fun inCompanion() {
27-
System.out.println("inCompanion");// 15
27+
System.out.println("inCompanion")// 15
2828
}// 16
2929

3030
public fun inCompanionJvmStatic() {
31-
System.out.println("inCompanionJvmStatic");// 20
31+
System.out.println("inCompanionJvmStatic")// 20
3232
}// 21
3333
}
3434
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ package pkg
22

33
public class TestComparison {
44
public fun test2(a: Any, b: Any): Boolean {
5-
return a == b;// 5
5+
return a == b// 5
66
}
77

88
public fun test3(a: Any, b: Any): Boolean {
9-
return a === b;// 9
9+
return a === b// 9
1010
}
1111

1212
public fun testNull2(a: Any?): Boolean {
13-
return a == null;// 13
13+
return a == null// 13
1414
}
1515

1616
public fun testNull3(a: Any?): Boolean {
17-
return a == null;// 17
17+
return a == null// 17
1818
}
1919

2020
public fun testNullDouble2(a: Any?, b: Any?): Boolean {
21-
return a == b;// 21
21+
return a == b// 21
2222
}
2323

2424
public fun testNullDouble3(a: Any?, b: Any?): Boolean {
25-
return a === b;// 25
25+
return a === b// 25
2626
}
2727
}
2828

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ package pkg
22

33
public class TestCompileTimeErrors {
44
public fun <I, O> test(i: I): O where O : I, O : pkg.TestCompileTimeErrors.Test {
5-
throw new NotImplementedError(null, 1, null);// 10
5+
throw new NotImplementedError(null, 1, null)// 10
66
}
77

88
public fun test2(i: Int?): pkg.TestCompileTimeErrors.Test? {
99
return if (i == null) null else new TestCompileTimeErrors.Test(i) {
1010
private final Integer testValue;
1111

1212
{
13-
this.testValue = `$i`;// 16
13+
this.testValue = `$i`// 16
1414
}// 14
1515

1616
public Integer getTestValue() {
17-
return this.testValue;// 15
17+
return this.testValue// 15
1818
}
1919

2020
/** @deprecated */
2121
// $VF: synthetic method
2222
public static void getTestValue$annotations() {
2323
}
24-
};
24+
}
2525
}
2626

2727
public interface Test {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package pkg
22

33
public class TestConstructors private constructor() {
44
public constructor(a: Int) : this() {// 4
5-
System.out.println("a = $a");// 5
5+
System.out.println("a = $a")// 5
66
}// 6
77

88
public constructor(a: Int, b: Int) : this(a) {// 8
9-
System.out.println("b = $b");// 9
9+
System.out.println("b = $b")// 9
1010
}// 10
1111
}
1212

0 commit comments

Comments
 (0)