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
|
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 {
|
private val _isDeprecated: Boolean by lazyPub {
|
||||||
classOrObjectSymbol.hasDeprecatedAnnotation()
|
classOrObjectSymbol.hasDeprecatedAnnotation()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-7
@@ -112,8 +112,8 @@ internal open class FirLightClassForSymbol(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val suppressStatic = classOrObjectSymbol.isCompanionObject
|
val suppressStatic = isCompanionObject
|
||||||
createMethods(visibleDeclarations, result, suppressStaticForMethods = suppressStatic)
|
createMethods(visibleDeclarations, result, suppressStatic = suppressStatic)
|
||||||
|
|
||||||
createConstructors(declaredMemberScope.getConstructors(), result)
|
createConstructors(declaredMemberScope.getConstructors(), result)
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,7 @@ internal open class FirLightClassForSymbol(
|
|||||||
analyzeWithSymbolAsContext(classOrObjectSymbol) {
|
analyzeWithSymbolAsContext(classOrObjectSymbol) {
|
||||||
val propertySymbols = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
|
val propertySymbols = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
|
||||||
.filterIsInstance<KtPropertySymbol>()
|
.filterIsInstance<KtPropertySymbol>()
|
||||||
.applyIf(classOrObjectSymbol.isCompanionObject) {
|
.applyIf(isCompanionObject) {
|
||||||
// All fields for companion object of classes are generated to the containing class
|
// 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
|
// 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)
|
// 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 isLateInit = (propertySymbol as? KtKotlinPropertySymbol)?.isLateInit == true
|
||||||
|
|
||||||
val forceStatic = classOrObjectSymbol.isObject
|
val forceStatic = classOrObjectSymbol.isObject
|
||||||
val takePropertyVisibility = !classOrObjectSymbol.isCompanionObject && (isLateInit || isJvmField)
|
val takePropertyVisibility = !isCompanionObject && (isLateInit || isJvmField)
|
||||||
|
|
||||||
createField(
|
createField(
|
||||||
declaration = propertySymbol,
|
declaration = propertySymbol,
|
||||||
@@ -294,9 +294,6 @@ internal open class FirLightClassForSymbol(
|
|||||||
private val KtClassOrObjectSymbol.isObject: Boolean
|
private val KtClassOrObjectSymbol.isObject: Boolean
|
||||||
get() = classKind == KtClassKind.OBJECT
|
get() = classKind == KtClassKind.OBJECT
|
||||||
|
|
||||||
private val KtClassOrObjectSymbol.isCompanionObject: Boolean
|
|
||||||
get() = classKind == KtClassKind.COMPANION_OBJECT
|
|
||||||
|
|
||||||
private val KtClassOrObjectSymbol.isNamedObject: Boolean
|
private val KtClassOrObjectSymbol.isNamedObject: Boolean
|
||||||
get() = isObject && !isCompanionObject
|
get() = isObject && !isCompanionObject
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ internal class FirLightInlineClass(
|
|||||||
it.deprecationStatus?.deprecationLevel == DeprecationLevelValue.HIDDEN
|
it.deprecationStatus?.deprecationLevel == DeprecationLevelValue.HIDDEN
|
||||||
}
|
}
|
||||||
|
|
||||||
createMethods(applicableDeclarations, result, suppressStaticForMethods = false)
|
createMethods(applicableDeclarations, result, suppressStatic = false)
|
||||||
|
|
||||||
val inlineClassParameterSymbol =
|
val inlineClassParameterSymbol =
|
||||||
declaredMemberScope.getConstructors().singleOrNull { it.isPrimary }?.valueParameters?.singleOrNull()
|
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? {
|
private fun lightClassForEnumEntry(ktEnumEntry: KtEnumEntry): KtLightClass? {
|
||||||
if (ktEnumEntry.body == null) return null
|
if (ktEnumEntry.body == null) return null
|
||||||
|
|
||||||
@@ -185,7 +181,7 @@ internal fun FirLightClassBase.createMethods(
|
|||||||
declarations: Sequence<KtCallableSymbol>,
|
declarations: Sequence<KtCallableSymbol>,
|
||||||
result: MutableList<KtLightMethod>,
|
result: MutableList<KtLightMethod>,
|
||||||
isTopLevel: Boolean = false,
|
isTopLevel: Boolean = false,
|
||||||
suppressStaticForMethods: Boolean = false
|
suppressStatic : Boolean = false
|
||||||
) {
|
) {
|
||||||
val declarationGroups = declarations.groupBy { it is KtPropertySymbol && it.isFromPrimaryConstructor }
|
val declarationGroups = declarations.groupBy { it is KtPropertySymbol && it.isFromPrimaryConstructor }
|
||||||
|
|
||||||
@@ -205,7 +201,7 @@ internal fun FirLightClassBase.createMethods(
|
|||||||
containingClass = this@createMethods,
|
containingClass = this@createMethods,
|
||||||
isTopLevel = isTopLevel,
|
isTopLevel = isTopLevel,
|
||||||
methodIndex = methodIndex,
|
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")
|
is KtConstructorSymbol -> error("Constructors should be handled separately and not passed to this function")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,6 +253,7 @@ internal fun FirLightClassBase.createPropertyAccessors(
|
|||||||
isTopLevel: Boolean,
|
isTopLevel: Boolean,
|
||||||
isMutable: Boolean = !declaration.isVal,
|
isMutable: Boolean = !declaration.isVal,
|
||||||
onlyJvmStatic: Boolean = false,
|
onlyJvmStatic: Boolean = false,
|
||||||
|
suppressStatic: Boolean = false,
|
||||||
) {
|
) {
|
||||||
if (declaration is KtKotlinPropertySymbol && declaration.isConst) return
|
if (declaration is KtKotlinPropertySymbol && declaration.isConst) return
|
||||||
|
|
||||||
@@ -292,7 +294,8 @@ internal fun FirLightClassBase.createPropertyAccessors(
|
|||||||
containingPropertySymbol = declaration,
|
containingPropertySymbol = declaration,
|
||||||
lightMemberOrigin = lightMemberOrigin,
|
lightMemberOrigin = lightMemberOrigin,
|
||||||
containingClass = this@createPropertyAccessors,
|
containingClass = this@createPropertyAccessors,
|
||||||
isTopLevel = isTopLevel
|
isTopLevel = isTopLevel,
|
||||||
|
suppressStatic = suppressStatic,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -315,7 +318,8 @@ internal fun FirLightClassBase.createPropertyAccessors(
|
|||||||
containingPropertySymbol = declaration,
|
containingPropertySymbol = declaration,
|
||||||
lightMemberOrigin = lightMemberOrigin,
|
lightMemberOrigin = lightMemberOrigin,
|
||||||
containingClass = this@createPropertyAccessors,
|
containingClass = this@createPropertyAccessors,
|
||||||
isTopLevel = isTopLevel
|
isTopLevel = isTopLevel,
|
||||||
|
suppressStatic = suppressStatic,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -29,6 +29,7 @@ internal class FirLightAccessorMethodForSymbol(
|
|||||||
lightMemberOrigin: LightMemberOrigin?,
|
lightMemberOrigin: LightMemberOrigin?,
|
||||||
containingClass: FirLightClassBase,
|
containingClass: FirLightClassBase,
|
||||||
private val isTopLevel: Boolean,
|
private val isTopLevel: Boolean,
|
||||||
|
private val suppressStatic: Boolean = false,
|
||||||
) : FirLightMethod(
|
) : FirLightMethod(
|
||||||
lightMemberOrigin,
|
lightMemberOrigin,
|
||||||
containingClass,
|
containingClass,
|
||||||
@@ -115,7 +116,9 @@ internal class FirLightAccessorMethodForSymbol(
|
|||||||
} ?: propertyAccessorSymbol.toPsiVisibilityForMember(isTopLevel)
|
} ?: propertyAccessorSymbol.toPsiVisibilityForMember(isTopLevel)
|
||||||
modifiers.add(visibility)
|
modifiers.add(visibility)
|
||||||
|
|
||||||
if (containingPropertySymbol.hasJvmStaticAnnotation(accessorSite)) {
|
if (!suppressStatic &&
|
||||||
|
(containingPropertySymbol.hasJvmStaticAnnotation() || propertyAccessorSymbol.hasJvmStaticAnnotation(accessorSite))
|
||||||
|
) {
|
||||||
modifiers.add(PsiModifier.STATIC)
|
modifiers.add(PsiModifier.STATIC)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ public final class C /* C*/ {
|
|||||||
public static final void foo();// foo()
|
public static final void foo();// foo()
|
||||||
|
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public final java.lang.String getX();// getX()
|
public static final java.lang.String getX();// getX()
|
||||||
|
|
||||||
public C();// .ctor()
|
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()
|
public static final int zoo();// zoo()
|
||||||
|
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public final java.lang.String getX();// getX()
|
public static final java.lang.String getX();// getX()
|
||||||
|
|
||||||
private Obj();// .ctor()
|
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()
|
public void run();// run()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user