Added JetScope.getSyntheticExtensionProperties()

This commit is contained in:
Valentin Kipyatkov
2015-07-06 19:38:25 +03:00
parent e2fa9397c8
commit c92b43c94b
15 changed files with 86 additions and 19 deletions
@@ -18,13 +18,11 @@ package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
import org.jetbrains.kotlin.resolve.scopes.FilteringScope
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.WritableScope
import java.util.ArrayList
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import java.util.ArrayList
class AllUnderImportsScope : JetScope { class AllUnderImportsScope : JetScope {
private val scopes = ArrayList<JetScope>() private val scopes = ArrayList<JetScope>()
@@ -55,6 +53,10 @@ class AllUnderImportsScope : JetScope {
return scopes.flatMap { it.getFunctions(name) } return scopes.flatMap { it.getFunctions(name) }
} }
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> {
return scopes.flatMap { it.getSyntheticExtensionProperties(receiverType, name) }
}
override fun getPackage(name: Name): PackageViewDescriptor? = null // packages are not imported by all under imports override fun getPackage(name: Name): PackageViewDescriptor? = null // packages are not imported by all under imports
override fun getLocalVariable(name: Name): VariableDescriptor? = null override fun getLocalVariable(name: Name): VariableDescriptor? = null
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
class SingleImportScope(private val aliasName: Name, private val descriptors: Collection<DeclarationDescriptor>) : JetScope { class SingleImportScope(private val aliasName: Name, private val descriptors: Collection<DeclarationDescriptor>) : JetScope {
@@ -35,6 +36,8 @@ class SingleImportScope(private val aliasName: Name, private val descriptors: Co
override fun getFunctions(name: Name) override fun getFunctions(name: Name)
= if (name == aliasName) descriptors.filterIsInstance<FunctionDescriptor>() else emptyList() = if (name == aliasName) descriptors.filterIsInstance<FunctionDescriptor>() else emptyList()
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> = emptyList()
override fun getLocalVariable(name: Name): VariableDescriptor? = null override fun getLocalVariable(name: Name): VariableDescriptor? = null
override fun getContainingDeclaration(): DeclarationDescriptor = throw UnsupportedOperationException() override fun getContainingDeclaration(): DeclarationDescriptor = throw UnsupportedOperationException()
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.LookupMode
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.util.collectionUtils.concat import org.jetbrains.kotlin.util.collectionUtils.concat
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import java.util.LinkedHashSet import java.util.LinkedHashSet
@@ -254,6 +255,11 @@ class LazyImportScope(
return importResolver.collectFromImports(name, LookupMode.EVERYTHING) { scope, name -> scope.getFunctions(name) } return importResolver.collectFromImports(name, LookupMode.EVERYTHING) { scope, name -> scope.getFunctions(name) }
} }
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name, LookupMode.EVERYTHING) { scope, name -> scope.getSyntheticExtensionProperties(receiverType, name) }
}
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf() override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> { override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.LinkedHashSet import java.util.LinkedHashSet
@@ -110,6 +111,8 @@ protected constructor(
protected abstract fun getNonDeclaredProperties(name: Name, result: MutableSet<VariableDescriptor>) protected abstract fun getNonDeclaredProperties(name: Name, result: MutableSet<VariableDescriptor>)
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = listOf<VariableDescriptor>()
override fun getLocalVariable(name: Name): VariableDescriptor? = null override fun getLocalVariable(name: Name): VariableDescriptor? = null
override fun getDeclarationsByLabel(labelName: Name) = setOf<DeclarationDescriptor>() override fun getDeclarationsByLabel(labelName: Name) = setOf<DeclarationDescriptor>()
@@ -297,6 +297,8 @@ public abstract class LazyJavaMemberScope(
override fun getProperties(name: Name): Collection<VariableDescriptor> = properties(name) override fun getProperties(name: Name): Collection<VariableDescriptor> = properties(name)
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = listOf<VariableDescriptor>()
override fun getLocalVariable(name: Name): VariableDescriptor? = null override fun getLocalVariable(name: Name): VariableDescriptor? = null
override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>() override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
/** /**
@@ -46,6 +47,10 @@ public abstract class AbstractScopeAdapter : JetScope {
return workerScope.getProperties(name) return workerScope.getProperties(name)
} }
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> {
return workerScope.getSyntheticExtensionProperties(receiverType, name)
}
override fun getLocalVariable(name: Name): VariableDescriptor? { override fun getLocalVariable(name: Name): VariableDescriptor? {
return workerScope.getLocalVariable(name) return workerScope.getLocalVariable(name)
} }
@@ -18,9 +18,11 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.util.collectionUtils.concat import org.jetbrains.kotlin.util.collectionUtils.concat
import java.util.* import org.jetbrains.kotlin.utils.Printer
import java.util.ArrayList
import java.util.LinkedHashSet
public open class ChainedScope( public open class ChainedScope(
private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */, private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
@@ -63,6 +65,9 @@ public open class ChainedScope(
override fun getFunctions(name: Name): Collection<FunctionDescriptor> override fun getFunctions(name: Name): Collection<FunctionDescriptor>
= getFromAllScopes { it.getFunctions(name) } = getFromAllScopes { it.getFunctions(name) }
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor>
= getFromAllScopes { it.getSyntheticExtensionProperties(receiverType, name) }
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> { override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
if (implicitReceiverHierarchy == null) { if (implicitReceiverHierarchy == null) {
val result = ArrayList<ReceiverParameterDescriptor>() val result = ArrayList<ReceiverParameterDescriptor>()
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
@@ -32,6 +33,8 @@ public class ExplicitImportsScope(private val descriptors: Collection<Declaratio
override fun getFunctions(name: Name) = descriptors.filter { it.getName() == name }.filterIsInstance<FunctionDescriptor>() override fun getFunctions(name: Name) = descriptors.filter { it.getName() == name }.filterIsInstance<FunctionDescriptor>()
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> = listOf()
override fun getContainingDeclaration() = throw UnsupportedOperationException() override fun getContainingDeclaration() = throw UnsupportedOperationException()
override fun getDeclarationsByLabel(labelName: Name) = emptyList<DeclarationDescriptor>() override fun getDeclarationsByLabel(labelName: Name) = emptyList<DeclarationDescriptor>()
@@ -16,8 +16,9 @@
package org.jetbrains.kotlin.resolve.scopes package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
public class FilteringScope(private val workerScope: JetScope, private val predicate: (DeclarationDescriptor) -> Boolean) : JetScope { public class FilteringScope(private val workerScope: JetScope, private val predicate: (DeclarationDescriptor) -> Boolean) : JetScope {
@@ -35,6 +36,8 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
override fun getProperties(name: Name) = workerScope.getProperties(name).filter(predicate) override fun getProperties(name: Name) = workerScope.getProperties(name).filter(predicate)
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = workerScope.getSyntheticExtensionProperties(receiverType, name).filter(predicate)
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name)) override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
override fun getDescriptors(kindFilter: DescriptorKindFilter, override fun getDescriptors(kindFilter: DescriptorKindFilter,
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList import org.jetbrains.kotlin.utils.toReadOnlyList
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
@@ -34,6 +35,8 @@ public trait JetScope {
public fun getFunctions(name: Name): Collection<FunctionDescriptor> public fun getFunctions(name: Name): Collection<FunctionDescriptor>
public fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor>
public fun getContainingDeclaration(): DeclarationDescriptor public fun getContainingDeclaration(): DeclarationDescriptor
public fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> public fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor>
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
public abstract class JetScopeImpl : JetScope { public abstract class JetScopeImpl : JetScope {
@@ -31,6 +32,8 @@ public abstract class JetScopeImpl : JetScope {
override fun getFunctions(name: Name): Collection<FunctionDescriptor> = setOf() override fun getFunctions(name: Name): Collection<FunctionDescriptor> = setOf()
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> = listOf()
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf() override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
override fun getDescriptors(kindFilter: DescriptorKindFilter, override fun getDescriptors(kindFilter: DescriptorKindFilter,
@@ -16,12 +16,14 @@
package org.jetbrains.kotlin.resolve.scopes package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValueOfMethod
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValuesMethod
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
import java.util.ArrayList import java.util.ArrayList
import kotlin.properties.Delegates import kotlin.properties.Delegates
import org.jetbrains.kotlin.resolve.DescriptorFactory.*
public class StaticScopeForKotlinClass( public class StaticScopeForKotlinClass(
private val containingClass: ClassDescriptor private val containingClass: ClassDescriptor
@@ -46,6 +48,7 @@ public class StaticScopeForKotlinClass(
override fun getPackage(name: Name) = null override fun getPackage(name: Name) = null
override fun getProperties(name: Name) = listOf<VariableDescriptor>() override fun getProperties(name: Name) = listOf<VariableDescriptor>()
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = listOf<VariableDescriptor>()
override fun getLocalVariable(name: Name) = null override fun getLocalVariable(name: Name) = null
override fun getContainingDeclaration() = containingClass override fun getContainingDeclaration() = containingClass
override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>() override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
@@ -16,11 +16,14 @@
package org.jetbrains.kotlin.resolve.scopes package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.* import org.jetbrains.kotlin.utils.Printer
import java.util.* import org.jetbrains.kotlin.utils.newHashSetWithExpectedSize
import java.util.HashMap
import kotlin.properties.Delegates import kotlin.properties.Delegates
public class SubstitutingScope(private val workerScope: JetScope, private val substitutor: TypeSubstitutor) : JetScope { public class SubstitutingScope(private val workerScope: JetScope, private val substitutor: TypeSubstitutor) : JetScope {
@@ -66,6 +69,8 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
override fun getFunctions(name: Name) = substitute(workerScope.getFunctions(name)) override fun getFunctions(name: Name) = substitute(workerScope.getFunctions(name))
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = substitute(workerScope.getSyntheticExtensionProperties(receiverType, name))
override fun getPackage(name: Name) = workerScope.getPackage(name) override fun getPackage(name: Name) = workerScope.getPackage(name)
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> { override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
@@ -91,6 +91,14 @@ public class ErrorUtils {
return ERROR_PROPERTY_GROUP; return ERROR_PROPERTY_GROUP;
} }
@NotNull
@Override
public Collection<VariableDescriptor> getSyntheticExtensionProperties(
@NotNull JetType receiverType, @NotNull Name name
) {
return ERROR_PROPERTY_GROUP;
}
@Override @Override
public VariableDescriptor getLocalVariable(@NotNull Name name) { public VariableDescriptor getLocalVariable(@NotNull Name name) {
return ERROR_PROPERTY; return ERROR_PROPERTY;
@@ -193,6 +201,14 @@ public class ErrorUtils {
throw new IllegalStateException(); throw new IllegalStateException();
} }
@NotNull
@Override
public Collection<VariableDescriptor> getSyntheticExtensionProperties(
@NotNull JetType receiverType, @NotNull Name name
) {
throw new IllegalStateException();
}
@NotNull @NotNull
@Override @Override
public DeclarationDescriptor getContainingDeclaration() { public DeclarationDescriptor getContainingDeclaration() {
@@ -16,17 +16,20 @@
package org.jetbrains.kotlin.serialization.deserialization.descriptors package org.jetbrains.kotlin.serialization.deserialization.descriptors
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.CallableKind import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.CallableKind
import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext import org.jetbrains.kotlin.serialization.deserialization.DeserializationContext
import java.util.* import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.toReadOnlyList
import java.util.ArrayList
import java.util.LinkedHashMap
import java.util.LinkedHashSet
public abstract class DeserializedMemberScope protected constructor( public abstract class DeserializedMemberScope protected constructor(
protected val c: DeserializationContext, protected val c: DeserializationContext,
@@ -109,6 +112,8 @@ public abstract class DeserializedMemberScope protected constructor(
protected abstract fun addClassDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean) protected abstract fun addClassDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = listOf<VariableDescriptor>()
override fun getPackage(name: Name): PackageViewDescriptor? = null override fun getPackage(name: Name): PackageViewDescriptor? = null
override fun getLocalVariable(name: Name): VariableDescriptor? = null override fun getLocalVariable(name: Name): VariableDescriptor? = null