Replace function MemberScope.getContainingDeclaration() to property ownerDescriptor

This commit is contained in:
Stanislav Erokhin
2015-11-04 15:29:33 +03:00
parent 52dc23012f
commit c4582d0e0c
32 changed files with 86 additions and 90 deletions
@@ -162,7 +162,7 @@ public class LazyJavaClassMemberScope(
val overriddenBuiltinProperty = getter?.getOverriddenBuiltinWithDifferentJvmName()
val specialGetterName = overriddenBuiltinProperty?.getBuiltinSpecialPropertyGetterName()
if (specialGetterName != null
&& !this@LazyJavaClassMemberScope.getContainingDeclaration().hasRealKotlinSuperClassWithOverrideOf(
&& !this@LazyJavaClassMemberScope.ownerDescriptor.hasRealKotlinSuperClassWithOverrideOf(
overriddenBuiltinProperty!!)
) {
return findGetterByName(specialGetterName, functions)
@@ -221,7 +221,7 @@ public class LazyJavaClassMemberScope(
// Merge functions with same signatures
val mergedFunctionFromSuperTypes = DescriptorResolverUtils.resolveOverrides(
name, functionsFromSupertypes, emptyList(), getContainingDeclaration(), ErrorReporter.DO_NOTHING)
name, functionsFromSupertypes, emptyList(), ownerDescriptor, ErrorReporter.DO_NOTHING)
// add declarations
addOverriddenBuiltinMethods(name, result, mergedFunctionFromSuperTypes, result) {
@@ -245,7 +245,7 @@ public class LazyJavaClassMemberScope(
functionsFromSupertypes: Collection<SimpleFunctionDescriptor>
) {
result.addAll(DescriptorResolverUtils.resolveOverrides(
name, functionsFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter))
name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
}
private fun addOverriddenBuiltinMethods(
@@ -301,7 +301,7 @@ public class LazyJavaClassMemberScope(
}
private fun getFunctionsFromSupertypes(name: Name): Set<SimpleFunctionDescriptor> {
return getContainingDeclaration().typeConstructor.supertypes.flatMap {
return ownerDescriptor.typeConstructor.supertypes.flatMap {
it.memberScope.getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { f -> f as SimpleFunctionDescriptor }
}.toSet()
}
@@ -323,7 +323,7 @@ public class LazyJavaClassMemberScope(
}
result.addAll(DescriptorResolverUtils.resolveOverrides(
name, propertiesFromSupertypes + propertiesOverridesFromSuperTypes, result, getContainingDeclaration(), c.components.errorReporter))
name, propertiesFromSupertypes + propertiesOverridesFromSuperTypes, result, ownerDescriptor, c.components.errorReporter))
}
private fun addPropertyOverrideByMethod(
@@ -351,7 +351,7 @@ public class LazyJavaClassMemberScope(
val annotations = c.resolveAnnotations(method)
val propertyDescriptor = JavaPropertyDescriptor(
getContainingDeclaration(), annotations, modality, method.getVisibility(),
ownerDescriptor, annotations, modality, method.getVisibility(),
/* isVar = */ false, method.name, c.components.sourceElementFactory.source(method), /* original */ null,
/* isStaticFinal = */ false
)
@@ -380,12 +380,12 @@ public class LazyJavaClassMemberScope(
null
assert(setterMethod?.let { it.modality == getterMethod.modality } ?: true) {
"Different accessors modalities when creating overrides for $overriddenProperty in ${getContainingDeclaration()}" +
"Different accessors modalities when creating overrides for $overriddenProperty in ${ownerDescriptor}" +
"for getter is ${getterMethod.modality}, but for setter is ${setterMethod?.modality}"
}
val propertyDescriptor = JavaPropertyDescriptor(
getContainingDeclaration(), Annotations.EMPTY, getterMethod.modality, getterMethod.visibility,
ownerDescriptor, Annotations.EMPTY, getterMethod.modality, getterMethod.visibility,
/* isVar = */ setterMethod != null, overriddenProperty.name, getterMethod.source,
/* original */ null,
/* isStaticFinal = */ false
@@ -413,7 +413,7 @@ public class LazyJavaClassMemberScope(
}
private fun getPropertiesFromSupertypes(name: Name): Set<PropertyDescriptor> {
return getContainingDeclaration().typeConstructor.supertypes.flatMap {
return ownerDescriptor.typeConstructor.supertypes.flatMap {
it.memberScope.getContributedVariables(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { p -> p }
}.toSet()
}
@@ -423,7 +423,7 @@ public class LazyJavaClassMemberScope(
valueParameters: LazyJavaScope.ResolvedValueParameters
): LazyJavaScope.MethodSignatureData {
val propagated = c.components.externalSignatureResolver.resolvePropagatedSignature(
method, getContainingDeclaration(), returnType, null, valueParameters.descriptors, methodTypeParameters
method, ownerDescriptor, returnType, null, valueParameters.descriptors, methodTypeParameters
)
val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature(
method, !propagated.getSuperMethods().isEmpty(), propagated.getReturnType(),
@@ -469,7 +469,7 @@ public class LazyJavaClassMemberScope(
}
private fun resolveConstructor(constructor: JavaConstructor): JavaConstructorDescriptor {
val classDescriptor = getContainingDeclaration()
val classDescriptor = ownerDescriptor
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
@@ -504,7 +504,7 @@ public class LazyJavaClassMemberScope(
if (jClass.isInterface() && !isAnnotation)
return null
val classDescriptor = getContainingDeclaration()
val classDescriptor = ownerDescriptor
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
classDescriptor, Annotations.EMPTY, /* isPrimary = */ true, c.components.sourceElementFactory.source(jClass)
)
@@ -598,7 +598,7 @@ public class LazyJavaClassMemberScope(
if (jNestedClass == null) {
val field = enumEntryIndex()[name]
if (field != null) {
EnumEntrySyntheticClassDescriptor.create(c.storageManager, getContainingDeclaration(), name,
EnumEntrySyntheticClassDescriptor.create(c.storageManager, ownerDescriptor, name,
c.storageManager.createLazyValue {
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({true})
}, c.components.sourceElementFactory.source(field))
@@ -607,13 +607,13 @@ public class LazyJavaClassMemberScope(
}
else {
LazyJavaClassDescriptor(
c, getContainingDeclaration(), DescriptorUtils.getFqName(getContainingDeclaration()).child(name).toSafe(), jNestedClass
c, ownerDescriptor, DescriptorUtils.getFqName(ownerDescriptor).child(name).toSafe(), jNestedClass
)
}
}
override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? =
DescriptorUtils.getDispatchReceiverParameterIfNeeded(getContainingDeclaration())
DescriptorUtils.getDispatchReceiverParameterIfNeeded(ownerDescriptor)
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
recordLookup(name, location)
@@ -627,14 +627,15 @@ public class LazyJavaClassMemberScope(
if (jClass.isAnnotationType()) return memberIndex().getMethodNames(nameFilter)
return memberIndex().getAllFieldNames() +
getContainingDeclaration().getTypeConstructor().getSupertypes().flatMapTo(LinkedHashSet<Name>()) { supertype ->
ownerDescriptor.getTypeConstructor().getSupertypes().flatMapTo(LinkedHashSet<Name>()) { supertype ->
supertype.getMemberScope().getContributedDescriptors(kindFilter, nameFilter).map { variable ->
variable.getName()
}
}
}
override fun getContainingDeclaration() = super.getContainingDeclaration() as ClassDescriptor
override val ownerDescriptor: ClassDescriptor
get() = super.ownerDescriptor as ClassDescriptor
// namespaces should be resolved elsewhere
override fun getPackage(name: Name) = null
@@ -78,7 +78,7 @@ public class LazyJavaPackageScope(
}
}
private val packageFragment: LazyJavaPackageFragment get() = getContainingDeclaration() as LazyJavaPackageFragment
private val packageFragment: LazyJavaPackageFragment get() = ownerDescriptor as LazyJavaPackageFragment
private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
val classId = ClassId(packageFragment.fqName, name)
@@ -53,7 +53,7 @@ import java.util.*
public abstract class LazyJavaScope(
protected val c: LazyJavaResolverContext,
private val containingDeclaration: DeclarationDescriptor
override val ownerDescriptor: DeclarationDescriptor
) : MemberScopeImpl() {
// 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
@@ -66,8 +66,6 @@ public abstract class LazyJavaScope(
listOf()
)
override fun getContainingDeclaration() = containingDeclaration
protected val memberIndex: NotNullLazyValue<MemberIndex> = c.storageManager.createLazyValue { computeMemberIndex() }
protected abstract fun computeMemberIndex(): MemberIndex
@@ -113,7 +111,7 @@ public abstract class LazyJavaScope(
fun resolveMethodToFunctionDescriptor(method: JavaMethod): JavaMethodDescriptor {
val annotations = c.resolveAnnotations(method)
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod(
containingDeclaration, annotations, method.name, c.components.sourceElementFactory.source(method)
ownerDescriptor, annotations, method.name, c.components.sourceElementFactory.source(method)
)
val c = c.child(functionDescriptorImpl, method)
@@ -237,7 +235,7 @@ public abstract class LazyJavaScope(
computeNonDeclaredProperties(name, properties)
if (DescriptorUtils.isAnnotationClass(containingDeclaration))
if (DescriptorUtils.isAnnotationClass(ownerDescriptor))
properties.toReadOnlyList()
else
enhanceSignatures(properties).toReadOnlyList()
@@ -275,7 +273,7 @@ public abstract class LazyJavaScope(
val annotations = c.resolveAnnotations(field)
val propertyName = field.getName()
return JavaPropertyDescriptor(containingDeclaration, annotations, Modality.FINAL, visibility, isVar, propertyName,
return JavaPropertyDescriptor(ownerDescriptor, annotations, Modality.FINAL, visibility, isVar, propertyName,
c.components.sourceElementFactory.source(field), /* original = */ null, /*isConst= */ field.isFinalStatic)
}
@@ -351,13 +349,13 @@ public abstract class LazyJavaScope(
protected abstract fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
override fun toString() = "Lazy scope for ${getContainingDeclaration()}"
override fun toString() = "Lazy scope for ${ownerDescriptor}"
override fun printScopeStructure(p: Printer) {
p.println(javaClass.getSimpleName(), " {")
p.pushIndent()
p.println("containingDeclaration: ${getContainingDeclaration()}")
p.println("containingDeclaration: ${ownerDescriptor}")
p.popIndent()
p.println("}")
@@ -16,10 +16,7 @@
package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
@@ -72,32 +69,32 @@ public class LazyJavaStaticClassScope(
override fun getSubPackages(): Collection<FqName> = listOf()
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) {
val nestedClassesScope = getContainingDeclaration().getUnsubstitutedInnerClassesScope()
val nestedClassesScope = ownerDescriptor.getUnsubstitutedInnerClassesScope()
result.addIfNotNull(c.components.samConversionResolver.resolveSamConstructor(name, nestedClassesScope, NoLookupLocation.FOR_ALREADY_TRACKED))
val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, getContainingDeclaration())
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter))
val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, ownerDescriptor)
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
if (jClass.isEnum()) {
when (name) {
DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(getContainingDeclaration()))
DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(getContainingDeclaration()))
DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(ownerDescriptor))
DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(ownerDescriptor))
}
}
}
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
val propertiesFromSupertypes = getStaticPropertiesFromJavaSupertypes(name, getContainingDeclaration())
val propertiesFromSupertypes = getStaticPropertiesFromJavaSupertypes(name, ownerDescriptor)
val actualProperties =
if (!result.isEmpty()) {
DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter)
DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, ownerDescriptor, c.components.errorReporter)
}
else {
propertiesFromSupertypes.groupBy {
it.realOriginal
}.flatMap {
DescriptorResolverUtils.resolveOverrides(name, it.value, result, getContainingDeclaration(), c.components.errorReporter)
DescriptorResolverUtils.resolveOverrides(name, it.value, result, ownerDescriptor, c.components.errorReporter)
}
}
@@ -105,12 +102,13 @@ public class LazyJavaStaticClassScope(
if (jClass.isEnum) {
if (name == DescriptorUtils.ENUM_VALUES) {
result.add(createEnumValuesProperty(getContainingDeclaration()))
result.add(createEnumValuesProperty(ownerDescriptor))
}
}
}
override fun getContainingDeclaration() = super.getContainingDeclaration() as LazyJavaClassDescriptor
override val ownerDescriptor: LazyJavaClassDescriptor
get() = super.ownerDescriptor as LazyJavaClassDescriptor
private fun getStaticFunctionsFromJavaSuperClasses(name: Name, descriptor: ClassDescriptor): Set<SimpleFunctionDescriptor> {
val staticScope = descriptor.getParentJavaStaticClassScope() ?: return emptySet()
@@ -41,7 +41,8 @@ class FunctionClassScope(
}
}
override fun getContainingDeclaration() = functionClass
override val ownerDescriptor: DeclarationDescriptor
get() = functionClass
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
if (!kindFilter.acceptsKinds(DescriptorKindFilter.CALLABLES.kindMask)) return listOf()
@@ -75,7 +76,7 @@ class FunctionClassScope(
}
override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) {
error("Conflict in scope of ${getContainingDeclaration()}: $fromSuper vs $fromCurrent")
error("Conflict in scope of $ownerDescriptor: $fromSuper vs $fromCurrent")
}
}
)
@@ -258,7 +258,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
public DeclarationDescriptor getOwnerDescriptor() {
return EnumEntrySyntheticClassDescriptor.this;
}
@@ -30,9 +30,8 @@ import org.jetbrains.kotlin.utils.sure
import java.util.ArrayList
public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() {
override fun getContainingDeclaration(): DeclarationDescriptor {
return moduleDescriptor.getPackage(fqName)
}
override val ownerDescriptor: DeclarationDescriptor
get() = moduleDescriptor.getPackage(fqName)
override fun getPackage(name: Name): PackageViewDescriptor? {
if (name.isSpecial()) {
@@ -65,7 +64,7 @@ public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, pr
p.println(javaClass.getSimpleName(), " {")
p.pushIndent()
p.println("thisDescriptor = ", getContainingDeclaration())
p.println("thisDescriptor = ", ownerDescriptor)
p.popIndent()
p.println("}")
@@ -31,7 +31,7 @@ public fun LookupTracker.record(from: LookupLocation, inScope: MemberScope, name
val location = from.location ?: return
val scopeContainingDeclaration = inScope.getContainingDeclaration()
val scopeContainingDeclaration = inScope.ownerDescriptor
val scopeKind =
when (scopeContainingDeclaration) {
@@ -33,6 +33,9 @@ public abstract class AbstractScopeAdapter : MemberScope {
else
workerScope
override val ownerDescriptor: DeclarationDescriptor
get() = workerScope.ownerDescriptor
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return workerScope.getContributedFunctions(name, location)
}
@@ -49,10 +52,6 @@ public abstract class AbstractScopeAdapter : MemberScope {
return workerScope.getContributedVariables(name, location)
}
override fun getContainingDeclaration(): DeclarationDescriptor {
return workerScope.getContainingDeclaration()
}
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
return workerScope.getContributedDescriptors(kindFilter, nameFilter)
@@ -24,12 +24,15 @@ import org.jetbrains.kotlin.util.collectionUtils.getFromAllScopes
import org.jetbrains.kotlin.utils.Printer
public open class ChainedScope(
private val containingDeclaration: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
private val descriptor: DeclarationDescriptor?/* it's nullable as a hack for TypeUtils.intersect() */,
private val debugName: String,
vararg scopes: MemberScope
) : MemberScope {
private val scopeChain = scopes.clone()
override val ownerDescriptor: DeclarationDescriptor
get() = descriptor!!
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
= getFirstMatch(scopeChain) { it.getContributedClassifier(name, location) }
@@ -42,8 +45,6 @@ public open class ChainedScope(
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
= getFromAllScopes(scopeChain) { it.getContributedFunctions(name, location) }
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration!!
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= getFromAllScopes(scopeChain) { it.getContributedDescriptors(kindFilter, nameFilter) }
@@ -23,9 +23,9 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.Printer
public class InnerClassesScopeWrapper(val workerScope: MemberScope) : MemberScopeImpl() {
override fun getContainingDeclaration(): DeclarationDescriptor {
return workerScope.getContainingDeclaration()
}
override val ownerDescriptor: DeclarationDescriptor
get() = workerScope.ownerDescriptor
override fun getContributedClassifier(name: Name, location: LookupLocation) = workerScope.getContributedClassifier(name, location) as? ClassDescriptor
@@ -34,7 +34,7 @@ public interface MemberScope {
public fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
public fun getContainingDeclaration(): DeclarationDescriptor
val ownerDescriptor: DeclarationDescriptor
/**
* All visible descriptors from current scope possibly filtered by the given name and kind filters
@@ -53,7 +53,7 @@ public interface MemberScope {
companion object {
public fun empty(ownerDescriptor: DeclarationDescriptor): MemberScope {
return object : MemberScopeImpl() {
override fun getContainingDeclaration() = ownerDescriptor
override val ownerDescriptor = ownerDescriptor
override fun toString() = "Empty scope with owner: $ownerDescriptor"
@@ -57,7 +57,8 @@ public class StaticScopeForKotlinClass(
override fun getContributedFunctions(name: Name, location: LookupLocation) = functions.filterTo(ArrayList<FunctionDescriptor>(2)) { it.getName() == name }
override fun getContainingDeclaration() = containingClass
override val ownerDescriptor: DeclarationDescriptor
get() = containingClass
override fun printScopeStructure(p: Printer) {
p.println("Static scope for $containingClass")
@@ -67,7 +67,8 @@ public class SubstitutingScope(private val workerScope: MemberScope, private val
override fun getPackage(name: Name) = workerScope.getPackage(name)
override fun getContainingDeclaration() = workerScope.getContainingDeclaration()
override val ownerDescriptor: DeclarationDescriptor
get() = workerScope.ownerDescriptor
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean) = _allDescriptors
@@ -192,7 +192,7 @@ public class ErrorUtils {
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
public DeclarationDescriptor getOwnerDescriptor() {
return ERROR_MODULE;
}
@@ -248,7 +248,7 @@ public class ErrorUtils {
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
public DeclarationDescriptor getOwnerDescriptor() {
return ERROR_MODULE;
}
@@ -116,7 +116,8 @@ public abstract class DeserializedMemberScope protected constructor(
protected abstract fun addClassDescriptors(result: MutableCollection<DeclarationDescriptor>, nameFilter: (Name) -> Boolean)
override fun getContainingDeclaration() = c.containingDeclaration
override val ownerDescriptor: DeclarationDescriptor
get() = c.containingDeclaration
protected fun computeDescriptors(
kindFilter: DescriptorKindFilter,
@@ -179,7 +180,7 @@ public abstract class DeserializedMemberScope protected constructor(
p.println(javaClass.simpleName, " {")
p.pushIndent()
p.println("containingDeclaration = " + getContainingDeclaration())
p.println("containingDeclaration = " + ownerDescriptor)
p.popIndent()
p.println("}")