DeserializedPackageMemberScope uses kind and name filters

This commit is contained in:
Valentin Kipyatkov
2014-11-01 09:50:53 +03:00
parent ad9bb5c2a5
commit d744575000
3 changed files with 30 additions and 20 deletions
@@ -39,6 +39,7 @@ import org.jetbrains.jet.descriptors.serialization
import org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName
import org.jetbrains.jet.descriptors.serialization.classKind
import org.jetbrains.jet.utils.addIfNotNull
import org.jetbrains.jet.lang.resolve.scopes.JetScope
public fun DeserializedClassDescriptor(globalContext: DeserializationGlobalContext, classData: ClassData): DeserializedClassDescriptor
= DeserializedClassDescriptor(globalContext.withNameResolver(classData.getNameResolver()), classData.getClassProto())
@@ -180,6 +181,10 @@ public class DeserializedClassDescriptor(outerContext: DeserializationContext, p
private inner class DeserializedClassMemberScope : DeserializedMemberScope(context, this@DeserializedClassDescriptor.classProto.getMemberList()) {
private val classDescriptor: DeserializedClassDescriptor = this@DeserializedClassDescriptor
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors({ true }, { true }) }
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors()
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
val fromSupertypes = ArrayList<FunctionDescriptor>()
@@ -232,7 +237,7 @@ public class DeserializedClassDescriptor(outerContext: DeserializationContext, p
override fun getClassDescriptor(name: Name): ClassifierDescriptor? = classDescriptor.nestedClasses.findClass(name)
override fun addAllClassDescriptors(result: MutableCollection<DeclarationDescriptor>) {
override fun addClassDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
result.addAll(classDescriptor.nestedClasses.getAllDescriptors())
}
}
@@ -35,7 +35,6 @@ public abstract class DeserializedMemberScope protected(
private val membersProtos = context.storageManager.createLazyValue { groupByName(filteredMemberProtos(membersList)) }
private val functions = context.storageManager.createMemoizedFunction<Name, Collection<FunctionDescriptor>> { computeFunctions(it) }
private val properties = context.storageManager.createMemoizedFunction<Name, Collection<VariableDescriptor>> { computeProperties(it) }
private val allDescriptors = context.storageManager.createLazyValue { computeAllDescriptors() }
protected open fun filteredMemberProtos(allMemberProtos: Collection<ProtoBuf.Callable>): Collection<ProtoBuf.Callable> = allMemberProtos
@@ -92,7 +91,7 @@ public abstract class DeserializedMemberScope protected(
protected abstract fun getClassDescriptor(name: Name): ClassifierDescriptor?
protected abstract fun addAllClassDescriptors(result: MutableCollection<DeclarationDescriptor>)
protected abstract fun addClassDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
override fun getPackage(name: Name): PackageViewDescriptor? = null
@@ -102,26 +101,32 @@ public abstract class DeserializedMemberScope protected(
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
private fun computeAllDescriptors(): Collection<DeclarationDescriptor> {
protected fun computeDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
val result = LinkedHashSet<DeclarationDescriptor>(0)
for (name in membersProtos().keySet()) {
result.addAll(getFunctions(name))
result.addAll(getProperties(name))
if (nameFilter(name)) {
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
result.addAll(getFunctions(name))
}
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_PROPERTY) || kindFilter(JetScope.DescriptorKind.EXTENSION_PROPERTY)) {
result.addAll(getProperties(name))
}
}
}
addNonDeclaredDescriptors(result)
addAllClassDescriptors(result)
if (kindFilter(JetScope.DescriptorKind.CLASSIFIER)) {
addClassDescriptors(result, nameFilter)
}
return result.toReadOnlyList()
}
protected abstract fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>)
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors.invoke()
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
val receiver = getImplicitReceiver()
return if (receiver != null) listOf(receiver) else listOf()
@@ -19,14 +19,13 @@ package org.jetbrains.jet.descriptors.serialization.descriptors
import org.jetbrains.jet.descriptors.serialization.PackageData
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
import org.jetbrains.jet.descriptors.serialization.context.*
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
import org.jetbrains.jet.lang.resolve.name.ClassId
import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.name.Name
import org.jetbrains.jet.storage.NotNullLazyValue
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.utils.addIfNotNull
public fun DeserializedPackageMemberScope(packageDescriptor: PackageFragmentDescriptor,
@@ -43,16 +42,17 @@ public open class DeserializedPackageMemberScope(
: DeserializedMemberScope(context.withTypes(packageDescriptor), proto.getMemberList()) {
private val packageFqName = packageDescriptor.fqName
private val classNames = context.storageManager.createLazyValue<Collection<Name>>(classNames)
private val classNames = context.storageManager.createLazyValue(classNames)
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean)
= computeDescriptors(kindFilter, nameFilter)
override fun getClassDescriptor(name: Name) = context.deserializeClass(ClassId(packageFqName, name))
override fun addAllClassDescriptors(result: MutableCollection<DeclarationDescriptor>) {
for (className in classNames.invoke()) {
val classDescriptor = getClassDescriptor(className)
if (classDescriptor != null) {
result.add(classDescriptor)
override fun addClassDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) {
for (className in classNames()) {
if (nameFilter(className)) {
result.addIfNotNull(getClassDescriptor(className))
}
}
}