Synthetic extensions suggested in completion

This commit is contained in:
Valentin Kipyatkov
2015-07-08 18:49:52 +03:00
parent 08754b9fc0
commit 17442617bb
27 changed files with 196 additions and 99 deletions
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.resolve.jvm.PLATFORM_TYPES
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude.NonExtensions
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.storage.NotNullLazyValue
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
@@ -51,7 +52,7 @@ import java.util.LinkedHashSet
public abstract class LazyJavaMemberScope(
protected val c: LazyJavaResolverContext,
private val containingDeclaration: DeclarationDescriptor
) : JetScope {
) : JetScopeImpl() {
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there
// but is placed in the base class to not duplicate code
private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue<Collection<DeclarationDescriptor>>(
@@ -297,11 +298,6 @@ public abstract class LazyJavaMemberScope(
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 getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
override fun getOwnDeclaredDescriptors() = getDescriptors()
override fun getDescriptors(kindFilter: DescriptorKindFilter,
@@ -51,6 +51,10 @@ public abstract class AbstractScopeAdapter : JetScope {
return workerScope.getSyntheticExtensionProperties(receiverType, name)
}
override fun getSyntheticExtensionProperties(receiverType: JetType): Collection<VariableDescriptor> {
return workerScope.getSyntheticExtensionProperties(receiverType)
}
override fun getLocalVariable(name: Name): VariableDescriptor? {
return workerScope.getLocalVariable(name)
}
@@ -68,6 +68,9 @@ public open class ChainedScope(
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor>
= getFromAllScopes { it.getSyntheticExtensionProperties(receiverType, name) }
override fun getSyntheticExtensionProperties(receiverType: JetType): Collection<VariableDescriptor>
= getFromAllScopes { it.getSyntheticExtensionProperties(receiverType) }
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
if (implicitReceiverHierarchy == null) {
val result = ArrayList<ReceiverParameterDescriptor>()
@@ -82,12 +85,8 @@ public open class ChainedScope(
override fun getDeclarationsByLabel(labelName: Name) = scopeChain.flatMap { it.getDeclarationsByLabel(labelName) }
override fun getDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
val result = LinkedHashSet<DeclarationDescriptor>()
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
return result
}
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= getFromAllScopes { it.getDescriptors(kindFilter, nameFilter) }
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
throw UnsupportedOperationException()
@@ -22,29 +22,19 @@ import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
public class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : JetScope {
public class ExplicitImportsScope(private val descriptors: Collection<DeclarationDescriptor>) : JetScopeImpl() {
override fun getClassifier(name: Name) = descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<ClassifierDescriptor>()
override fun getPackage(name: Name)= descriptors.filter { it.getName() == name }.firstIsInstanceOrNull<PackageViewDescriptor>()
override fun getProperties(name: Name) = descriptors.filter { it.getName() == name }.filterIsInstance<VariableDescriptor>()
override fun getLocalVariable(name: Name): VariableDescriptor? = null
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 getDeclarationsByLabel(labelName: Name) = emptyList<DeclarationDescriptor>()
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = descriptors
override fun getImplicitReceiversHierarchy() = emptyList<ReceiverParameterDescriptor>()
override fun getOwnDeclaredDescriptors() = emptyList<DeclarationDescriptor>()
override fun printScopeStructure(p: Printer) {
p.println(javaClass.getName())
}
@@ -38,6 +38,8 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = workerScope.getSyntheticExtensionProperties(receiverType, name).filter(predicate)
override fun getSyntheticExtensionProperties(receiverType: JetType) = workerScope.getSyntheticExtensionProperties(receiverType).filter(predicate)
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
override fun getDescriptors(kindFilter: DescriptorKindFilter,
@@ -37,6 +37,8 @@ public trait JetScope {
public fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor>
public fun getSyntheticExtensionProperties(receiverType: JetType): Collection<VariableDescriptor>
public fun getContainingDeclaration(): DeclarationDescriptor
public fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor>
@@ -34,6 +34,8 @@ public abstract class JetScopeImpl : JetScope {
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name): Collection<VariableDescriptor> = listOf()
override fun getSyntheticExtensionProperties(receiverType: JetType): Collection<VariableDescriptor> = listOf()
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
override fun getDescriptors(kindFilter: DescriptorKindFilter,
@@ -27,7 +27,7 @@ import kotlin.properties.Delegates
public class StaticScopeForKotlinClass(
private val containingClass: ClassDescriptor
) : JetScope {
) : JetScopeImpl() {
override fun getClassifier(name: Name) = null // TODO
private val functions: List<FunctionDescriptor> by Delegates.lazy {
@@ -46,13 +46,7 @@ public class StaticScopeForKotlinClass(
override fun getFunctions(name: Name) = functions.filterTo(ArrayList<FunctionDescriptor>(2)) { it.getName() == name }
override fun getPackage(name: Name) = null
override fun getProperties(name: Name) = listOf<VariableDescriptor>()
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = listOf<VariableDescriptor>()
override fun getLocalVariable(name: Name) = null
override fun getContainingDeclaration() = containingClass
override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
override fun getImplicitReceiversHierarchy() = listOf<ReceiverParameterDescriptor>()
override fun printScopeStructure(p: Printer) {
p.println("Static scope for $containingClass")
@@ -71,6 +71,8 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
override fun getSyntheticExtensionProperties(receiverType: JetType, name: Name) = substitute(workerScope.getSyntheticExtensionProperties(receiverType, name))
override fun getSyntheticExtensionProperties(receiverType: JetType) = substitute(workerScope.getSyntheticExtensionProperties(receiverType))
override fun getPackage(name: Name) = workerScope.getPackage(name)
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
@@ -99,6 +99,12 @@ public class ErrorUtils {
return ERROR_PROPERTY_GROUP;
}
@NotNull
@Override
public Collection<VariableDescriptor> getSyntheticExtensionProperties(@NotNull JetType receiverType) {
return ERROR_PROPERTY_GROUP;
}
@Override
public VariableDescriptor getLocalVariable(@NotNull Name name) {
return ERROR_PROPERTY;
@@ -209,6 +215,12 @@ public class ErrorUtils {
throw new IllegalStateException();
}
@NotNull
@Override
public Collection<VariableDescriptor> getSyntheticExtensionProperties(@NotNull JetType receiverType) {
throw new IllegalStateException();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.serialization.deserialization.descriptors
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
import org.jetbrains.kotlin.serialization.Flags
import org.jetbrains.kotlin.serialization.ProtoBuf
import org.jetbrains.kotlin.serialization.ProtoBuf.Callable.CallableKind
@@ -34,7 +34,7 @@ import java.util.LinkedHashSet
public abstract class DeserializedMemberScope protected constructor(
protected val c: DeserializationContext,
membersList: Collection<ProtoBuf.Callable>
) : JetScope {
) : JetScopeImpl() {
private data class ProtoKey(val name: Name, val kind: Kind, val isExtension: Boolean)
private enum class Kind { FUNCTION, PROPERTY }
@@ -112,16 +112,8 @@ public abstract class DeserializedMemberScope protected constructor(
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 getLocalVariable(name: Name): VariableDescriptor? = null
override fun getContainingDeclaration() = c.containingDeclaration
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
protected fun computeDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
//NOTE: descriptors should be in the same order they were serialized in