[SLC] make INSTANCE field for object public
^KT-56441 Fixed
This commit is contained in:
committed by
Space Team
parent
8e815e943e
commit
6c24436657
+1
-1
@@ -107,7 +107,7 @@ abstract class SymbolLightClassBase protected constructor(val ktModule: KtModule
|
||||
}
|
||||
}
|
||||
|
||||
protected open val isTopLevel: Boolean get() = false
|
||||
internal open val isTopLevel: Boolean get() = false
|
||||
|
||||
private val _containingFile: PsiFile? by lazyPub {
|
||||
val kotlinOrigin = kotlinOrigin ?: return@lazyPub null
|
||||
|
||||
+1
@@ -273,6 +273,7 @@ internal open class SymbolLightClassForClassOrObject : SymbolLightClassForNamedC
|
||||
containingClass = this,
|
||||
name = JvmAbi.INSTANCE_FIELD,
|
||||
lightMemberOrigin = null,
|
||||
isCompanion = false,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+2
-4
@@ -26,8 +26,6 @@ import org.jetbrains.kotlin.light.classes.symbol.fields.SymbolLightFieldForPrope
|
||||
import org.jetbrains.kotlin.light.classes.symbol.isConstOrJvmField
|
||||
import org.jetbrains.kotlin.light.classes.symbol.isLateInit
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.GranularModifiersBox
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.with
|
||||
import org.jetbrains.kotlin.light.classes.symbol.toPsiVisibilityForClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
||||
|
||||
@@ -137,6 +135,7 @@ abstract class SymbolLightClassForNamedClassLike : SymbolLightClassForClassLike<
|
||||
containingClass = this,
|
||||
name = it.name.asString(),
|
||||
lightMemberOrigin = null,
|
||||
isCompanion = true,
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -144,8 +143,7 @@ abstract class SymbolLightClassForNamedClassLike : SymbolLightClassForClassLike<
|
||||
|
||||
internal fun computeModifiers(modifier: String): Map<String, Boolean>? = when (modifier) {
|
||||
in GranularModifiersBox.VISIBILITY_MODIFIERS -> {
|
||||
val visibility = withClassOrObjectSymbol { it.toPsiVisibilityForClass(isNested = !isTopLevel) }
|
||||
GranularModifiersBox.VISIBILITY_MODIFIERS_MAP.with(visibility)
|
||||
GranularModifiersBox.computeVisibilityForClass(ktModule, classOrObjectSymbolPointer, isTopLevel)
|
||||
}
|
||||
|
||||
in GranularModifiersBox.MODALITY_MODIFIERS -> GranularModifiersBox.computeSimpleModality(ktModule, classOrObjectSymbolPointer)
|
||||
|
||||
+17
-9
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.light.classes.symbol.classes.SymbolLightClassForClas
|
||||
import org.jetbrains.kotlin.light.classes.symbol.compareSymbolPointers
|
||||
import org.jetbrains.kotlin.light.classes.symbol.isValid
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.GranularModifiersBox
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.InitializedModifiersBox
|
||||
import org.jetbrains.kotlin.light.classes.symbol.modifierLists.SymbolLightMemberModifierList
|
||||
import org.jetbrains.kotlin.light.classes.symbol.nonExistentType
|
||||
import org.jetbrains.kotlin.light.classes.symbol.withSymbol
|
||||
@@ -35,6 +36,7 @@ internal class SymbolLightFieldForObject private constructor(
|
||||
lightMemberOrigin: LightMemberOrigin?,
|
||||
private val objectSymbolPointer: KtSymbolPointer<KtNamedClassOrObjectSymbol>,
|
||||
override val kotlinOrigin: KtObjectDeclaration?,
|
||||
private val isCompanion: Boolean,
|
||||
) : SymbolLightField(containingClass, lightMemberOrigin) {
|
||||
internal constructor(
|
||||
ktAnalysisSession: KtAnalysisSession,
|
||||
@@ -42,12 +44,14 @@ internal class SymbolLightFieldForObject private constructor(
|
||||
name: String,
|
||||
lightMemberOrigin: LightMemberOrigin?,
|
||||
containingClass: SymbolLightClassForClassLike<*>,
|
||||
isCompanion: Boolean,
|
||||
) : this(
|
||||
containingClass = containingClass,
|
||||
name = name,
|
||||
lightMemberOrigin = lightMemberOrigin,
|
||||
kotlinOrigin = objectSymbol.sourcePsiSafe(),
|
||||
objectSymbolPointer = with(ktAnalysisSession) { objectSymbol.createPointer() },
|
||||
isCompanion = isCompanion,
|
||||
)
|
||||
|
||||
private inline fun <T> withObjectDeclarationSymbol(crossinline action: KtAnalysisSession.(KtNamedClassOrObjectSymbol) -> T): T =
|
||||
@@ -58,22 +62,26 @@ internal class SymbolLightFieldForObject private constructor(
|
||||
private val _modifierList: PsiModifierList by lazyPub {
|
||||
SymbolLightMemberModifierList(
|
||||
containingDeclaration = this,
|
||||
modifiersBox = GranularModifiersBox(
|
||||
initialValue = GranularModifiersBox.MODALITY_MODIFIERS_MAP.mutate {
|
||||
it[PsiModifier.FINAL] = true
|
||||
it[PsiModifier.STATIC] = true
|
||||
},
|
||||
computer = ::computeModifiers,
|
||||
),
|
||||
modifiersBox = if (isCompanion) {
|
||||
GranularModifiersBox(
|
||||
initialValue = GranularModifiersBox.MODALITY_MODIFIERS_MAP.mutate {
|
||||
it[PsiModifier.FINAL] = true
|
||||
it[PsiModifier.STATIC] = true
|
||||
},
|
||||
computer = ::computeCompanionModifiers,
|
||||
)
|
||||
} else {
|
||||
InitializedModifiersBox(PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL)
|
||||
},
|
||||
annotationsBox = ComputeAllAtOnceAnnotationsBox { modifierList ->
|
||||
listOf(SymbolLightSimpleAnnotation(NotNull::class.java.name, modifierList))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private fun computeModifiers(modifier: String): Map<String, Boolean>? {
|
||||
private fun computeCompanionModifiers(modifier: String): Map<String, Boolean>? {
|
||||
if (modifier !in GranularModifiersBox.VISIBILITY_MODIFIERS) return null
|
||||
return GranularModifiersBox.computeVisibilityForMember(ktModule, objectSymbolPointer)
|
||||
return GranularModifiersBox.computeVisibilityForClass(ktModule, objectSymbolPointer, isTopLevel = false)
|
||||
}
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
|
||||
+13
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
import org.jetbrains.kotlin.light.classes.symbol.computeSimpleModality
|
||||
import org.jetbrains.kotlin.light.classes.symbol.toPsiVisibilityForClass
|
||||
import org.jetbrains.kotlin.light.classes.symbol.toPsiVisibilityForMember
|
||||
import org.jetbrains.kotlin.light.classes.symbol.withSymbol
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
@@ -71,6 +72,18 @@ internal class GranularModifiersBox(
|
||||
return VISIBILITY_MODIFIERS_MAP.with(visibility)
|
||||
}
|
||||
|
||||
internal fun computeVisibilityForClass(
|
||||
ktModule: KtModule,
|
||||
declarationPointer: KtSymbolPointer<KtSymbolWithVisibility>,
|
||||
isTopLevel: Boolean,
|
||||
): PersistentMap<String, Boolean> {
|
||||
val visibility = declarationPointer.withSymbol(ktModule) {
|
||||
it.toPsiVisibilityForClass(!isTopLevel)
|
||||
}
|
||||
|
||||
return VISIBILITY_MODIFIERS_MAP.with(visibility)
|
||||
}
|
||||
|
||||
internal fun computeSimpleModality(
|
||||
ktModule: KtModule,
|
||||
declarationPointer: KtSymbolPointer<KtSymbolWithModality>,
|
||||
|
||||
+4
-4
@@ -13,15 +13,15 @@ final class PrivateObject /* one.PrivateObject*/ {
|
||||
|
||||
private final void privateFun();// privateFun()
|
||||
|
||||
public final boolean getInternalProperty$test_module();// getInternalProperty$test_module()
|
||||
public final boolean getInternalProperty$light_idea_test_case();// getInternalProperty$light_idea_test_case()
|
||||
|
||||
public final int getPublicProperty();// getPublicProperty()
|
||||
|
||||
public final void internalFun$test_module();// internalFun$test_module()
|
||||
public final void internalFun$light_idea_test_case();// internalFun$light_idea_test_case()
|
||||
|
||||
public final void publicFun();// publicFun()
|
||||
|
||||
public final void setInternalProperty$test_module(boolean);// setInternalProperty$test_module(boolean)
|
||||
public final void setInternalProperty$light_idea_test_case(boolean);// setInternalProperty$light_idea_test_case(boolean)
|
||||
|
||||
public final void setPublicProperty(int);// setPublicProperty(int)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
final class PrivateObject /* one.PrivateObject*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private static final one.PrivateObject INSTANCE;
|
||||
private static java.lang.String privateProperty = "" /* initializer type: java.lang.String */;
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private static java.lang.String privateProperty = "" /* initializer type: java.lang.String */;
|
||||
public static final one.PrivateObject INSTANCE;
|
||||
|
||||
private static boolean internalProperty = false /* initializer type: boolean */;
|
||||
|
||||
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
public final class C /* C*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final C.Companion Companion;
|
||||
|
||||
public C();// .ctor()
|
||||
|
||||
class Companion ...
|
||||
|
||||
class Factory ...
|
||||
}
|
||||
|
||||
public static final class Companion /* C.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
|
||||
public final void bar();// bar()
|
||||
}
|
||||
|
||||
public static final class Factory /* C.Factory*/ {
|
||||
private Factory();// .ctor()
|
||||
}
|
||||
+13
@@ -37,6 +37,15 @@ public final class C1 /* C1*/ {
|
||||
class Companion ...
|
||||
}
|
||||
|
||||
public final class C2 /* C2*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final C2.Companion Companion;
|
||||
|
||||
public C2();// .ctor()
|
||||
|
||||
class Companion ...
|
||||
}
|
||||
|
||||
public final class ClassWithConstContainer /* ClassWithConstContainer*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final ClassWithConstContainer.Companion Companion;
|
||||
@@ -96,6 +105,10 @@ public static final class Companion /* I.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* C2.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* ClassWithConstContainer.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
@@ -44,6 +44,15 @@ public final class C1 /* C1*/ {
|
||||
class Companion ...
|
||||
}
|
||||
|
||||
public final class C2 /* C2*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final C2.Companion Companion;
|
||||
|
||||
public C2();// .ctor()
|
||||
|
||||
class Companion ...
|
||||
}
|
||||
|
||||
public final class ClassWithConstContainer /* ClassWithConstContainer*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final ClassWithConstContainer.Companion Companion;
|
||||
@@ -103,6 +112,10 @@ public static final class Companion /* I.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* C2.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* ClassWithConstContainer.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ interface I {
|
||||
companion object { }
|
||||
}
|
||||
|
||||
class C2 {
|
||||
internal companion object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
object Obj : java.lang.Runnable {
|
||||
@JvmStatic var x: String = ""
|
||||
override fun run() {}
|
||||
|
||||
@@ -37,6 +37,15 @@ public final class C1 /* C1*/ {
|
||||
class Companion ...
|
||||
}
|
||||
|
||||
public final class C2 /* C2*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final C2.Companion Companion;
|
||||
|
||||
public C2();// .ctor()
|
||||
|
||||
class Companion ...
|
||||
}
|
||||
|
||||
public final class ClassWithConstContainer /* ClassWithConstContainer*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final ClassWithConstContainer.Companion Companion;
|
||||
@@ -65,11 +74,7 @@ private static final class Companion /* C1.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* I.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* ClassWithConstContainer.Companion*/ {
|
||||
public static final class Companion /* C2.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
@@ -100,6 +105,14 @@ public static final class Companion /* C.Companion*/ {
|
||||
public final void setX(@org.jetbrains.annotations.NotNull() java.lang.String);// setX(java.lang.String)
|
||||
}
|
||||
|
||||
public static final class Companion /* I.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public static final class Companion /* ClassWithConstContainer.Companion*/ {
|
||||
private Companion();// .ctor()
|
||||
}
|
||||
|
||||
public final class ConstContainer /* ConstContainer*/ {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final ConstContainer INSTANCE;
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ abstract class AbstractCompilerLightClassTest : KotlinMultiFileTestWithJava<Kotl
|
||||
val actual = LightClassTestCommon.getActualLightClassText(
|
||||
wholeFile,
|
||||
{ fqname -> findLightClass(allowFrontendExceptions, environment, fqname) },
|
||||
LightClassTestCommon::removeEmptyDefaultImpls
|
||||
{ LightClassTestCommon.removeEmptyDefaultImpls(it).replace("\$test_module", "\$light_idea_test_case") },
|
||||
)
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user