[FIR] Synthetic property symbol is now a property symbol, not a function
This commit is contained in:
@@ -8,15 +8,13 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.isStatic
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.symbols.AccessorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
|
||||
@@ -27,7 +25,7 @@ import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeFirstWord
|
||||
class SyntheticPropertySymbol(
|
||||
callableId: CallableId,
|
||||
override val accessorId: CallableId
|
||||
) : FirNamedFunctionSymbol(callableId), AccessorSymbol, SyntheticSymbol
|
||||
) : FirPropertySymbol(callableId), AccessorSymbol, SyntheticSymbol
|
||||
|
||||
class FirSyntheticFunctionSymbol(
|
||||
callableId: CallableId
|
||||
@@ -43,7 +41,7 @@ class FirSyntheticPropertiesScope(
|
||||
private fun checkGetAndCreateSynthetic(
|
||||
name: Name,
|
||||
symbol: FirFunctionSymbol<*>,
|
||||
processor: (FirCallableSymbol<*>) -> Unit
|
||||
processor: (FirVariableSymbol<*>) -> Unit
|
||||
) {
|
||||
val fir = symbol.fir as? FirSimpleFunction ?: return
|
||||
|
||||
@@ -52,13 +50,15 @@ class FirSyntheticPropertiesScope(
|
||||
if (fir.isStatic) return
|
||||
if (fir.returnTypeRef.coneTypeSafe<ConeClassLikeType>()?.lookupTag?.classId == StandardClassIds.Unit) return
|
||||
|
||||
val synthetic = SyntheticPropertySymbol(
|
||||
accessorId = symbol.callableId,
|
||||
callableId = CallableId(symbol.callableId.packageName, symbol.callableId.className, name)
|
||||
val property = FirSyntheticProperty(
|
||||
session, name,
|
||||
symbol = SyntheticPropertySymbol(
|
||||
accessorId = symbol.callableId,
|
||||
callableId = CallableId(symbol.callableId.packageName, symbol.callableId.className, name)
|
||||
),
|
||||
delegateGetter = fir
|
||||
)
|
||||
synthetic.bind(fir)
|
||||
|
||||
processor(synthetic)
|
||||
processor(property.symbol)
|
||||
}
|
||||
|
||||
override fun processPropertiesByName(name: Name, processor: (FirCallableSymbol<*>) -> Unit) {
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations.synthetic
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.references.impl.FirEmptyControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirDelegateFieldSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
|
||||
class FirSyntheticProperty(
|
||||
override val session: FirSession,
|
||||
override val returnTypeRef: FirTypeRef,
|
||||
override val name: Name,
|
||||
override val isVar: Boolean,
|
||||
override val symbol: FirPropertySymbol,
|
||||
override val status: FirDeclarationStatus,
|
||||
override val resolvePhase: FirResolvePhase,
|
||||
override val getter: FirSyntheticPropertyAccessor,
|
||||
override val setter: FirSyntheticPropertyAccessor? = null
|
||||
) : FirProperty() {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
constructor(
|
||||
session: FirSession,
|
||||
name: Name,
|
||||
symbol: FirPropertySymbol,
|
||||
delegateGetter: FirSimpleFunction
|
||||
) : this(
|
||||
session, delegateGetter.returnTypeRef, name, false, symbol,
|
||||
FirDeclarationStatusImpl(delegateGetter.visibility, delegateGetter.modality),
|
||||
delegateGetter.resolvePhase,
|
||||
FirSyntheticPropertyAccessor(delegateGetter, isGetter = true)
|
||||
)
|
||||
|
||||
override val source: FirSourceElement?
|
||||
get() = null
|
||||
|
||||
override val initializer: FirExpression?
|
||||
get() = null
|
||||
|
||||
override val delegate: FirExpression?
|
||||
get() = null
|
||||
|
||||
override val delegateFieldSymbol: FirDelegateFieldSymbol<FirProperty>?
|
||||
get() = null
|
||||
|
||||
override val isLocal: Boolean
|
||||
get() = false
|
||||
|
||||
override val receiverTypeRef: FirTypeRef?
|
||||
get() = null
|
||||
|
||||
override val isVal: Boolean
|
||||
get() = !isVar
|
||||
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = emptyList()
|
||||
|
||||
override val typeParameters: List<FirTypeParameter>
|
||||
get() = emptyList()
|
||||
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = null
|
||||
|
||||
override val controlFlowGraphReference: FirControlFlowGraphReference = FirEmptyControlFlowGraphReference
|
||||
|
||||
// ???
|
||||
override val backingFieldSymbol: FirBackingFieldSymbol = FirBackingFieldSymbol(symbol.callableId)
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
returnTypeRef.accept(visitor, data)
|
||||
status.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformReceiverTypeRef(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformControlFlowGraphReference(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformStatus(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformOtherChildren(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformInitializer(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformGetter(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformSetter(transformer: FirTransformer<D>, data: D): FirSyntheticProperty {
|
||||
throw AssertionError("Transformation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) {
|
||||
throw AssertionError("Mutation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceReturnTypeRef(newReturnTypeRef: FirTypeRef) {
|
||||
throw AssertionError("Mutation of synthetic property isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceReceiverTypeRef(newReceiverTypeRef: FirTypeRef?) {
|
||||
throw AssertionError("Mutation of synthetic property isn't supported")
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.declarations.synthetic
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.contracts.FirContractDescription
|
||||
import org.jetbrains.kotlin.fir.contracts.impl.FirEmptyContractDescription
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirPropertyAccessorImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.references.impl.FirEmptyControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||
|
||||
class FirSyntheticPropertyAccessor(
|
||||
private val delegate: FirSimpleFunction,
|
||||
override val isGetter: Boolean
|
||||
) : FirPropertyAccessor() {
|
||||
override val source: FirSourceElement?
|
||||
get() = delegate.source
|
||||
|
||||
override val session: FirSession
|
||||
get() = delegate.session
|
||||
|
||||
override val returnTypeRef: FirTypeRef
|
||||
get() = delegate.returnTypeRef
|
||||
|
||||
override val resolvePhase: FirResolvePhase
|
||||
get() = delegate.resolvePhase
|
||||
|
||||
override val status: FirDeclarationStatus
|
||||
get() = delegate.status
|
||||
|
||||
override val receiverTypeRef: FirTypeRef?
|
||||
get() = null
|
||||
|
||||
override val valueParameters: List<FirValueParameter>
|
||||
get() = delegate.valueParameters
|
||||
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = delegate.annotations
|
||||
|
||||
override val typeParameters: List<FirTypeParameter>
|
||||
get() = emptyList()
|
||||
|
||||
override val isSetter: Boolean
|
||||
get() = !isGetter
|
||||
|
||||
override val body: FirBlock?
|
||||
get() = delegate.body
|
||||
|
||||
override val symbol: FirPropertyAccessorSymbol = FirPropertyAccessorSymbol().apply {
|
||||
bind(this@FirSyntheticPropertyAccessor)
|
||||
}
|
||||
|
||||
override val controlFlowGraphReference: FirControlFlowGraphReference = FirEmptyControlFlowGraphReference
|
||||
|
||||
override val contractDescription: FirContractDescription = FirEmptyContractDescription
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
delegate.accept(visitor, data)
|
||||
controlFlowGraphReference.accept(visitor, data)
|
||||
contractDescription.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformReceiverTypeRef(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformControlFlowGraphReference(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformValueParameters(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformContractDescription(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun <D> transformStatus(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
|
||||
throw AssertionError("Transformation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) {
|
||||
throw AssertionError("Mutation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceReturnTypeRef(newReturnTypeRef: FirTypeRef) {
|
||||
throw AssertionError("Mutation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceReceiverTypeRef(newReceiverTypeRef: FirTypeRef?) {
|
||||
throw AssertionError("Mutation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceValueParameters(newValueParameters: List<FirValueParameter>) {
|
||||
throw AssertionError("Mutation of synthetic property accessor isn't supported")
|
||||
}
|
||||
|
||||
override fun replaceContractDescription(newContractDescription: FirContractDescription) {
|
||||
throw AssertionError("Mutation of synthetic property accessor isn't supported")
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -2,12 +2,12 @@ FILE fqName:<root> fileName:/javaSyntheticPropertyAccess.kt
|
||||
FUN name:test visibility:public modality:FINAL <> (j:<root>.J) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:j index:0 type:<root>.J
|
||||
BLOCK_BODY
|
||||
CALL 'public open fun getFoo (): kotlin.Int [operator] declared in <root>.J' type=kotlin.Int origin=GET_PROPERTY
|
||||
CALL 'public open fun <get-foo> (): kotlin.Int declared in <root>.J' type=kotlin.Int origin=null
|
||||
$this: GET_VAR 'j: <root>.J declared in <root>.test' type=<root>.J origin=null
|
||||
ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val]
|
||||
CALL 'public open fun getFoo (): kotlin.Int [operator] declared in <root>.J' type=kotlin.Int origin=GET_PROPERTY
|
||||
CALL 'public open fun <get-foo> (): kotlin.Int declared in <root>.J' type=kotlin.Int origin=null
|
||||
$this: GET_VAR 'j: <root>.J declared in <root>.test' type=<root>.J origin=null
|
||||
ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType
|
||||
GET_VAR 'val tmp_0: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||
ERROR_CALL 'Unresolved reference: <Variable expected>#' type=IrErrorType
|
||||
ERROR_CALL 'Unresolved reference: R|/J.foo|' type=IrErrorType
|
||||
|
||||
@@ -2,7 +2,7 @@ FILE fqName:<root> fileName:/javaSyntheticProperty.kt
|
||||
PROPERTY name:test visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
CALL 'public open fun getFoo (): kotlin.String? [operator] declared in <root>.J' type=kotlin.String? origin=GET_PROPERTY
|
||||
CALL 'public open fun <get-foo> (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
|
||||
$this: CONSTRUCTOR_CALL 'public/*package*/ constructor <init> () [primary] declared in <root>.J' type=<root>.J origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.String?
|
||||
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
|
||||
|
||||
@@ -4,5 +4,5 @@ FILE fqName:<root> fileName:/jdkClassSyntheticProperty.kt
|
||||
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.Array<out java.lang.reflect.Field?>? declared in <root>'
|
||||
CALL 'public open fun getDeclaredFields (): kotlin.Array<out java.lang.reflect.Field?>? [operator] declared in java.lang.Class' type=kotlin.Array<out java.lang.reflect.Field?>? origin=GET_PROPERTY
|
||||
CALL 'public open fun <get-declaredFields> (): kotlin.Array<out java.lang.reflect.Field?>? declared in java.lang.Class' type=kotlin.Array<out java.lang.reflect.Field?>? origin=null
|
||||
$this: ERROR_CALL 'Unresolved reference: this@R|/test|' type=java.lang.Class<*>
|
||||
|
||||
Reference in New Issue
Block a user