Minor: use List instead of Array as container in chained scopes

This commit is contained in:
Zalim Bashorov
2015-12-15 18:41:04 +03:00
parent 5008a66a5b
commit 976fbf32ba
12 changed files with 36 additions and 35 deletions
@@ -108,7 +108,7 @@ public final class DeserializedDescriptorResolver {
if (list.isEmpty()) {
return MemberScope.Empty.INSTANCE;
}
return new ChainedMemberScope("Member scope for union of package parts data", list.toArray(new MemberScope[list.size()]));
return new ChainedMemberScope("Member scope for union of package parts data", list);
}
@Nullable
@@ -23,8 +23,8 @@ import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue
import org.jetbrains.kotlin.types.TypeSubstitutor
@@ -46,7 +46,7 @@ public class LazyPackageViewDescriptorImpl(
else {
// Packages from SubpackagesScope are got via getContributedDescriptors(DescriptorKindFilter.PACKAGES, MemberScope.ALL_NAME_FILTER)
val scopes = fragments.map { it.getMemberScope() } + SubpackagesScope(module, fqName)
ChainedMemberScope("package view scope for $fqName in ${module.getName()}", *scopes.toTypedArray())
ChainedMemberScope("package view scope for $fqName in ${module.name}", scopes)
}
})
@@ -27,21 +27,19 @@ import org.jetbrains.kotlin.utils.Printer
public class ChainedMemberScope(
internal val debugName: String,
vararg scopes: MemberScope
private val scopes: List<MemberScope>
) : MemberScope {
private val scopeChain = scopes.clone()
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
= getFirstMatch(scopeChain) { it.getContributedClassifier(name, location) }
= getFirstMatch(scopes) { it.getContributedClassifier(name, location) }
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor>
= getFromAllScopes(scopeChain) { it.getContributedVariables(name, location) }
= getFromAllScopes(scopes) { it.getContributedVariables(name, location) }
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
= getFromAllScopes(scopeChain) { it.getContributedFunctions(name, location) }
= getFromAllScopes(scopes) { it.getContributedFunctions(name, location) }
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= getFromAllScopes(scopeChain) { it.getContributedDescriptors(kindFilter, nameFilter) }
= getFromAllScopes(scopes) { it.getContributedDescriptors(kindFilter, nameFilter) }
override fun toString() = debugName
@@ -49,7 +47,7 @@ public class ChainedMemberScope(
p.println(javaClass.getSimpleName(), ": ", debugName, " {")
p.pushIndent()
for (scope in scopeChain) {
for (scope in scopes) {
scope.printScopeStructure(p)
}
@@ -46,7 +46,7 @@ class TypeIntersectionScope private constructor(override val workerScope: Chaine
companion object {
@JvmStatic
fun create(message: String, types: List<KotlinType>): MemberScope {
val chainedScope = ChainedMemberScope(message, *types.map { it.memberScope }.toTypedArray())
val chainedScope = ChainedMemberScope(message, types.map { it.memberScope })
if (types.size <= 1) return chainedScope
return TypeIntersectionScope(chainedScope)
@@ -53,7 +53,7 @@ public fun <T> concatInOrder(c1: Collection<T>?, c2: Collection<T>?): Collection
return result ?: emptySet()
}
public inline fun <Scope, T> getFromAllScopes(scopes: Array<out Scope>, callback: (Scope) -> Collection<T>): Collection<T> {
public inline fun <Scope, T> getFromAllScopes(scopes: List<Scope>, callback: (Scope) -> Collection<T>): Collection<T> {
if (scopes.isEmpty()) return emptySet()
var result: Collection<T>? = null
for (scope in scopes) {
@@ -62,11 +62,11 @@ public inline fun <Scope, T> getFromAllScopes(scopes: Array<out Scope>, callback
return result ?: emptySet()
}
public inline fun <Scope, T : Any> getFirstMatch(scopes: Array<out Scope>, callback: (Scope) -> T?): T? {
public inline fun <Scope, T : Any> getFirstMatch(scopes: List<Scope>, callback: (Scope) -> T?): T? {
// NOTE: This is performance-sensitive; please don't replace with map().firstOrNull()
for (scope in scopes) {
val result = callback(scope)
if (result != null) return result
}
return null
}
}