Add missing definitelyDoesNotContainName methods
This commit is contained in:
committed by
Ilya Chernikov
parent
573c60ed6b
commit
8c2baf0704
+15
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
|
||||
import java.util.*
|
||||
|
||||
//----------------------------------------------------------------
|
||||
@@ -43,6 +44,13 @@ interface SyntheticResolveExtension {
|
||||
override fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> =
|
||||
instances.flatMap { withLinkageErrorLogger(it) { getSyntheticNestedClassNames(thisDescriptor) } }
|
||||
|
||||
override fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? =
|
||||
instances.flatMapToNullable(ArrayList<Name>()) {
|
||||
withLinkageErrorLogger(it) {
|
||||
getPossibleSyntheticNestedClassNames(thisDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> =
|
||||
instances.flatMap { withLinkageErrorLogger(it) { getSyntheticFunctionNames(thisDescriptor) } }
|
||||
|
||||
@@ -136,6 +144,13 @@ interface SyntheticResolveExtension {
|
||||
|
||||
fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> = emptyList()
|
||||
|
||||
/**
|
||||
* This method should return either superset of what [getSyntheticNestedClassNames] returns,
|
||||
* or null in case it needs to run resolution and inference and/or it is very costly.
|
||||
* Override this method if resolution started to fail with recursion.
|
||||
*/
|
||||
fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? = getSyntheticNestedClassNames(thisDescriptor)
|
||||
|
||||
fun addSyntheticSupertypes(thisDescriptor: ClassDescriptor, supertypes: MutableList<KotlinType>) {}
|
||||
|
||||
fun generateSyntheticClasses(
|
||||
|
||||
+35
-2
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
|
||||
import java.util.*
|
||||
|
||||
open class LazyClassMemberScope(
|
||||
@@ -102,7 +103,7 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
|
||||
private val _variableNames: MutableSet<Name>
|
||||
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
by storageManager.createLazyValue {
|
||||
mutableSetOf<Name>().apply {
|
||||
addAll(declarationProvider.getDeclarationNames())
|
||||
supertypes.flatMapTo(this) {
|
||||
@@ -112,9 +113,10 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
|
||||
private val _functionNames: MutableSet<Name>
|
||||
by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
by storageManager.createLazyValue {
|
||||
mutableSetOf<Name>().apply {
|
||||
addAll(declarationProvider.getDeclarationNames())
|
||||
addAll(c.syntheticResolveExtension.getSyntheticFunctionNames(thisDescriptor))
|
||||
supertypes.flatMapTo(this) {
|
||||
it.memberScope.getFunctionNames()
|
||||
}
|
||||
@@ -123,6 +125,32 @@ open class LazyClassMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
private val _classifierNames: Set<Name>?
|
||||
by storageManager.createNullableLazyValue {
|
||||
mutableSetOf<Name>().apply {
|
||||
supertypes.flatMapToNullable(this) {
|
||||
it.memberScope.getClassifierNames()
|
||||
} ?: return@createNullableLazyValue null
|
||||
|
||||
addAll(declarationProvider.getDeclarationNames())
|
||||
with(c.syntheticResolveExtension) {
|
||||
getPossibleSyntheticNestedClassNames(thisDescriptor)?.let { addAll(it) } ?: return@createNullableLazyValue null
|
||||
getSyntheticCompanionObjectNameIfNeeded(thisDescriptor)?.let { add(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val _allNames: Set<Name>?
|
||||
by storageManager.createNullableLazyValue {
|
||||
val classifiers = getClassifierNames() ?: return@createNullableLazyValue null
|
||||
|
||||
mutableSetOf<Name>().apply {
|
||||
addAll(getVariableNames())
|
||||
addAll(getFunctionNames())
|
||||
addAll(classifiers)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDataClassRelatedFunctionNames(): Collection<Name> {
|
||||
val declarations = mutableListOf<DeclarationDescriptor>()
|
||||
addDataClassMethods(declarations, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS)
|
||||
@@ -131,6 +159,11 @@ open class LazyClassMemberScope(
|
||||
|
||||
override fun getVariableNames() = _variableNames
|
||||
override fun getFunctionNames() = _functionNames
|
||||
override fun getClassifierNames() = _classifierNames
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
||||
return _allNames?.let { name !in it } ?: false
|
||||
}
|
||||
|
||||
private interface MemberExtractor<out T : CallableMemberDescriptor> {
|
||||
fun extract(extractFrom: KotlinType, name: Name): Collection<T>
|
||||
|
||||
@@ -46,6 +46,8 @@ interface MemberScope : ResolutionScope {
|
||||
p.println("Empty member scope")
|
||||
}
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name): Boolean = true
|
||||
|
||||
override fun getFunctionNames() = emptySet<Name>()
|
||||
override fun getVariableNames() = emptySet<Name>()
|
||||
override fun getClassifierNames() = emptySet<Name>()
|
||||
|
||||
+4
@@ -42,6 +42,10 @@ open class SerializationResolveExtension : SyntheticResolveExtension {
|
||||
else -> listOf()
|
||||
}
|
||||
|
||||
override fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? {
|
||||
return listOf(SerialEntityNames.IMPL_NAME, SerialEntityNames.SERIALIZER_CLASS_NAME)
|
||||
}
|
||||
|
||||
override fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> = when {
|
||||
thisDescriptor.isSerializableObject || thisDescriptor.isCompanionObject && getSerializableClassDescriptorByCompanion(thisDescriptor) != null ->
|
||||
listOf(SerialEntityNames.SERIALIZER_PROVIDER_NAME)
|
||||
|
||||
+5
@@ -33,6 +33,11 @@ public class SerializationPluginDiagnosticTestGenerated extends AbstractSerializ
|
||||
runTest("plugins/kotlin-serialization/kotlin-serialization-compiler/testData/diagnostics/DuplicateSerialName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("LazyRecursionBug.kt")
|
||||
public void testLazyRecursionBug() throws Exception {
|
||||
runTest("plugins/kotlin-serialization/kotlin-serialization-compiler/testData/diagnostics/LazyRecursionBug.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("NoSuitableCtorInParent.kt")
|
||||
public void testNoSuitableCtorInParent() throws Exception {
|
||||
runTest("plugins/kotlin-serialization/kotlin-serialization-compiler/testData/diagnostics/NoSuitableCtorInParent.kt");
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// This test enshures that analysis ends up without compiler exceptions
|
||||
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
class Digest() {
|
||||
@Serializer(forClass = Digest::class)
|
||||
companion object : KSerializer<Digest> {}
|
||||
}
|
||||
plugins/kotlin-serialization/kotlin-serialization-compiler/testData/diagnostics/LazyRecursionBug.txt
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
@kotlinx.serialization.Serializable public final class Digest {
|
||||
public constructor Digest()
|
||||
@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "This synthesized declaration should not be used directly", replaceWith = kotlin.ReplaceWith(expression = "", imports = {})) public /*synthesized*/ constructor Digest(/*0*/ seen1: kotlin.Int, /*1*/ serializationConstructorMarker: kotlinx.serialization.SerializationConstructorMarker?)
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
@kotlinx.serialization.Serializer(forClass = Digest::class) public companion object Companion : kotlinx.serialization.KSerializer<Digest> {
|
||||
private constructor Companion()
|
||||
public open override /*1*/ /*synthesized*/ val descriptor: kotlinx.serialization.SerialDescriptor
|
||||
public open override /*1*/ /*synthesized*/ fun deserialize(/*0*/ decoder: kotlinx.serialization.Decoder): Digest
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Patch function is deprecated for removal since this functionality is no longer supported by serializer.Some formats may provide implementation-specific patching in their Decoders.") public open override /*1*/ /*fake_override*/ fun patch(/*0*/ decoder: kotlinx.serialization.Decoder, /*1*/ old: Digest): Digest
|
||||
public open override /*1*/ /*synthesized*/ fun serialize(/*0*/ encoder: kotlinx.serialization.Encoder, /*1*/ value: Digest): kotlin.Unit
|
||||
public final /*synthesized*/ fun serializer(): kotlinx.serialization.KSerializer<Digest>
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+6
@@ -21,6 +21,12 @@ class SerializationIDEResolveExtension : SerializationResolveExtension() {
|
||||
override fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> =
|
||||
getIfEnabledOn(thisDescriptor) { super.getSyntheticNestedClassNames(thisDescriptor) } ?: emptyList()
|
||||
|
||||
override fun getPossibleSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name>? {
|
||||
val enabled = getIfEnabledOn(thisDescriptor) { true } ?: false
|
||||
return if (enabled) super.getPossibleSyntheticNestedClassNames(thisDescriptor)
|
||||
else emptyList()
|
||||
}
|
||||
|
||||
override fun getSyntheticFunctionNames(thisDescriptor: ClassDescriptor): List<Name> =
|
||||
getIfEnabledOn(thisDescriptor) { super.getSyntheticFunctionNames(thisDescriptor) } ?: emptyList()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user