FIR LC: correct static modifiers for accessors from companion
This commit is contained in:
committed by
Ilya Kirillov
parent
a7a01a1f7e
commit
85388f0c79
+3
@@ -39,6 +39,9 @@ internal abstract class FirLightClassForClassOrObjectSymbol(
|
||||
|
||||
protected val isTopLevel: Boolean = classOrObjectSymbol.symbolKind == KtSymbolKind.TOP_LEVEL
|
||||
|
||||
internal val isCompanionObject: Boolean
|
||||
get() = classOrObjectSymbol.classKind == KtClassKind.COMPANION_OBJECT
|
||||
|
||||
private val _isDeprecated: Boolean by lazyPub {
|
||||
classOrObjectSymbol.hasDeprecatedAnnotation()
|
||||
}
|
||||
|
||||
+4
-7
@@ -112,8 +112,8 @@ internal open class FirLightClassForSymbol(
|
||||
}
|
||||
}
|
||||
|
||||
val suppressStatic = classOrObjectSymbol.isCompanionObject
|
||||
createMethods(visibleDeclarations, result, suppressStaticForMethods = suppressStatic)
|
||||
val suppressStatic = isCompanionObject
|
||||
createMethods(visibleDeclarations, result, suppressStatic = suppressStatic)
|
||||
|
||||
createConstructors(declaredMemberScope.getConstructors(), result)
|
||||
}
|
||||
@@ -234,7 +234,7 @@ internal open class FirLightClassForSymbol(
|
||||
analyzeWithSymbolAsContext(classOrObjectSymbol) {
|
||||
val propertySymbols = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
|
||||
.filterIsInstance<KtPropertySymbol>()
|
||||
.applyIf(classOrObjectSymbol.isCompanionObject) {
|
||||
.applyIf(isCompanionObject) {
|
||||
// All fields for companion object of classes are generated to the containing class
|
||||
// For interfaces, only @JvmField-annotated properties are generated to the containing class
|
||||
// Probably, the same should work for const vals but it doesn't at the moment (see KT-28294)
|
||||
@@ -249,7 +249,7 @@ internal open class FirLightClassForSymbol(
|
||||
val isLateInit = (propertySymbol as? KtKotlinPropertySymbol)?.isLateInit == true
|
||||
|
||||
val forceStatic = classOrObjectSymbol.isObject
|
||||
val takePropertyVisibility = !classOrObjectSymbol.isCompanionObject && (isLateInit || isJvmField)
|
||||
val takePropertyVisibility = !isCompanionObject && (isLateInit || isJvmField)
|
||||
|
||||
createField(
|
||||
declaration = propertySymbol,
|
||||
@@ -294,9 +294,6 @@ internal open class FirLightClassForSymbol(
|
||||
private val KtClassOrObjectSymbol.isObject: Boolean
|
||||
get() = classKind == KtClassKind.OBJECT
|
||||
|
||||
private val KtClassOrObjectSymbol.isCompanionObject: Boolean
|
||||
get() = classKind == KtClassKind.COMPANION_OBJECT
|
||||
|
||||
private val KtClassOrObjectSymbol.isNamedObject: Boolean
|
||||
get() = isObject && !isCompanionObject
|
||||
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ internal class FirLightInlineClass(
|
||||
it.deprecationStatus?.deprecationLevel == DeprecationLevelValue.HIDDEN
|
||||
}
|
||||
|
||||
createMethods(applicableDeclarations, result, suppressStaticForMethods = false)
|
||||
createMethods(applicableDeclarations, result, suppressStatic = false)
|
||||
|
||||
val inlineClassParameterSymbol =
|
||||
declaredMemberScope.getConstructors().singleOrNull { it.isPrimary }?.valueParameters?.singleOrNull()
|
||||
|
||||
+13
-9
@@ -94,10 +94,6 @@ internal fun KtClassOrObjectSymbol.createLightClassNoCache(manager: PsiManager):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private fun lightClassForEnumEntry(ktEnumEntry: KtEnumEntry): KtLightClass? {
|
||||
if (ktEnumEntry.body == null) return null
|
||||
|
||||
@@ -185,7 +181,7 @@ internal fun FirLightClassBase.createMethods(
|
||||
declarations: Sequence<KtCallableSymbol>,
|
||||
result: MutableList<KtLightMethod>,
|
||||
isTopLevel: Boolean = false,
|
||||
suppressStaticForMethods: Boolean = false
|
||||
suppressStatic : Boolean = false
|
||||
) {
|
||||
val declarationGroups = declarations.groupBy { it is KtPropertySymbol && it.isFromPrimaryConstructor }
|
||||
|
||||
@@ -205,7 +201,7 @@ internal fun FirLightClassBase.createMethods(
|
||||
containingClass = this@createMethods,
|
||||
isTopLevel = isTopLevel,
|
||||
methodIndex = methodIndex,
|
||||
suppressStatic = suppressStaticForMethods
|
||||
suppressStatic = suppressStatic
|
||||
)
|
||||
)
|
||||
|
||||
@@ -231,7 +227,12 @@ internal fun FirLightClassBase.createMethods(
|
||||
}
|
||||
}
|
||||
}
|
||||
is KtPropertySymbol -> createPropertyAccessors(result, declaration, isTopLevel)
|
||||
is KtPropertySymbol -> createPropertyAccessors(
|
||||
result,
|
||||
declaration,
|
||||
isTopLevel = isTopLevel,
|
||||
suppressStatic = suppressStatic
|
||||
)
|
||||
is KtConstructorSymbol -> error("Constructors should be handled separately and not passed to this function")
|
||||
}
|
||||
}
|
||||
@@ -252,6 +253,7 @@ internal fun FirLightClassBase.createPropertyAccessors(
|
||||
isTopLevel: Boolean,
|
||||
isMutable: Boolean = !declaration.isVal,
|
||||
onlyJvmStatic: Boolean = false,
|
||||
suppressStatic: Boolean = false,
|
||||
) {
|
||||
if (declaration is KtKotlinPropertySymbol && declaration.isConst) return
|
||||
|
||||
@@ -292,7 +294,8 @@ internal fun FirLightClassBase.createPropertyAccessors(
|
||||
containingPropertySymbol = declaration,
|
||||
lightMemberOrigin = lightMemberOrigin,
|
||||
containingClass = this@createPropertyAccessors,
|
||||
isTopLevel = isTopLevel
|
||||
isTopLevel = isTopLevel,
|
||||
suppressStatic = suppressStatic,
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -315,7 +318,8 @@ internal fun FirLightClassBase.createPropertyAccessors(
|
||||
containingPropertySymbol = declaration,
|
||||
lightMemberOrigin = lightMemberOrigin,
|
||||
containingClass = this@createPropertyAccessors,
|
||||
isTopLevel = isTopLevel
|
||||
isTopLevel = isTopLevel,
|
||||
suppressStatic = suppressStatic,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
+4
-1
@@ -29,6 +29,7 @@ internal class FirLightAccessorMethodForSymbol(
|
||||
lightMemberOrigin: LightMemberOrigin?,
|
||||
containingClass: FirLightClassBase,
|
||||
private val isTopLevel: Boolean,
|
||||
private val suppressStatic: Boolean = false,
|
||||
) : FirLightMethod(
|
||||
lightMemberOrigin,
|
||||
containingClass,
|
||||
@@ -115,7 +116,9 @@ internal class FirLightAccessorMethodForSymbol(
|
||||
} ?: propertyAccessorSymbol.toPsiVisibilityForMember(isTopLevel)
|
||||
modifiers.add(visibility)
|
||||
|
||||
if (containingPropertySymbol.hasJvmStaticAnnotation(accessorSite)) {
|
||||
if (!suppressStatic &&
|
||||
(containingPropertySymbol.hasJvmStaticAnnotation() || propertyAccessorSymbol.hasJvmStaticAnnotation(accessorSite))
|
||||
) {
|
||||
modifiers.add(PsiModifier.STATIC)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ public final class C /* C*/ {
|
||||
public static final void foo();// foo()
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final java.lang.String getX();// getX()
|
||||
public static final java.lang.String getX();// getX()
|
||||
|
||||
public C();// .ctor()
|
||||
|
||||
public final void setX(@org.jetbrains.annotations.NotNull() java.lang.String);// setX(java.lang.String)
|
||||
public static final void setX(@org.jetbrains.annotations.NotNull() java.lang.String);// setX(java.lang.String)
|
||||
|
||||
|
||||
|
||||
@@ -105,11 +105,11 @@ public final class Obj /* Obj*/ implements java.lang.Runnable {
|
||||
public static final int zoo();// zoo()
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public final java.lang.String getX();// getX()
|
||||
public static final java.lang.String getX();// getX()
|
||||
|
||||
private Obj();// .ctor()
|
||||
|
||||
public final void setX(@org.jetbrains.annotations.NotNull() java.lang.String);// setX(java.lang.String)
|
||||
public static final void setX(@org.jetbrains.annotations.NotNull() java.lang.String);// setX(java.lang.String)
|
||||
|
||||
public void run();// run()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user