Refactored WritableScopeImpl to not cache result of getDescriptors() but use filters
This commit is contained in:
@@ -23,10 +23,6 @@ import org.jetbrains.jet.lang.types.checker.JetTypeChecker
|
||||
import org.jetbrains.jet.utils.Printer
|
||||
|
||||
import java.util.*
|
||||
import kotlin.Collection
|
||||
import kotlin.Map
|
||||
import kotlin.List
|
||||
import kotlin.Set
|
||||
|
||||
// Reads from:
|
||||
// 1. Maps
|
||||
@@ -41,9 +37,8 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
debugName: String)
|
||||
: WritableScopeWithImports(scope, redeclarationHandler, debugName) {
|
||||
|
||||
private val allDescriptors = ArrayList<DeclarationDescriptor>()
|
||||
private val explicitlyAddedDescriptors = ArrayList<DeclarationDescriptor>()
|
||||
private val declaredDescriptorsAccessibleBySimpleName = HashMultimap.create<Name, DeclarationDescriptor>()
|
||||
private var allDescriptorsDone = false
|
||||
|
||||
private var functionGroups: SetMultimap<Name, FunctionDescriptor>? = null
|
||||
|
||||
@@ -67,14 +62,14 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
override fun importClassifierAlias(importedClassifierName: Name, classifierDescriptor: ClassifierDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
allDescriptors.add(classifierDescriptor)
|
||||
explicitlyAddedDescriptors.add(classifierDescriptor)
|
||||
super.importClassifierAlias(importedClassifierName, classifierDescriptor)
|
||||
}
|
||||
|
||||
override fun importPackageAlias(aliasName: Name, packageView: PackageViewDescriptor) {
|
||||
checkMayWrite()
|
||||
|
||||
allDescriptors.add(packageView)
|
||||
explicitlyAddedDescriptors.add(packageView)
|
||||
super.importPackageAlias(aliasName, packageView)
|
||||
}
|
||||
|
||||
@@ -102,19 +97,13 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
changeLockLevel(WritableScope.LockLevel.READING)
|
||||
|
||||
if (!allDescriptorsDone) {
|
||||
allDescriptorsDone = true
|
||||
|
||||
// make sure no descriptors added to allDescriptors collection
|
||||
changeLockLevel(WritableScope.LockLevel.READING)
|
||||
|
||||
allDescriptors.addAll(workerScope.getDescriptors())
|
||||
for (imported in getImports()) {
|
||||
allDescriptors.addAll(imported.getDescriptors())
|
||||
}
|
||||
}
|
||||
return allDescriptors
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
result.addAll(explicitlyAddedDescriptors)
|
||||
result.addAll(workerScope.getDescriptors(kindFilter, nameFilter))
|
||||
getImports().flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getLabelsToDescriptors(): MutableMap<Name, MutableList<DeclarationDescriptor>> {
|
||||
@@ -182,7 +171,7 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
// TODO : Should this always happen?
|
||||
getVariableOrClassDescriptors().put(name, variableDescriptor)
|
||||
}
|
||||
allDescriptors.add(variableDescriptor)
|
||||
explicitlyAddedDescriptors.add(variableDescriptor)
|
||||
addToDeclared(variableDescriptor)
|
||||
}
|
||||
|
||||
@@ -227,7 +216,7 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
checkMayWrite()
|
||||
|
||||
getFunctionGroups().put(functionDescriptor.getName(), functionDescriptor)
|
||||
allDescriptors.add(functionDescriptor)
|
||||
explicitlyAddedDescriptors.add(functionDescriptor)
|
||||
}
|
||||
|
||||
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
@@ -259,7 +248,7 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
|
||||
checkForRedeclaration(name, classifierDescriptor)
|
||||
getVariableOrClassDescriptors().put(name, classifierDescriptor)
|
||||
allDescriptors.add(classifierDescriptor)
|
||||
explicitlyAddedDescriptors.add(classifierDescriptor)
|
||||
addToDeclared(classifierDescriptor)
|
||||
}
|
||||
|
||||
@@ -268,7 +257,7 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
|
||||
checkForRedeclaration(name, packageView)
|
||||
getPackageAliases().put(name, packageView)
|
||||
allDescriptors.add(packageView)
|
||||
explicitlyAddedDescriptors.add(packageView)
|
||||
addToDeclared(packageView)
|
||||
}
|
||||
|
||||
@@ -277,7 +266,7 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
|
||||
checkForRedeclaration(name, functionDescriptor)
|
||||
getFunctionGroups().put(name, functionDescriptor)
|
||||
allDescriptors.add(functionDescriptor)
|
||||
explicitlyAddedDescriptors.add(functionDescriptor)
|
||||
}
|
||||
|
||||
override fun addVariableAlias(name: Name, variableDescriptor: VariableDescriptor) {
|
||||
@@ -288,7 +277,7 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
getVariableOrClassDescriptors().put(name, variableDescriptor)
|
||||
getPropertyGroups().put(name, variableDescriptor)
|
||||
|
||||
allDescriptors.add(variableDescriptor)
|
||||
explicitlyAddedDescriptors.add(variableDescriptor)
|
||||
addToDeclared(variableDescriptor)
|
||||
}
|
||||
|
||||
@@ -355,6 +344,5 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
= declaredDescriptorsAccessibleBySimpleName.values()
|
||||
|
||||
override fun printAdditionalScopeStructure(p: Printer) {
|
||||
p.println("allDescriptorsDone = ", allDescriptorsDone)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user