Chained scope to not cache result of getDescriptors() but uses filters
This commit is contained in:
@@ -23,15 +23,11 @@ import org.jetbrains.jet.utils.Printer
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*
|
import org.jetbrains.jet.lang.resolve.scopes.JetScopeSelectorUtil.*
|
||||||
import kotlin.Collection
|
|
||||||
import kotlin.List
|
|
||||||
import kotlin.Set
|
|
||||||
|
|
||||||
public class ChainedScope(private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
|
public class ChainedScope(private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
|
||||||
private val debugName: String,
|
private val debugName: String,
|
||||||
vararg scopes: JetScope) : JetScope {
|
vararg scopes: JetScope) : JetScope {
|
||||||
private val scopeChain = scopes.clone()
|
private val scopeChain = scopes.clone()
|
||||||
private var _allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
|
||||||
private var implicitReceiverHierarchy: List<ReceiverParameterDescriptor>? = null
|
private var implicitReceiverHierarchy: List<ReceiverParameterDescriptor>? = null
|
||||||
|
|
||||||
override fun getClassifier(name: Name): ClassifierDescriptor?
|
override fun getClassifier(name: Name): ClassifierDescriptor?
|
||||||
@@ -74,13 +70,9 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
|
|||||||
|
|
||||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
if (_allDescriptors == null) {
|
val result = HashSet<DeclarationDescriptor>()
|
||||||
_allDescriptors = HashSet<DeclarationDescriptor>()
|
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||||
for (scope in scopeChain) {
|
return result
|
||||||
_allDescriptors!!.addAll(scope.getDescriptors())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _allDescriptors!!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
||||||
|
|||||||
Reference in New Issue
Block a user