Change return type of KtScope.getProperties()

This commit is contained in:
Stanislav Erokhin
2015-10-31 09:43:50 +03:00
parent 7cd667c0e3
commit 6412df2e0b
20 changed files with 43 additions and 49 deletions
@@ -1085,7 +1085,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
assert loopRangeType != null;
Type asmLoopRangeType = asmType(loopRangeType);
Collection<VariableDescriptor> incrementProp =
Collection<PropertyDescriptor> incrementProp =
loopRangeType.getMemberScope().getProperties(Name.identifier("increment"), NoLookupLocation.FROM_BACKEND);
assert incrementProp.size() == 1 : loopRangeType + " " + incrementProp.size();
incrementType = asmType(incrementProp.iterator().next().getType());
@@ -78,7 +78,7 @@ class DynamicCallableDescriptors(private val builtIns: KotlinBuiltIns) {
return false
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
return if (call.getValueArgumentList() == null && call.getValueArguments().isEmpty()) {
listOf(createDynamicProperty(owner, name, call))
}
@@ -17,10 +17,7 @@
package org.jetbrains.kotlin.resolve.lazy.descriptors
import com.google.common.collect.Sets
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.name.Name
@@ -51,7 +48,7 @@ protected constructor(
protected val storageManager: StorageManager = c.storageManager
private val classDescriptors: MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> = storageManager.createMemoizedFunction { resolveClassDescriptor(it) }
private val functionDescriptors: MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>> = storageManager.createMemoizedFunction { doGetFunctions(it) }
private val propertyDescriptors: MemoizedFunctionToNotNull<Name, Collection<VariableDescriptor>> = storageManager.createMemoizedFunction { doGetProperties(it) }
private val propertyDescriptors: MemoizedFunctionToNotNull<Name, Collection<PropertyDescriptor>> = storageManager.createMemoizedFunction { doGetProperties(it) }
private fun resolveClassDescriptor(name: Name): List<ClassDescriptor> {
return declarationProvider.getClassOrObjectDeclarations(name).map {
@@ -97,13 +94,13 @@ protected constructor(
protected abstract fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>)
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
recordLookup(name, location)
return propertyDescriptors(name)
}
public fun doGetProperties(name: Name): Collection<VariableDescriptor> {
val result = LinkedHashSet<VariableDescriptor>()
public fun doGetProperties(name: Name): Collection<PropertyDescriptor> {
val result = LinkedHashSet<PropertyDescriptor>()
val declarations = declarationProvider.getPropertyDeclarations(name)
for (propertyDeclaration in declarations) {
@@ -122,7 +119,7 @@ protected constructor(
return result.toReadOnlyList()
}
protected abstract fun getNonDeclaredProperties(name: Name, result: MutableSet<VariableDescriptor>)
protected abstract fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>)
protected fun computeDescriptorsFromDeclaredElements(
kindFilter: DescriptorKindFilter,
@@ -152,7 +152,7 @@ public open class LazyClassMemberScope(
val properties = getProperties(parameter.name, location)
if (properties.isEmpty()) continue
val property = properties.iterator().next() as PropertyDescriptor
val property = properties.iterator().next()
++componentIndex
@@ -175,7 +175,7 @@ public open class LazyClassMemberScope(
}
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
// TODO: this should be handled by lazy property descriptors
val properties = super.getProperties(name, location)
resolveUnknownVisibilitiesForMembers(properties as Collection<CallableMemberDescriptor>)
@@ -191,20 +191,19 @@ public open class LazyClassMemberScope(
}
}
@Suppress("UNCHECKED_CAST")
protected override fun getNonDeclaredProperties(name: Name, result: MutableSet<VariableDescriptor>) {
protected override fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>) {
createPropertiesFromPrimaryConstructorParameters(name, result)
// Members from supertypes
val fromSupertypes = ArrayList<PropertyDescriptor>()
for (supertype in thisDescriptor.typeConstructor.supertypes) {
fromSupertypes.addAll(supertype.memberScope.getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED) as Collection<PropertyDescriptor>)
fromSupertypes.addAll(supertype.memberScope.getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED))
}
result.addAll(generateDelegatingDescriptors(name, EXTRACT_PROPERTIES, result))
generateFakeOverrides(name, fromSupertypes, result as MutableCollection<PropertyDescriptor>, javaClass<PropertyDescriptor>())
generateFakeOverrides(name, fromSupertypes, result, javaClass<PropertyDescriptor>())
}
protected open fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<VariableDescriptor>) {
protected open fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<PropertyDescriptor>) {
val classInfo = declarationProvider.getOwnerInfo()
// From primary constructor parameters
@@ -322,8 +321,7 @@ public open class LazyClassMemberScope(
private val EXTRACT_PROPERTIES: MemberExtractor<PropertyDescriptor> = object : MemberExtractor<PropertyDescriptor> {
override fun extract(extractFrom: KotlinType, name: Name): Collection<PropertyDescriptor> {
@Suppress("UNCHECKED_CAST")
return extractFrom.memberScope.getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED) as Collection<PropertyDescriptor>
return extractFrom.memberScope.getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}
}
}
@@ -43,7 +43,7 @@ public class LazyPackageMemberScope(
// No extra functions
}
override fun getNonDeclaredProperties(name: Name, result: MutableSet<VariableDescriptor>) {
override fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>) {
// No extra properties
}
@@ -50,7 +50,7 @@ public class LazyScriptClassMemberScope protected constructor(
private fun getPropertiesForScriptParameters() = getPrimaryConstructor()!!.valueParameters.flatMap { getProperties(it.name, NoLookupLocation.FOR_SCRIPT) }
override fun getNonDeclaredProperties(name: Name, result: MutableSet<VariableDescriptor>) {
override fun getNonDeclaredProperties(name: Name, result: MutableSet<PropertyDescriptor>) {
super.getNonDeclaredProperties(name, result)
if (name.asString() == ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME) {
@@ -60,7 +60,7 @@ public class LazyScriptClassMemberScope protected constructor(
public fun getScriptResultProperty(): PropertyDescriptor = scriptResultProperty()
override fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<VariableDescriptor>) {
override fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet<PropertyDescriptor>) {
val scriptInfo = declarationProvider.getOwnerInfo() as JetScriptInfo
// From primary constructor parameters
@@ -186,11 +186,11 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinLite
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) {
Name propertyName = Name.identifier(name);
KtScope memberScope = packageView.getMemberScope();
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName, NoLookupLocation.FROM_TEST);
Collection<PropertyDescriptor> properties = memberScope.getProperties(propertyName, NoLookupLocation.FROM_TEST);
if (properties.isEmpty()) {
for (DeclarationDescriptor descriptor : memberScope.getAllDescriptors()) {
if (descriptor instanceof ClassDescriptor) {
Collection<VariableDescriptor> classProperties =
Collection<PropertyDescriptor> classProperties =
((ClassDescriptor) descriptor).getMemberScope(Collections.<TypeProjection>emptyList())
.getProperties(propertyName, NoLookupLocation.FROM_TEST);
if (!classProperties.isEmpty()) {
@@ -206,16 +206,16 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinLite
else if (properties.size() != 1) {
return null;
}
return (PropertyDescriptor) properties.iterator().next();
return properties.iterator().next();
}
@NotNull
private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name propertyName = Name.identifier(name);
KtScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<VariableDescriptor> properties = memberScope.getProperties(propertyName, NoLookupLocation.FROM_TEST);
Collection<PropertyDescriptor> properties = memberScope.getProperties(propertyName, NoLookupLocation.FROM_TEST);
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName();
return (PropertyDescriptor) properties.iterator().next();
return properties.iterator().next();
}
@NotNull
@@ -414,7 +414,7 @@ public class LazyJavaClassMemberScope(
private fun getPropertiesFromSupertypes(name: Name): Set<PropertyDescriptor> {
return getContainingDeclaration().typeConstructor.supertypes.flatMap {
it.memberScope.getProperties(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { p -> p as PropertyDescriptor }
it.memberScope.getProperties(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { p -> p }
}.toSet()
}
@@ -106,10 +106,11 @@ public class LazyJavaPackageScope(
return classes(name)
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
recordLookup(name, location)
return deserializedPackageScope().getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}
override fun getFunctions(name: Name, location: LookupLocation): List<FunctionDescriptor> {
recordLookup(name, location)
return deserializedPackageScope().getFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED) + super.getFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)
@@ -298,7 +298,7 @@ public abstract class LazyJavaScope(
return propertyType
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
recordLookup(name, location)
return properties(name)
}
@@ -122,7 +122,7 @@ public class LazyJavaStaticClassScope(
if (staticScope !is LazyJavaStaticClassScope) return getStaticPropertiesFromJavaSupertypes(name, superTypeDescriptor)
return staticScope.getProperties(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { it as PropertyDescriptor }
return staticScope.getProperties(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { it }
}
return descriptor.typeConstructor.supertypes.flatMap(::getStaticProperties).toSet()
@@ -52,7 +52,7 @@ class FunctionClassScope(
return allDescriptors().filterIsInstance<FunctionDescriptor>().filter { it.getName() == name }
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
return allDescriptors().filterIsInstance<PropertyDescriptor>().filter { it.getName() == name }
}
@@ -201,9 +201,8 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
@NotNull
@Override
@SuppressWarnings("unchecked")
public Collection<VariableDescriptor> getProperties(@NotNull Name name, @NotNull LookupLocation location) {
return (Collection) properties.invoke(name);
public Collection<PropertyDescriptor> getProperties(@NotNull Name name, @NotNull LookupLocation location) {
return properties.invoke(name);
}
@NotNull
@@ -45,7 +45,7 @@ public abstract class AbstractScopeAdapter : KtScope {
return workerScope.getClassifier(name, location)
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
return workerScope.getProperties(name, location)
}
@@ -36,7 +36,7 @@ public open class ChainedScope(
override fun getPackage(name: Name): PackageViewDescriptor?
= getFirstMatch(scopeChain) { it.getPackage(name) }
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor>
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor>
= getFromAllScopes(scopeChain) { it.getProperties(name, location) }
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
@@ -30,7 +30,7 @@ public interface KtScope {
@Deprecated("Should be removed soon")
public fun getPackage(name: Name): PackageViewDescriptor?
public fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor>
public fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor>
public fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.utils.Printer
abstract class KtScopeImpl : KtScope {
override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> = emptyList()
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
override fun getPackage(name: Name): PackageViewDescriptor? = null
@@ -175,8 +175,8 @@ public class ErrorUtils {
@NotNull
@Override
public Set<VariableDescriptor> getProperties(@NotNull Name name, @NotNull LookupLocation location) {
return ERROR_VARIABLE_GROUP;
public Set<PropertyDescriptor> getProperties(@NotNull Name name, @NotNull LookupLocation location) {
return ERROR_PROPERTY_GROUP;
}
@Override
@@ -248,7 +248,7 @@ public class ErrorUtils {
@NotNull
@Override
public Collection<VariableDescriptor> getProperties(@NotNull Name name, @NotNull LookupLocation location) {
public Collection<PropertyDescriptor> getProperties(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException();
}
@@ -361,7 +361,7 @@ public class ErrorUtils {
private static final KotlinType ERROR_PROPERTY_TYPE = createErrorType("<ERROR PROPERTY TYPE>");
private static final PropertyDescriptor ERROR_PROPERTY = createErrorProperty();
private static final Set<VariableDescriptor> ERROR_VARIABLE_GROUP = Collections.<VariableDescriptor>singleton(ERROR_PROPERTY);
private static final Set<PropertyDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
@NotNull
private static PropertyDescriptorImpl createErrorProperty() {
@@ -206,8 +206,7 @@ public class DeserializedClassDescriptor(
override fun computeNonDeclaredProperties(name: Name, descriptors: MutableCollection<PropertyDescriptor>) {
val fromSupertypes = ArrayList<PropertyDescriptor>()
for (supertype in classDescriptor.getTypeConstructor().supertypes) {
@Suppress("UNCHECKED_CAST")
fromSupertypes.addAll(supertype.memberScope.getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED) as Collection<PropertyDescriptor>)
fromSupertypes.addAll(supertype.memberScope.getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED))
}
generateFakeOverrides(name, fromSupertypes, descriptors)
}
@@ -50,7 +50,7 @@ public abstract class DeserializedMemberScope protected constructor(
private val functions =
c.storageManager.createMemoizedFunction<Name, Collection<FunctionDescriptor>> { computeFunctions(it) }
private val properties =
c.storageManager.createMemoizedFunction<Name, Collection<VariableDescriptor>> { computeProperties(it) }
c.storageManager.createMemoizedFunction<Name, Collection<PropertyDescriptor>> { computeProperties(it) }
protected open fun filteredFunctionProtos(protos: Collection<ProtoBuf.Function>): Collection<ProtoBuf.Function> = protos
@@ -87,7 +87,7 @@ public abstract class DeserializedMemberScope protected constructor(
return functions(name)
}
private fun computeProperties(name: Name): Collection<VariableDescriptor> {
private fun computeProperties(name: Name): Collection<PropertyDescriptor> {
val protos = propertyProtos()[ProtoKey(name, isExtension = false)].orEmpty() +
propertyProtos()[ProtoKey(name, isExtension = true)].orEmpty()
@@ -102,7 +102,7 @@ public abstract class DeserializedMemberScope protected constructor(
protected open fun computeNonDeclaredProperties(name: Name, descriptors: MutableCollection<PropertyDescriptor>) {
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
override fun getProperties(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
recordLookup(name, location)
return properties.invoke(name)
}