Reformat SyntheticJavaPropertiesScope.kt

This commit is contained in:
Denis Zharkov
2018-07-03 14:16:46 +03:00
parent fc93f00c7b
commit 5e6a3673c8
@@ -69,20 +69,24 @@ interface SyntheticJavaPropertyDescriptor : PropertyDescriptor {
override val scopes: Collection<SyntheticScope> = listOf(syntheticScope) override val scopes: Collection<SyntheticScope> = listOf(syntheticScope)
}) })
fun propertyNameByGetMethodName(methodName: Name): Name? fun propertyNameByGetMethodName(methodName: Name): Name? = org.jetbrains.kotlin.load.java.propertyNameByGetMethodName(methodName)
= org.jetbrains.kotlin.load.java.propertyNameByGetMethodName(methodName)
fun propertyNameBySetMethodName(methodName: Name, withIsPrefix: Boolean): Name? fun propertyNameBySetMethodName(methodName: Name, withIsPrefix: Boolean): Name? =
= org.jetbrains.kotlin.load.java.propertyNameBySetMethodName(methodName, withIsPrefix) org.jetbrains.kotlin.load.java.propertyNameBySetMethodName(methodName, withIsPrefix)
} }
} }
class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : SyntheticScope { class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val lookupTracker: LookupTracker) : SyntheticScope {
private val syntheticPropertyInClass = storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair -> private val syntheticPropertyInClass =
storageManager.createMemoizedFunction<Pair<ClassDescriptor, Name>, SyntheticPropertyHolder> { pair ->
syntheticPropertyInClassNotCached(pair.first, pair.second) syntheticPropertyInClassNotCached(pair.first, pair.second)
} }
private fun getSyntheticPropertyAndRecordLookups(classifier: ClassDescriptor, name: Name, location: LookupLocation): PropertyDescriptor? { private fun getSyntheticPropertyAndRecordLookups(
classifier: ClassDescriptor,
name: Name,
location: LookupLocation
): PropertyDescriptor? {
val (descriptor, lookedNames) = syntheticPropertyInClass(Pair(classifier, name)) val (descriptor, lookedNames) = syntheticPropertyInClass(Pair(classifier, name))
if (location !is NoLookupLocation) { if (location !is NoLookupLocation) {
@@ -168,7 +172,11 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return null return null
} }
override fun getSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<PropertyDescriptor> { override fun getSyntheticExtensionProperties(
receiverTypes: Collection<KotlinType>,
name: Name,
location: LookupLocation
): Collection<PropertyDescriptor> {
var result: SmartList<PropertyDescriptor>? = null var result: SmartList<PropertyDescriptor>? = null
val processedTypes: MutableSet<TypeConstructor>? = if (receiverTypes.size > 1) HashSet<TypeConstructor>() else null val processedTypes: MutableSet<TypeConstructor>? = if (receiverTypes.size > 1) HashSet<TypeConstructor>() else null
for (type in receiverTypes) { for (type in receiverTypes) {
@@ -181,22 +189,25 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
} }
} }
override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> override fun getSyntheticStaticFunctions(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> =
= emptyList() emptyList()
override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> override fun getSyntheticConstructors(scope: ResolutionScope, name: Name, location: LookupLocation): Collection<FunctionDescriptor> =
= emptyList() emptyList()
override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection<FunctionDescriptor> override fun getSyntheticStaticFunctions(scope: ResolutionScope): Collection<FunctionDescriptor> = emptyList()
= emptyList()
override fun getSyntheticConstructors(scope: ResolutionScope): Collection<FunctionDescriptor> override fun getSyntheticConstructors(scope: ResolutionScope): Collection<FunctionDescriptor> = emptyList()
= emptyList()
override fun getSyntheticConstructor(constructor: ConstructorDescriptor): ConstructorDescriptor? override fun getSyntheticConstructor(constructor: ConstructorDescriptor): ConstructorDescriptor? = null
= null
private fun collectSyntheticPropertiesByName(result: SmartList<PropertyDescriptor>?, type: TypeConstructor, name: Name, processedTypes: MutableSet<TypeConstructor>?, location: LookupLocation): SmartList<PropertyDescriptor>? { private fun collectSyntheticPropertiesByName(
result: SmartList<PropertyDescriptor>?,
type: TypeConstructor,
name: Name,
processedTypes: MutableSet<TypeConstructor>?,
location: LookupLocation
): SmartList<PropertyDescriptor>? {
if (processedTypes != null && !processedTypes.add(type)) return result if (processedTypes != null && !processedTypes.add(type)) return result
@Suppress("NAME_SHADOWING") @Suppress("NAME_SHADOWING")
@@ -205,8 +216,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
val classifier = type.declarationDescriptor val classifier = type.declarationDescriptor
if (classifier is ClassDescriptor) { if (classifier is ClassDescriptor) {
result = result.add(getSyntheticPropertyAndRecordLookups(classifier, name, location)) result = result.add(getSyntheticPropertyAndRecordLookups(classifier, name, location))
} } else {
else {
type.supertypes.forEach { result = collectSyntheticPropertiesByName(result, it.constructor, name, processedTypes, location) } type.supertypes.forEach { result = collectSyntheticPropertiesByName(result, it.constructor, name, processedTypes, location) }
} }
@@ -220,7 +230,10 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return result return result
} }
private fun MutableList<PropertyDescriptor>.collectSyntheticProperties(type: TypeConstructor, processedTypes: MutableSet<TypeConstructor>) { private fun MutableList<PropertyDescriptor>.collectSyntheticProperties(
type: TypeConstructor,
processedTypes: MutableSet<TypeConstructor>
) {
if (!processedTypes.add(type)) return if (!processedTypes.add(type)) return
val classifier = type.declarationDescriptor val classifier = type.declarationDescriptor
@@ -231,8 +244,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
addIfNotNull(syntheticPropertyInClass(Pair(classifier, propertyName)).descriptor) addIfNotNull(syntheticPropertyInClass(Pair(classifier, propertyName)).descriptor)
} }
} }
} } else {
else {
type.supertypes.forEach { collectSyntheticProperties(it.constructor, processedTypes) } type.supertypes.forEach { collectSyntheticProperties(it.constructor, processedTypes) }
} }
} }
@@ -244,7 +256,12 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
return list return list
} }
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList() override fun getSyntheticMemberFunctions(
receiverTypes: Collection<KotlinType>,
name: Name,
location: LookupLocation
): Collection<FunctionDescriptor> = emptyList()
override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList() override fun getSyntheticMemberFunctions(receiverTypes: Collection<KotlinType>): Collection<FunctionDescriptor> = emptyList()
private data class SyntheticPropertyHolder(val descriptor: PropertyDescriptor?, val lookedNames: List<Name>) { private data class SyntheticPropertyHolder(val descriptor: PropertyDescriptor?, val lookedNames: List<Name>) {
@@ -276,9 +293,16 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
private set private set
companion object { companion object {
fun create(ownerClass: ClassDescriptor, getMethod: FunctionDescriptor, setMethod: FunctionDescriptor?, name: Name, type: KotlinType): MyPropertyDescriptor { fun create(
ownerClass: ClassDescriptor,
getMethod: FunctionDescriptor,
setMethod: FunctionDescriptor?,
name: Name,
type: KotlinType
): MyPropertyDescriptor {
val visibility = syntheticVisibility(getMethod, isUsedForExtension = true) val visibility = syntheticVisibility(getMethod, isUsedForExtension = true)
val descriptor = MyPropertyDescriptor(DescriptorUtils.getContainingModule(ownerClass), val descriptor = MyPropertyDescriptor(
DescriptorUtils.getContainingModule(ownerClass),
null, null,
Annotations.EMPTY, Annotations.EMPTY,
Modality.FINAL, Modality.FINAL,
@@ -286,19 +310,22 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
setMethod != null, setMethod != null,
name, name,
CallableMemberDescriptor.Kind.SYNTHESIZED, CallableMemberDescriptor.Kind.SYNTHESIZED,
SourceElement.NO_SOURCE) SourceElement.NO_SOURCE
)
descriptor.getMethod = getMethod descriptor.getMethod = getMethod
descriptor.setMethod = setMethod descriptor.setMethod = setMethod
val classTypeParams = ownerClass.typeConstructor.parameters val classTypeParams = ownerClass.typeConstructor.parameters
val typeParameters = ArrayList<TypeParameterDescriptor>(classTypeParams.size) val typeParameters = ArrayList<TypeParameterDescriptor>(classTypeParams.size)
val typeSubstitutor = DescriptorSubstitutor.substituteTypeParameters(classTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters) val typeSubstitutor =
DescriptorSubstitutor.substituteTypeParameters(classTypeParams, TypeSubstitution.EMPTY, descriptor, typeParameters)
val propertyType = typeSubstitutor.safeSubstitute(type, Variance.INVARIANT) val propertyType = typeSubstitutor.safeSubstitute(type, Variance.INVARIANT)
val receiverType = typeSubstitutor.safeSubstitute(ownerClass.defaultType, Variance.INVARIANT) val receiverType = typeSubstitutor.safeSubstitute(ownerClass.defaultType, Variance.INVARIANT)
descriptor.setType(propertyType, typeParameters, null, receiverType) descriptor.setType(propertyType, typeParameters, null, receiverType)
val getter = PropertyGetterDescriptorImpl(descriptor, val getter = PropertyGetterDescriptorImpl(
descriptor,
getMethod.annotations, getMethod.annotations,
Modality.FINAL, Modality.FINAL,
visibility, visibility,
@@ -307,11 +334,13 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
false, false,
CallableMemberDescriptor.Kind.SYNTHESIZED, CallableMemberDescriptor.Kind.SYNTHESIZED,
null, null,
SourceElement.NO_SOURCE) SourceElement.NO_SOURCE
)
getter.initialize(null) getter.initialize(null)
val setter = if (setMethod != null) val setter = if (setMethod != null)
PropertySetterDescriptorImpl(descriptor, PropertySetterDescriptorImpl(
descriptor,
setMethod.annotations, setMethod.annotations,
Modality.FINAL, Modality.FINAL,
syntheticVisibility(setMethod, isUsedForExtension = true), syntheticVisibility(setMethod, isUsedForExtension = true),
@@ -320,7 +349,8 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
false, false,
CallableMemberDescriptor.Kind.SYNTHESIZED, CallableMemberDescriptor.Kind.SYNTHESIZED,
null, null,
SourceElement.NO_SOURCE) SourceElement.NO_SOURCE
)
else else
null null
setter?.initializeDefault() setter?.initializeDefault()