FIR Java: generate accessors only in override Kotlin case, make them non-synthetic

This commit is contained in:
Mikhail Glukhikh
2019-11-29 16:47:52 +03:00
parent 5275b4d0fc
commit a6f8859a49
4 changed files with 24 additions and 20 deletions
@@ -53,24 +53,23 @@ class JavaClassUseSiteMemberScope(
} }
} }
private fun processAccessorFunction( private fun generateAccessorSymbol(
functionSymbol: FirFunctionSymbol<*>, functionSymbol: FirFunctionSymbol<*>,
syntheticPropertyName: Name, syntheticPropertyName: Name,
overrideCandidates: MutableSet<FirCallableSymbol<*>>, overrideCandidates: MutableSet<FirCallableSymbol<*>>,
processor: (FirCallableSymbol<*>) -> ProcessorAction,
isGetter: Boolean isGetter: Boolean
): ProcessorAction { ): FirAccessorSymbol? {
if (functionSymbol is FirNamedFunctionSymbol) { if (functionSymbol is FirNamedFunctionSymbol) {
val fir = functionSymbol.fir val fir = functionSymbol.fir
if (fir.isStatic) { if (fir.isStatic) {
return NEXT return null
} }
when (isGetter) { when (isGetter) {
true -> if (fir.valueParameters.isNotEmpty()) { true -> if (fir.valueParameters.isNotEmpty()) {
return NEXT return null
} }
false -> if (fir.valueParameters.size != 1) { false -> if (fir.valueParameters.size != 1) {
return NEXT return null
} }
} }
} }
@@ -82,7 +81,7 @@ class JavaClassUseSiteMemberScope(
if (functionSymbol is FirNamedFunctionSymbol) { if (functionSymbol is FirNamedFunctionSymbol) {
functionSymbol.fir.let { callableMember -> accessorSymbol.bind(callableMember) } functionSymbol.fir.let { callableMember -> accessorSymbol.bind(callableMember) }
} }
return processor(accessorSymbol) return accessorSymbol
} }
private fun processAccessorFunctionsAndPropertiesByName( private fun processAccessorFunctionsAndPropertiesByName(
@@ -100,10 +99,16 @@ class JavaClassUseSiteMemberScope(
) return STOP ) return STOP
if (klass is FirJavaClass) { if (klass is FirJavaClass) {
for (getterName in getterNames) { for (getterName in getterNames) {
if (!declaredMemberScope.processFunctionsByName(getterName) { functionSymbol -> declaredMemberScope.processFunctionsByName(getterName) { functionSymbol ->
processAccessorFunction(functionSymbol, propertyName, overrideCandidates, processor, isGetter = true) val accessorSymbol = generateAccessorSymbol(
functionSymbol, propertyName, overrideCandidates, isGetter = true
)
if (accessorSymbol != null) {
// NB: accessor should not be processed directly unless we find matching property symbol in supertype
overrideCandidates += accessorSymbol
} }
) return STOP NEXT
}
} }
} }
@@ -112,11 +117,10 @@ class JavaClassUseSiteMemberScope(
if (firCallableMember?.isStatic == true) { if (firCallableMember?.isStatic == true) {
processor(it) processor(it)
} else { } else {
val overriddenBy = it.getOverridden(overrideCandidates) when (val overriddenBy = it.getOverridden(overrideCandidates)) {
if (overriddenBy == null) { null -> processor(it)
processor(it) is FirAccessorSymbol -> processor(overriddenBy)
} else { else -> NEXT
NEXT
} }
} }
} }
@@ -149,7 +153,7 @@ class JavaClassUseSiteMemberScope(
override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> ProcessorAction): ProcessorAction { override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> ProcessorAction): ProcessorAction {
// Do not generate accessors at all? // Do not generate accessors at all?
if (true) { if (name.isSpecial) {
return processAccessorFunctionsAndPropertiesByName(name, emptyList(), null, processor) return processAccessorFunctionsAndPropertiesByName(name, emptyList(), null, processor)
} }
val getterNames = FirSyntheticPropertiesScope.possibleGetterNamesByPropertyName(name) val getterNames = FirSyntheticPropertiesScope.possibleGetterNamesByPropertyName(name)
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeFirstWord
class SyntheticPropertySymbol( class SyntheticPropertySymbol(
callableId: CallableId, callableId: CallableId,
override val accessorId: CallableId override val accessorId: CallableId
) : FirNamedFunctionSymbol(callableId), AccessorSymbol ) : FirNamedFunctionSymbol(callableId), AccessorSymbol, SyntheticSymbol
class FirSyntheticFunctionSymbol( class FirSyntheticFunctionSymbol(
callableId: CallableId callableId: CallableId
@@ -7,7 +7,7 @@ FILE: main.kt
} }
public final fun test(): R|kotlin/Unit| { public final fun test(): R|kotlin/Unit| {
lval b: R|MyMapEntry| = R|/MyMapEntry.MyMapEntry|() lval b: R|MyMapEntry| = R|/MyMapEntry.MyMapEntry|()
R|<local>/b|.R|FakeOverride<kotlin/collections/Map.Entry.key: R|kotlin/String|>| R|<local>/b|.R|/Test.MapEntryImpl.key|
R|<local>/b|.R|FakeOverride<kotlin/collections/Map.Entry.value: R|kotlin/String|>| R|<local>/b|.R|/Test.MapEntryImpl.value|
R|<local>/b|.R|/Test.MapEntryImpl.setValue|(Null(null)) R|<local>/b|.R|/Test.MapEntryImpl.setValue|(Null(null))
} }
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.symbols
interface SyntheticSymbol interface SyntheticSymbol
interface AccessorSymbol : SyntheticSymbol { interface AccessorSymbol {
val callableId: CallableId // it's an id of related property (synthetic or not) val callableId: CallableId // it's an id of related property (synthetic or not)
val accessorId: CallableId // it's an id of accessor function val accessorId: CallableId // it's an id of accessor function
} }