Skip to content

Commit f07f24e

Browse files
Googlercopybara-github
authored andcommitted
[J2KT] Move most of visibility related logic from Environment to MemberDescriptor and keep only what's necessary.
PiperOrigin-RevId: 926030874
1 parent a3ff1af commit f07f24e

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

transpiler/java/com/google/j2cl/transpiler/backend/kotlin/Environment.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ internal data class Environment(
121121
/** Returns Kotlin member visibility. */
122122
fun ktVisibility(memberDescriptor: MemberDescriptor): KtVisibility =
123123
when {
124-
// Enum constructors are implicitly private in Kotlin
125-
memberDescriptor.isEnumConstructor -> KtVisibility.PRIVATE
126-
// All interface methods are public in Kotlin, and Java allows non-public static members, so
127-
// we map them to public.
128-
memberDescriptor.isInterfaceMethod -> KtVisibility.PUBLIC
129-
// TODO(b/483489173): Remove when visibility problem in Dagger is solved differently.
130-
memberDescriptor.isConstructor && memberDescriptor.hasInjectAnnotation -> KtVisibility.PUBLIC
131124
// Explicit private members translated as internal
132125
isForcedKtInternal(memberDescriptor) -> KtVisibility.INTERNAL
133126
// Use default visibility for everything else.

transpiler/java/com/google/j2cl/transpiler/backend/kotlin/MemberDescriptorUtils.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package com.google.j2cl.transpiler.backend.kotlin
1717

1818
import com.google.j2cl.transpiler.ast.MemberDescriptor
1919
import com.google.j2cl.transpiler.ast.MethodDescriptor
20-
import com.google.j2cl.transpiler.ast.Visibility
2120
import com.google.j2cl.transpiler.backend.kotlin.ast.Visibility as KtVisibility
2221

2322
internal val MemberDescriptor.isEnumConstructor: Boolean
@@ -36,14 +35,18 @@ internal val MethodDescriptor.isOpen: Boolean
3635

3736
internal val MemberDescriptor.ktVisibility: KtVisibility
3837
get() =
39-
if (useActualKtVisibility) {
40-
KtVisibility.from(visibility)
41-
} else {
42-
when (visibility) {
43-
Visibility.PUBLIC -> KtVisibility.PUBLIC
44-
// Map protected to public, to allow access within the same package across different types.
45-
Visibility.PROTECTED -> KtVisibility.PUBLIC
46-
Visibility.PACKAGE_PRIVATE -> KtVisibility.INTERNAL
47-
Visibility.PRIVATE -> KtVisibility.PRIVATE
48-
}
38+
when {
39+
// Enum constructors are implicitly private in Kotlin
40+
isEnumConstructor -> KtVisibility.PRIVATE
41+
// All interface methods are public in Kotlin, and Java allows non-public static members, so
42+
// we map them to public.
43+
isInterfaceMethod -> KtVisibility.PUBLIC
44+
// TODO(b/483489173): Remove when visibility problem in Dagger (fastinit) is solved
45+
// differently.
46+
isConstructor && hasInjectAnnotation -> KtVisibility.PUBLIC
47+
// When not translating actual visibilites, map protected to public, to allow access within
48+
// the same package across different types.
49+
!useActualKtVisibility && visibility.isProtected -> KtVisibility.PUBLIC
50+
// For all other cases, use the default visibility mapping.
51+
else -> KtVisibility.from(visibility)
4952
}

0 commit comments

Comments
 (0)