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