[Plugin API] Add extension point to contribute synthetic properties

- needs to fix KT_41006
This commit is contained in:
Roman Artemev
2020-08-12 15:10:30 +03:00
committed by romanart
parent 5ede37d6ab
commit fa2c49a311
3 changed files with 20 additions and 0 deletions
@@ -54,6 +54,9 @@ interface SyntheticResolveExtension {
override fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> =
instances.flatMap { withLinkageErrorLogger(it) { getSyntheticFunctionNames(thisDescriptor) } }
override fun getSyntheticPropertiesNames(thisDescriptor: ClassDescriptor): List<Name> =
instances.flatMap { withLinkageErrorLogger(it) { getSyntheticPropertiesNames(thisDescriptor) } }
override fun generateSyntheticClasses(
thisDescriptor: ClassDescriptor, name: Name,
ctx: LazyClassContext, declarationProvider: ClassMemberDeclarationProvider,
@@ -142,6 +145,9 @@ interface SyntheticResolveExtension {
fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> = emptyList()
@JvmDefault
fun getSyntheticPropertiesNames(thisDescriptor: ClassDescriptor): List<Name> = emptyList()
fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> = emptyList()
/**
@@ -90,6 +90,7 @@ open class LazyClassMemberScope(
addDataClassMethods(result, location)
addSyntheticFunctions(result, location)
addSyntheticVariables(result, location)
addSyntheticCompanionObject(result, location)
addSyntheticNestedClasses(result, location)
@@ -106,6 +107,7 @@ open class LazyClassMemberScope(
by storageManager.createLazyValue {
mutableSetOf<Name>().apply {
addAll(declarationProvider.getDeclarationNames())
addAll(c.syntheticResolveExtension.getSyntheticPropertiesNames(thisDescriptor))
supertypes.flatMapTo(this) {
it.memberScope.getVariableNames()
}
@@ -344,6 +346,15 @@ open class LazyClassMemberScope(
}.toList())
}
private fun addSyntheticVariables(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
result.addAll(c.syntheticResolveExtension.getSyntheticPropertiesNames(thisDescriptor).flatMap {
getContributedVariables(
it,
location
)
}.toList())
}
private fun addSyntheticNestedClasses(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
result.addAll(c.syntheticResolveExtension.getSyntheticNestedClassNames(thisDescriptor).mapNotNull {
getContributedClassifier(
@@ -74,6 +74,9 @@
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
<args>
<arg>-Xjvm-default=enable</arg>
</args>
</configuration>
</plugin>
<plugin>