Skip to content

Commit

Permalink
[Kotlin] Fix class visibility when public should be explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
sschr15 committed Aug 14, 2024
1 parent f6c21ed commit 7f460c3
Show file tree
Hide file tree
Showing 43 changed files with 56 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ private void writeKotlinFile(ClassNode node, TextBuffer buffer, int indent, KPro
}
}

//TODO update this to use Kotlin's metadata
private void writeAnnotationDefinition(ClassNode node, TextBuffer buffer, int indent, KProperty.Data propertyData, Map<StructMethod, KFunction> functions, KConstructor.Data constructorData) {
ClassWrapper wrapper = node.getWrapper();
StructClass cl = wrapper.getClassStruct();
Expand Down Expand Up @@ -624,7 +625,7 @@ private void writeClassDefinition(ClassNode node, TextBuffer buffer, int indent,

buffer.appendIndent(indent);

if (kotlinFlags.visibility != ProtoBuf.Visibility.PUBLIC) {
if (kotlinFlags.visibility != ProtoBuf.Visibility.PUBLIC || DecompilerContext.getOption(KotlinOptions.SHOW_PUBLIC_VISIBILITY)) {
buffer.append(ProtobufFlags.toString(kotlinFlags.visibility)).append(' ');
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestAnnotations.dec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pkg
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy

class TestAnnotations {
public class TestAnnotations {
@TestAnnotations.TestAnnotation(first = "test", second = 1)
public fun test() {
}// 16
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestAnyType.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestAnyType {
public class TestAnyType {
public fun test(param: Any): Int {
if (param is java.lang.String) {// 5
return (param as java.lang.String).length();// 6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestBitwiseFunctions {
public class TestBitwiseFunctions {
public fun and(a: Int, b: Int): Int {
return a and b;// 5
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/kotlin/testData/results/pkg/TestClassDec.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestClassDec {
public class TestClassDec {
public fun pkg.TestClassDec.Vec2iVal.dot(v: pkg.TestClassDec.Vec2iVal): Int {
return `$this$dot`.getX() * v.getX() + `$this$dot`.getY() * v.getY();// 11
}
Expand All @@ -13,13 +13,13 @@ class TestClassDec {
System.out.println(this.dot(vec, vec1));// 20
}// 21

class EmptyDec {
public class EmptyDec {
}

class Vec2i(x: Int, y: Int) {
public class Vec2i(x: Int, y: Int) {
}

class Vec2iVal(x: Int, y: Int) {
public class Vec2iVal(x: Int, y: Int) {
public final val x: Int
public final val y: Int

Expand All @@ -29,7 +29,7 @@ class TestClassDec {
}
}

class Vec2iVar(x: Int, y: Int) {
public class Vec2iVar(x: Int, y: Int) {
public final var x: Int
internal set
public final var y: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestClassicStringInterpolation {
public class TestClassicStringInterpolation {
public final val x: Int = 5


Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestComparison.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestComparison {
public class TestComparison {
public fun test2(a: Any, b: Any): Boolean {
return a == b;// 5
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/kotlin/testData/results/pkg/TestCompileTimeErrors.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestCompileTimeErrors {
public class TestCompileTimeErrors {
public fun <I, O> test(i: I): O where O : I, O : pkg.TestCompileTimeErrors.Test {
throw new NotImplementedError(null, 1, null);// 10
}
Expand All @@ -24,7 +24,7 @@ class TestCompileTimeErrors {
};
}

interface Test {
public interface Test {
public val testValue: Int
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestConstructors.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestConstructors private constructor() {
public class TestConstructors private constructor() {
public constructor(a: Int) : this() {// 4
System.out.println("a = $a");// 5
}// 6
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestContracts.dec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlin.contracts.InvocationKind
import kotlin.jvm.internal.SourceDebugExtension

@SourceDebugExtension(["SMAP\nTestContracts.kt\nKotlin\n*S Kotlin\n*F\n+ 1 TestContracts.kt\npkg/TestContracts\n+ 2 fake.kt\nkotlin/jvm/internal/FakeKt\n*L\n1#1,56:1\n1#2:57\n*E\n"])
class TestContracts {
public class TestContracts {
public fun testSimpleContract(x: Int?): Int {
contract {
returns() implies (x != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestConvertedK2JOps {
public class TestConvertedK2JOps {
public final val list: List<String> = CollectionsKt.listOf(new java.lang.String[]{"a", "b", "c"})
public final val set: Set<String> = SetsKt.setOf(new java.lang.String[]{"a", "b", "c"})
public final val map: Map<String, String> = MapsKt.mapOf(new Pair[]{TuplesKt.to("a", "b"), TuplesKt.to("c", "d")})
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestDataClass.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

data class TestDataClass(dataClassVal: Regex, variableWithVeryLongName: Int, requestLineWrapsIfTheParamListIsTooLong: List<String>, nullability: String?) {
public data class TestDataClass(dataClassVal: Regex, variableWithVeryLongName: Int, requestLineWrapsIfTheParamListIsTooLong: List<String>, nullability: String?) {
public final val dataClassVal: Regex
public final val variableWithVeryLongName: Int
public final val requestLineWrapsIfTheParamListIsTooLong: List<String>
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestDestructors.dec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlin.jvm.functions.Function0
import kotlin.jvm.internal.SourceDebugExtension

@SourceDebugExtension(["SMAP\nTestDestructors.kt\nKotlin\n*S Kotlin\n*F\n+ 1 TestDestructors.kt\npkg/TestDestructors\n*L\n1#1,71:1\n68#1,3:72\n68#1,3:75\n*S KotlinDebug\n*F\n+ 1 TestDestructors.kt\npkg/TestDestructors\n*L\n49#1:72,3\n54#1:75,3\n*E\n"])
class TestDestructors {
public class TestDestructors {
public fun destructDataClasses(x: Pair<String, Int?>, y: Triple<Number, Boolean?, String>) {
System.out.println("${x.component1() as java.lang.String} ${x.component2() as Integer}");// 8 9
System.out.println("${y.component1() as java.lang.Number} ${y.component2() as java.lang.Boolean} ${y.component3() as java.lang.String}");// 11 12
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestExtensionFun.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestExtensionFun {
public class TestExtensionFun {
public fun CharSequence.repeat2(n: Int): String {
return StringsKt.repeat(`$this$repeat2`, n);// 5
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestForRange.dec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pkg

import kotlin.internal.ProgressionUtilKt

class TestForRange {
public class TestForRange {
public fun testInt() {
for (int i = 1; i < 11; i++) {// 5
System.out.println(i);// 6
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestFunVarargs.dec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pkg

import java.util.Arrays

class TestFunVarargs {
public class TestFunVarargs {
public fun printAll(vararg messages: String) {
for (java.lang.String m : messages) {// 5
System.out.println(m);
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestGenerics.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestGenerics<T> {
public class TestGenerics<T> {
public fun <T> genericFun(v: T): T {
return (T)v;// 5
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestIfRange.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestIfRange {
public class TestIfRange {
public fun testInt(x: Int) {
if (1 <= x && x < 11) {// 5
System.out.println(x);// 6
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestInfixFun.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestInfixFun {
public class TestInfixFun {
public fun test() {
System.out.println(test$times(2, "Bye "));// 7
}// 8
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestKotlinTypes.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestKotlinTypes {
public class TestKotlinTypes {
public final val consumer: (Int) -> Unit = TestKotlinTypes::consumer$lambda$0


Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestKt.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestKt {
public class TestKt {
public fun test() {
System.out.println("Hello, world!");// 5
}// 6
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestLabeledJumps.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestLabeledJumps {
public class TestLabeledJumps {
public fun testContinue(tester: (Int) -> Boolean) {
label24:
for (int i = 1; i < 101; i++) {// 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pkg
import kotlin.jvm.internal.Ref.IntRef
import kotlin.jvm.internal.Ref.ObjectRef

open class TestNonInlineLambda {
public open class TestNonInlineLambda {
public final var intField: Int
internal set
public final var stringField: String = ""
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestNothingReturns.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestNothingReturns {
public class TestNothingReturns {
public fun loop(): Nothing {
while (true) {
System.out.println("loop");// 6
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestNullable.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestNullable {
public class TestNullable {
public fun nullableParams(v: String, vn: String?) {
}// 6

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestNullableOperator {
public class TestNullableOperator {
public fun test(x: Int?): Int {
return x ?: 0;// 5
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestObject.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

object TestObject private constructor() {
public object TestObject private constructor() {
@JvmStatic
public TestObject INSTANCE = new TestObject();

Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestParams.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestParams {
public class TestParams {
public fun printMessageUnit(message: String) {
System.out.println(message);// 5
}// 6
Expand Down
4 changes: 2 additions & 2 deletions plugins/kotlin/testData/results/pkg/TestPoorNames.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestPoorNames {
public class TestPoorNames {
public final val `Property with spaces`: Int = 42
public final val `Dangerous property name?!`: String = "test"

Expand All @@ -23,7 +23,7 @@ class TestPoorNames {
this.functionWithParameters(42, "test");// 24
}// 25

class `Class with spaces` {
public class `Class with spaces` {
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestReflection.dec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pkg
import kotlin.jvm.functions.Function1
import kotlin.reflect.KFunction

class TestReflection {
public class TestReflection {
public fun testClassReference() {
System.out.println(TestReflection::class);// 5
System.out.println(TestReflection::class.java);// 6
Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestSafeCasts.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestSafeCasts {
public class TestSafeCasts {
public fun test(obj: Any): Boolean {
var t: Int = obj as? Integer;// 5
if ((obj as? Integer) != null) {// 7
Expand Down
6 changes: 3 additions & 3 deletions plugins/kotlin/testData/results/pkg/TestSealedHierarchy.dec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package pkg

sealed class TestSealedHierarchy protected constructor() {
class TestClass(x: Int) : TestSealedHierarchy() {// 5
public sealed class TestSealedHierarchy protected constructor() {
public class TestClass(x: Int) : TestSealedHierarchy() {// 5
public final val x: Int

init {
this.x = x;
}
}

object TestObject private constructor() : TestSealedHierarchy() {// 4
public object TestObject private constructor() : TestSealedHierarchy() {// 4
@JvmStatic
public TestSealedHierarchy.TestObject INSTANCE = new TestSealedHierarchy.TestObject();

Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestShadowParam.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestShadowParam {
public class TestShadowParam {
public fun test(x: Int) {
var xx: Int = x - 1;// 5 6
System.out.println(x - 1);// 7
Expand Down
10 changes: 5 additions & 5 deletions plugins/kotlin/testData/results/pkg/TestSmartCasts.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestSmartCasts {
public class TestSmartCasts {
public fun testWhen(o: Any?): String {
if (o is java.lang.String) {// 19 20
return o as java.lang.String;// 21
Expand Down Expand Up @@ -72,25 +72,25 @@ class TestSmartCasts {
return if (t is TestSmartCasts.X) (t as TestSmartCasts.X).woo(t as java.lang.Iterable<?>) else t.get(0) as java.lang.String;// 83 84 87
}

sealed class A protected constructor() {
public sealed class A protected constructor() {
public fun test(): String {
return "";// 15
}

class B : TestSmartCasts.A() {// 8
public class B : TestSmartCasts.A() {// 8
public fun testB(): String {
return "B";// 9
}
}

class C : TestSmartCasts.A() {// 11
public class C : TestSmartCasts.A() {// 11
public fun testC(): String {
return "C";// 12
}
}
}

interface X {
public interface X {
public open fun Iterable<*>.woo(): String {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestStringInterpolation {
public class TestStringInterpolation {
public final val x: Int = 5


Expand Down
2 changes: 1 addition & 1 deletion plugins/kotlin/testData/results/pkg/TestSynchronized.dec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestSynchronized {
public class TestSynchronized {
public fun test() {
synchronized (this) {// 5
System.out.println("Hello");// 6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pkg

class TestTailrecFunctions {
public class TestTailrecFunctions {
public tailrec fun sum(x: Long, sum: Long): Long {
var var5: TestTailrecFunctions = this;// 4

Expand Down
Loading

0 comments on commit 7f460c3

Please sign in to comment.