Minor. Refactor DeserializedMemberScope.addNonDeclaredDescriptors

This commit is contained in:
Denis Zharkov
2016-04-06 15:59:27 +03:00
parent f104be16cf
commit 137847e0c9
3 changed files with 18 additions and 15 deletions
@@ -226,17 +226,15 @@ class DeserializedClassDescriptor(
})
}
override fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
for (supertype in classDescriptor.getTypeConstructor().supertypes) {
for (descriptor in supertype.memberScope.getContributedDescriptors()) {
if (descriptor is FunctionDescriptor) {
result.addAll(getContributedFunctions(descriptor.name, location))
}
else if (descriptor is PropertyDescriptor) {
result.addAll(getContributedVariables(descriptor.name, location))
}
// Nothing else is inherited
}
override fun getNonDeclaredFunctionNames(location: LookupLocation): Set<Name> {
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
it.memberScope.getContributedDescriptors().filterIsInstance<SimpleFunctionDescriptor>().map { it.name }
}
}
override fun getNonDeclaredVariableNames(location: LookupLocation): Set<Name> {
return classDescriptor.typeConstructor.supertypes.flatMapTo(LinkedHashSet()) {
it.memberScope.getContributedDescriptors().filterIsInstance<PropertyDescriptor>().map { it.name }
}
}
@@ -165,7 +165,13 @@ abstract class DeserializedMemberScope protected constructor(
}
}
protected abstract fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation)
protected fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
result.addAll(getNonDeclaredFunctionNames(location).flatMap { getContributedFunctions(it, location) })
result.addAll(getNonDeclaredVariableNames(location).flatMap { getContributedVariables(it, location) })
}
protected abstract fun getNonDeclaredFunctionNames(location: LookupLocation): Set<Name>
protected abstract fun getNonDeclaredVariableNames(location: LookupLocation): Set<Name>
protected abstract fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
@@ -63,9 +63,8 @@ open class DeserializedPackageMemberScope(
}
}
override fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>, location: LookupLocation) {
// Do nothing
}
override fun getNonDeclaredFunctionNames(location: LookupLocation): Set<Name> = emptySet()
override fun getNonDeclaredVariableNames(location: LookupLocation): Set<Name> = emptySet()
override fun addEnumEntryDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
// Do nothing