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
@@ -39,7 +39,7 @@ public object SamConversionResolverImpl : SamConversionResolver {
override fun resolveSamConstructor(name: Name, scope: MemberScope, location: LookupLocation): SamConstructorDescriptor? { override fun resolveSamConstructor(name: Name, scope: MemberScope, location: LookupLocation): SamConstructorDescriptor? {
val classifier = scope.getContributedClassifier(name, location) as? LazyJavaClassDescriptor ?: return null val classifier = scope.getContributedClassifier(name, location) as? LazyJavaClassDescriptor ?: return null
if (classifier.getFunctionTypeForSamInterface() == null) return null if (classifier.getFunctionTypeForSamInterface() == null) return null
return SingleAbstractMethodUtils.createSamConstructorFunction(scope.getContainingDeclaration(), classifier) return SingleAbstractMethodUtils.createSamConstructorFunction(scope.ownerDescriptor, classifier)
} }
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@@ -67,7 +67,7 @@ class PropagationHeuristics {
arrayTypeFromSuper.getConstructor(), arrayTypeFromSuper.getConstructor(),
arrayTypeFromSuper.isMarkedNullable(), arrayTypeFromSuper.isMarkedNullable(),
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)), Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
MemberScope.Companion.empty(elementType.getMemberScope().getContainingDeclaration())); MemberScope.Companion.empty(elementType.getMemberScope().getOwnerDescriptor()));
data.reportError("Return type is not a subtype of overridden method. " + data.reportError("Return type is not a subtype of overridden method. " +
"To fix it, add annotation with Kotlin signature to super method with type " "To fix it, add annotation with Kotlin signature to super method with type "
@@ -104,7 +104,7 @@ public fun resolvePossiblyAmbiguousCallableReference(
fun resolveInScope(traceTitle: String, staticScope: MemberScope): OverloadResolutionResults<CallableDescriptor> { fun resolveInScope(traceTitle: String, staticScope: MemberScope): OverloadResolutionResults<CallableDescriptor> {
// todo: drop this class when new resolve will be finished // todo: drop this class when new resolve will be finished
class StaticScopeAsLexicalScope(val staticScope: MemberScope) : BaseLexicalScope(staticScope.memberScopeAsImportingScope(), staticScope.getContainingDeclaration()) { class StaticScopeAsLexicalScope(val staticScope: MemberScope) : BaseLexicalScope(staticScope.memberScopeAsImportingScope(), staticScope.ownerDescriptor) {
override fun printStructure(p: Printer) { override fun printStructure(p: Printer) {
p.println(toString()) p.println(toString())
} }
@@ -44,7 +44,7 @@ class DynamicCallableDescriptors(private val builtIns: KotlinBuiltIns) {
val dynamicType = createDynamicType(builtIns) val dynamicType = createDynamicType(builtIns)
fun createDynamicDescriptorScope(call: Call, owner: DeclarationDescriptor) = object : MemberScopeImpl() { fun createDynamicDescriptorScope(call: Call, owner: DeclarationDescriptor) = object : MemberScopeImpl() {
override fun getContainingDeclaration() = owner override val ownerDescriptor: DeclarationDescriptor get() = owner
override fun printScopeStructure(p: Printer) { override fun printScopeStructure(p: Printer) {
p.println(javaClass.getSimpleName(), ": dynamic candidates for " + call) p.println(javaClass.getSimpleName(), ": dynamic candidates for " + call)
@@ -86,7 +86,7 @@ public class ResolveSessionUtils {
scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope(); scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope();
} }
return (ClassDescriptor) scope.getContainingDeclaration(); return (ClassDescriptor) scope.getOwnerDescriptor();
} }
@NotNull @NotNull
@@ -59,7 +59,7 @@ protected constructor(
}.toReadOnlyList() }.toReadOnlyList()
} }
override fun getContainingDeclaration() = thisDescriptor override val ownerDescriptor: DeclarationDescriptor get() = thisDescriptor
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassDescriptor? { override fun getContributedClassifier(name: Name, location: LookupLocation): ClassDescriptor? {
recordLookup(name, location) recordLookup(name, location)
@@ -23,9 +23,10 @@ import org.jetbrains.kotlin.utils.Printer
public class FilteringScope(private val workerScope: MemberScope, private val predicate: (DeclarationDescriptor) -> Boolean) : MemberScope { public class FilteringScope(private val workerScope: MemberScope, private val predicate: (DeclarationDescriptor) -> Boolean) : MemberScope {
override fun getContributedFunctions(name: Name, location: LookupLocation) = workerScope.getContributedFunctions(name, location).filter(predicate) override val ownerDescriptor: DeclarationDescriptor
get() = workerScope.ownerDescriptor
override fun getContainingDeclaration() = workerScope.getContainingDeclaration() override fun getContributedFunctions(name: Name, location: LookupLocation) = workerScope.getContributedFunctions(name, location).filter(predicate)
private fun <D : DeclarationDescriptor> filterDescriptor(descriptor: D?): D? private fun <D : DeclarationDescriptor> filterDescriptor(descriptor: D?): D?
= if (descriptor != null && predicate(descriptor)) descriptor else null = if (descriptor != null && predicate(descriptor)) descriptor else null
@@ -116,7 +116,7 @@ public fun HierarchicalScope.takeSnapshot(): HierarchicalScope = if (this is Lex
public fun MemberScope.memberScopeAsImportingScope(parentScope: ImportingScope? = null): ImportingScope = MemberScopeToImportingScopeAdapter(parentScope, this) public fun MemberScope.memberScopeAsImportingScope(parentScope: ImportingScope? = null): ImportingScope = MemberScopeToImportingScopeAdapter(parentScope, this)
@Deprecated("Temporary method for scope migration") @Deprecated("Temporary method for scope migration")
public fun MemberScope.memberScopeAsLexicalScope(): LexicalScope = LexicalScope.empty(memberScopeAsImportingScope(), getContainingDeclaration()) public fun MemberScope.memberScopeAsLexicalScope(): LexicalScope = LexicalScope.empty(memberScopeAsImportingScope(), ownerDescriptor)
private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: MemberScope) : ImportingScope { private class MemberScopeToImportingScopeAdapter(override val parent: ImportingScope?, val memberScope: MemberScope) : ImportingScope {
override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name) override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
@@ -161,7 +161,7 @@ public class TypeIntersector {
@NotNull @NotNull
@Override @Override
public DeclarationDescriptor getContainingDeclaration() { public DeclarationDescriptor getOwnerDescriptor() {
throw new UnsupportedOperationException("Should not call getContainingDeclaration on intersection scope " + this); throw new UnsupportedOperationException("Should not call getContainingDeclaration on intersection scope " + this);
} }
} }
@@ -62,7 +62,7 @@ class LazyOperationsLog(
public fun getText(): String { public fun getText(): String {
val groupedByOwner = records.groupByTo(IdentityHashMap()) { val groupedByOwner = records.groupByTo(IdentityHashMap()) {
val owner = it.data.fieldOwner val owner = it.data.fieldOwner
if (owner is MemberScope) owner.getContainingDeclaration() else owner if (owner is MemberScope) owner.ownerDescriptor else owner
}.map { Pair(it.getKey(), it.getValue()) } }.map { Pair(it.getKey(), it.getValue()) }
return groupedByOwner.map { return groupedByOwner.map {
@@ -40,14 +40,14 @@ private fun validateDeserializedScope(scope: MemberScope) {
val relevantDescriptors = scope.getContributedDescriptors().filter { member -> val relevantDescriptors = scope.getContributedDescriptors().filter { member ->
member is CallableMemberDescriptor && member.getKind().isReal() || (!isPackageViewScope && member is ClassDescriptor) member is CallableMemberDescriptor && member.getKind().isReal() || (!isPackageViewScope && member is ClassDescriptor)
} }
checkSorted(relevantDescriptors, scope.getContainingDeclaration()) checkSorted(relevantDescriptors, scope.ownerDescriptor)
} }
} }
//NOTE: see TypeUtils#IntersectionScope#getContainingDeclaration() //NOTE: see TypeUtils#IntersectionScope#getContainingDeclaration()
private fun MemberScope.safeGetContainingDeclaration(): DeclarationDescriptor? { private fun MemberScope.safeGetContainingDeclaration(): DeclarationDescriptor? {
return try { return try {
getContainingDeclaration() ownerDescriptor
} }
catch (e: UnsupportedOperationException) { catch (e: UnsupportedOperationException) {
null null
@@ -213,10 +213,8 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
private class ScopeWithClassifiers( private class ScopeWithClassifiers(
classifiers: List<ClassifierDescriptor>, classifiers: List<ClassifierDescriptor>,
val ownerDescriptor: DeclarationDescriptor override val ownerDescriptor: DeclarationDescriptor
) : MemberScopeImpl() { ) : MemberScopeImpl() {
override fun getContainingDeclaration() = ownerDescriptor
private val classifierMap = HashMap<Name, ClassifierDescriptor>() private val classifierMap = HashMap<Name, ClassifierDescriptor>()
val redeclarationHandler = RedeclarationHandler.THROW_EXCEPTION val redeclarationHandler = RedeclarationHandler.THROW_EXCEPTION
@@ -200,7 +200,7 @@ public class TypeUnifierTest extends KotlinLiteFixture {
} }
private TypeProjection makeTypeProjection(MemberScope scope, String typeStr) { private TypeProjection makeTypeProjection(MemberScope scope, String typeStr) {
LexicalScope withX = new LexicalScopeImpl(TypeTestUtilsKt.asLexicalScope(scope), scope.getContainingDeclaration(), LexicalScope withX = new LexicalScopeImpl(TypeTestUtilsKt.asLexicalScope(scope), scope.getOwnerDescriptor(),
false, null, "With X", RedeclarationHandler.DO_NOTHING, false, null, "With X", RedeclarationHandler.DO_NOTHING,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() { new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override @Override
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.utils.Printer
public fun MemberScope.asLexicalScope(): LexicalScope { public fun MemberScope.asLexicalScope(): LexicalScope {
val importingScope = memberScopeAsImportingScope() val importingScope = memberScopeAsImportingScope()
return object : BaseLexicalScope(importingScope, getContainingDeclaration()) { return object : BaseLexicalScope(importingScope, ownerDescriptor) {
override fun printStructure(p: Printer) { override fun printStructure(p: Printer) {
p.println("Util scope for tests") p.println("Util scope for tests")
} }
@@ -162,7 +162,7 @@ public class LazyJavaClassMemberScope(
val overriddenBuiltinProperty = getter?.getOverriddenBuiltinWithDifferentJvmName() val overriddenBuiltinProperty = getter?.getOverriddenBuiltinWithDifferentJvmName()
val specialGetterName = overriddenBuiltinProperty?.getBuiltinSpecialPropertyGetterName() val specialGetterName = overriddenBuiltinProperty?.getBuiltinSpecialPropertyGetterName()
if (specialGetterName != null if (specialGetterName != null
&& !this@LazyJavaClassMemberScope.getContainingDeclaration().hasRealKotlinSuperClassWithOverrideOf( && !this@LazyJavaClassMemberScope.ownerDescriptor.hasRealKotlinSuperClassWithOverrideOf(
overriddenBuiltinProperty!!) overriddenBuiltinProperty!!)
) { ) {
return findGetterByName(specialGetterName, functions) return findGetterByName(specialGetterName, functions)
@@ -221,7 +221,7 @@ public class LazyJavaClassMemberScope(
// Merge functions with same signatures // Merge functions with same signatures
val mergedFunctionFromSuperTypes = DescriptorResolverUtils.resolveOverrides( val mergedFunctionFromSuperTypes = DescriptorResolverUtils.resolveOverrides(
name, functionsFromSupertypes, emptyList(), getContainingDeclaration(), ErrorReporter.DO_NOTHING) name, functionsFromSupertypes, emptyList(), ownerDescriptor, ErrorReporter.DO_NOTHING)
// add declarations // add declarations
addOverriddenBuiltinMethods(name, result, mergedFunctionFromSuperTypes, result) { addOverriddenBuiltinMethods(name, result, mergedFunctionFromSuperTypes, result) {
@@ -245,7 +245,7 @@ public class LazyJavaClassMemberScope(
functionsFromSupertypes: Collection<SimpleFunctionDescriptor> functionsFromSupertypes: Collection<SimpleFunctionDescriptor>
) { ) {
result.addAll(DescriptorResolverUtils.resolveOverrides( result.addAll(DescriptorResolverUtils.resolveOverrides(
name, functionsFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter)) name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
} }
private fun addOverriddenBuiltinMethods( private fun addOverriddenBuiltinMethods(
@@ -301,7 +301,7 @@ public class LazyJavaClassMemberScope(
} }
private fun getFunctionsFromSupertypes(name: Name): Set<SimpleFunctionDescriptor> { 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 } it.memberScope.getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { f -> f as SimpleFunctionDescriptor }
}.toSet() }.toSet()
} }
@@ -323,7 +323,7 @@ public class LazyJavaClassMemberScope(
} }
result.addAll(DescriptorResolverUtils.resolveOverrides( result.addAll(DescriptorResolverUtils.resolveOverrides(
name, propertiesFromSupertypes + propertiesOverridesFromSuperTypes, result, getContainingDeclaration(), c.components.errorReporter)) name, propertiesFromSupertypes + propertiesOverridesFromSuperTypes, result, ownerDescriptor, c.components.errorReporter))
} }
private fun addPropertyOverrideByMethod( private fun addPropertyOverrideByMethod(
@@ -351,7 +351,7 @@ public class LazyJavaClassMemberScope(
val annotations = c.resolveAnnotations(method) val annotations = c.resolveAnnotations(method)
val propertyDescriptor = JavaPropertyDescriptor( val propertyDescriptor = JavaPropertyDescriptor(
getContainingDeclaration(), annotations, modality, method.getVisibility(), ownerDescriptor, annotations, modality, method.getVisibility(),
/* isVar = */ false, method.name, c.components.sourceElementFactory.source(method), /* original */ null, /* isVar = */ false, method.name, c.components.sourceElementFactory.source(method), /* original */ null,
/* isStaticFinal = */ false /* isStaticFinal = */ false
) )
@@ -380,12 +380,12 @@ public class LazyJavaClassMemberScope(
null null
assert(setterMethod?.let { it.modality == getterMethod.modality } ?: true) { 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}" "for getter is ${getterMethod.modality}, but for setter is ${setterMethod?.modality}"
} }
val propertyDescriptor = JavaPropertyDescriptor( val propertyDescriptor = JavaPropertyDescriptor(
getContainingDeclaration(), Annotations.EMPTY, getterMethod.modality, getterMethod.visibility, ownerDescriptor, Annotations.EMPTY, getterMethod.modality, getterMethod.visibility,
/* isVar = */ setterMethod != null, overriddenProperty.name, getterMethod.source, /* isVar = */ setterMethod != null, overriddenProperty.name, getterMethod.source,
/* original */ null, /* original */ null,
/* isStaticFinal = */ false /* isStaticFinal = */ false
@@ -413,7 +413,7 @@ public class LazyJavaClassMemberScope(
} }
private fun getPropertiesFromSupertypes(name: Name): Set<PropertyDescriptor> { 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 } it.memberScope.getContributedVariables(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS).map { p -> p }
}.toSet() }.toSet()
} }
@@ -423,7 +423,7 @@ public class LazyJavaClassMemberScope(
valueParameters: LazyJavaScope.ResolvedValueParameters valueParameters: LazyJavaScope.ResolvedValueParameters
): LazyJavaScope.MethodSignatureData { ): LazyJavaScope.MethodSignatureData {
val propagated = c.components.externalSignatureResolver.resolvePropagatedSignature( 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( val effectiveSignature = c.components.externalSignatureResolver.resolveAlternativeMethodSignature(
method, !propagated.getSuperMethods().isEmpty(), propagated.getReturnType(), method, !propagated.getSuperMethods().isEmpty(), propagated.getReturnType(),
@@ -469,7 +469,7 @@ public class LazyJavaClassMemberScope(
} }
private fun resolveConstructor(constructor: JavaConstructor): JavaConstructorDescriptor { private fun resolveConstructor(constructor: JavaConstructor): JavaConstructorDescriptor {
val classDescriptor = getContainingDeclaration() val classDescriptor = ownerDescriptor
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor( val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor) classDescriptor, c.resolveAnnotations(constructor), /* isPrimary = */ false, c.components.sourceElementFactory.source(constructor)
@@ -504,7 +504,7 @@ public class LazyJavaClassMemberScope(
if (jClass.isInterface() && !isAnnotation) if (jClass.isInterface() && !isAnnotation)
return null return null
val classDescriptor = getContainingDeclaration() val classDescriptor = ownerDescriptor
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor( val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
classDescriptor, Annotations.EMPTY, /* isPrimary = */ true, c.components.sourceElementFactory.source(jClass) classDescriptor, Annotations.EMPTY, /* isPrimary = */ true, c.components.sourceElementFactory.source(jClass)
) )
@@ -598,7 +598,7 @@ public class LazyJavaClassMemberScope(
if (jNestedClass == null) { if (jNestedClass == null) {
val field = enumEntryIndex()[name] val field = enumEntryIndex()[name]
if (field != null) { if (field != null) {
EnumEntrySyntheticClassDescriptor.create(c.storageManager, getContainingDeclaration(), name, EnumEntrySyntheticClassDescriptor.create(c.storageManager, ownerDescriptor, name,
c.storageManager.createLazyValue { c.storageManager.createLazyValue {
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({true}) memberIndex().getAllFieldNames() + memberIndex().getMethodNames({true})
}, c.components.sourceElementFactory.source(field)) }, c.components.sourceElementFactory.source(field))
@@ -607,13 +607,13 @@ public class LazyJavaClassMemberScope(
} }
else { else {
LazyJavaClassDescriptor( LazyJavaClassDescriptor(
c, getContainingDeclaration(), DescriptorUtils.getFqName(getContainingDeclaration()).child(name).toSafe(), jNestedClass c, ownerDescriptor, DescriptorUtils.getFqName(ownerDescriptor).child(name).toSafe(), jNestedClass
) )
} }
} }
override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? =
DescriptorUtils.getDispatchReceiverParameterIfNeeded(getContainingDeclaration()) DescriptorUtils.getDispatchReceiverParameterIfNeeded(ownerDescriptor)
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
recordLookup(name, location) recordLookup(name, location)
@@ -627,14 +627,15 @@ public class LazyJavaClassMemberScope(
if (jClass.isAnnotationType()) return memberIndex().getMethodNames(nameFilter) if (jClass.isAnnotationType()) return memberIndex().getMethodNames(nameFilter)
return memberIndex().getAllFieldNames() + return memberIndex().getAllFieldNames() +
getContainingDeclaration().getTypeConstructor().getSupertypes().flatMapTo(LinkedHashSet<Name>()) { supertype -> ownerDescriptor.getTypeConstructor().getSupertypes().flatMapTo(LinkedHashSet<Name>()) { supertype ->
supertype.getMemberScope().getContributedDescriptors(kindFilter, nameFilter).map { variable -> supertype.getMemberScope().getContributedDescriptors(kindFilter, nameFilter).map { variable ->
variable.getName() variable.getName()
} }
} }
} }
override fun getContainingDeclaration() = super.getContainingDeclaration() as ClassDescriptor override val ownerDescriptor: ClassDescriptor
get() = super.ownerDescriptor as ClassDescriptor
// namespaces should be resolved elsewhere // namespaces should be resolved elsewhere
override fun getPackage(name: Name) = null 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 -> private val classes = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> { name ->
val classId = ClassId(packageFragment.fqName, name) val classId = ClassId(packageFragment.fqName, name)
@@ -53,7 +53,7 @@ import java.util.*
public abstract class LazyJavaScope( public abstract class LazyJavaScope(
protected val c: LazyJavaResolverContext, protected val c: LazyJavaResolverContext,
private val containingDeclaration: DeclarationDescriptor override val ownerDescriptor: DeclarationDescriptor
) : MemberScopeImpl() { ) : MemberScopeImpl() {
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there // 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 // but is placed in the base class to not duplicate code
@@ -66,8 +66,6 @@ public abstract class LazyJavaScope(
listOf() listOf()
) )
override fun getContainingDeclaration() = containingDeclaration
protected val memberIndex: NotNullLazyValue<MemberIndex> = c.storageManager.createLazyValue { computeMemberIndex() } protected val memberIndex: NotNullLazyValue<MemberIndex> = c.storageManager.createLazyValue { computeMemberIndex() }
protected abstract fun computeMemberIndex(): MemberIndex protected abstract fun computeMemberIndex(): MemberIndex
@@ -113,7 +111,7 @@ public abstract class LazyJavaScope(
fun resolveMethodToFunctionDescriptor(method: JavaMethod): JavaMethodDescriptor { fun resolveMethodToFunctionDescriptor(method: JavaMethod): JavaMethodDescriptor {
val annotations = c.resolveAnnotations(method) val annotations = c.resolveAnnotations(method)
val functionDescriptorImpl = JavaMethodDescriptor.createJavaMethod( 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) val c = c.child(functionDescriptorImpl, method)
@@ -237,7 +235,7 @@ public abstract class LazyJavaScope(
computeNonDeclaredProperties(name, properties) computeNonDeclaredProperties(name, properties)
if (DescriptorUtils.isAnnotationClass(containingDeclaration)) if (DescriptorUtils.isAnnotationClass(ownerDescriptor))
properties.toReadOnlyList() properties.toReadOnlyList()
else else
enhanceSignatures(properties).toReadOnlyList() enhanceSignatures(properties).toReadOnlyList()
@@ -275,7 +273,7 @@ public abstract class LazyJavaScope(
val annotations = c.resolveAnnotations(field) val annotations = c.resolveAnnotations(field)
val propertyName = field.getName() 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) 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> 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) { override fun printScopeStructure(p: Printer) {
p.println(javaClass.getSimpleName(), " {") p.println(javaClass.getSimpleName(), " {")
p.pushIndent() p.pushIndent()
p.println("containingDeclaration: ${getContainingDeclaration()}") p.println("containingDeclaration: ${ownerDescriptor}")
p.popIndent() p.popIndent()
p.println("}") p.println("}")
@@ -16,10 +16,7 @@
package org.jetbrains.kotlin.load.java.lazy.descriptors package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
@@ -72,32 +69,32 @@ public class LazyJavaStaticClassScope(
override fun getSubPackages(): Collection<FqName> = listOf() override fun getSubPackages(): Collection<FqName> = listOf()
override fun computeNonDeclaredFunctions(result: MutableCollection<SimpleFunctionDescriptor>, name: Name) { 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)) result.addIfNotNull(c.components.samConversionResolver.resolveSamConstructor(name, nestedClassesScope, NoLookupLocation.FOR_ALREADY_TRACKED))
val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, getContainingDeclaration()) val functionsFromSupertypes = getStaticFunctionsFromJavaSuperClasses(name, ownerDescriptor)
result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter)) result.addAll(DescriptorResolverUtils.resolveOverrides(name, functionsFromSupertypes, result, ownerDescriptor, c.components.errorReporter))
if (jClass.isEnum()) { if (jClass.isEnum()) {
when (name) { when (name) {
DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(getContainingDeclaration())) DescriptorUtils.ENUM_VALUE_OF -> result.add(createEnumValueOfMethod(ownerDescriptor))
DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(getContainingDeclaration())) DescriptorUtils.ENUM_VALUES -> result.add(createEnumValuesMethod(ownerDescriptor))
} }
} }
} }
override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) { override fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>) {
val propertiesFromSupertypes = getStaticPropertiesFromJavaSupertypes(name, getContainingDeclaration()) val propertiesFromSupertypes = getStaticPropertiesFromJavaSupertypes(name, ownerDescriptor)
val actualProperties = val actualProperties =
if (!result.isEmpty()) { if (!result.isEmpty()) {
DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, getContainingDeclaration(), c.components.errorReporter) DescriptorResolverUtils.resolveOverrides(name, propertiesFromSupertypes, result, ownerDescriptor, c.components.errorReporter)
} }
else { else {
propertiesFromSupertypes.groupBy { propertiesFromSupertypes.groupBy {
it.realOriginal it.realOriginal
}.flatMap { }.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 (jClass.isEnum) {
if (name == DescriptorUtils.ENUM_VALUES) { 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> { private fun getStaticFunctionsFromJavaSuperClasses(name: Name, descriptor: ClassDescriptor): Set<SimpleFunctionDescriptor> {
val staticScope = descriptor.getParentJavaStaticClassScope() ?: return emptySet() 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> { override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
if (!kindFilter.acceptsKinds(DescriptorKindFilter.CALLABLES.kindMask)) return listOf() if (!kindFilter.acceptsKinds(DescriptorKindFilter.CALLABLES.kindMask)) return listOf()
@@ -75,7 +76,7 @@ class FunctionClassScope(
} }
override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) { 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 @NotNull
@Override @Override
public DeclarationDescriptor getContainingDeclaration() { public DeclarationDescriptor getOwnerDescriptor() {
return EnumEntrySyntheticClassDescriptor.this; return EnumEntrySyntheticClassDescriptor.this;
} }
@@ -30,9 +30,8 @@ import org.jetbrains.kotlin.utils.sure
import java.util.ArrayList import java.util.ArrayList
public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() { public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, private val fqName: FqName) : MemberScopeImpl() {
override fun getContainingDeclaration(): DeclarationDescriptor { override val ownerDescriptor: DeclarationDescriptor
return moduleDescriptor.getPackage(fqName) get() = moduleDescriptor.getPackage(fqName)
}
override fun getPackage(name: Name): PackageViewDescriptor? { override fun getPackage(name: Name): PackageViewDescriptor? {
if (name.isSpecial()) { if (name.isSpecial()) {
@@ -65,7 +64,7 @@ public class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, pr
p.println(javaClass.getSimpleName(), " {") p.println(javaClass.getSimpleName(), " {")
p.pushIndent() p.pushIndent()
p.println("thisDescriptor = ", getContainingDeclaration()) p.println("thisDescriptor = ", ownerDescriptor)
p.popIndent() p.popIndent()
p.println("}") p.println("}")
@@ -31,7 +31,7 @@ public fun LookupTracker.record(from: LookupLocation, inScope: MemberScope, name
val location = from.location ?: return val location = from.location ?: return
val scopeContainingDeclaration = inScope.getContainingDeclaration() val scopeContainingDeclaration = inScope.ownerDescriptor
val scopeKind = val scopeKind =
when (scopeContainingDeclaration) { when (scopeContainingDeclaration) {
@@ -33,6 +33,9 @@ public abstract class AbstractScopeAdapter : MemberScope {
else else
workerScope workerScope
override val ownerDescriptor: DeclarationDescriptor
get() = workerScope.ownerDescriptor
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> { override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return workerScope.getContributedFunctions(name, location) return workerScope.getContributedFunctions(name, location)
} }
@@ -49,10 +52,6 @@ public abstract class AbstractScopeAdapter : MemberScope {
return workerScope.getContributedVariables(name, location) return workerScope.getContributedVariables(name, location)
} }
override fun getContainingDeclaration(): DeclarationDescriptor {
return workerScope.getContainingDeclaration()
}
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> { nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
return workerScope.getContributedDescriptors(kindFilter, nameFilter) return workerScope.getContributedDescriptors(kindFilter, nameFilter)
@@ -24,12 +24,15 @@ import org.jetbrains.kotlin.util.collectionUtils.getFromAllScopes
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
public open class ChainedScope( 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, private val debugName: String,
vararg scopes: MemberScope vararg scopes: MemberScope
) : MemberScope { ) : MemberScope {
private val scopeChain = scopes.clone() private val scopeChain = scopes.clone()
override val ownerDescriptor: DeclarationDescriptor
get() = descriptor!!
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor?
= getFirstMatch(scopeChain) { it.getContributedClassifier(name, location) } = getFirstMatch(scopeChain) { it.getContributedClassifier(name, location) }
@@ -42,8 +45,6 @@ public open class ChainedScope(
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
= getFromAllScopes(scopeChain) { it.getContributedFunctions(name, location) } = getFromAllScopes(scopeChain) { it.getContributedFunctions(name, location) }
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration!!
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= getFromAllScopes(scopeChain) { it.getContributedDescriptors(kindFilter, nameFilter) } = getFromAllScopes(scopeChain) { it.getContributedDescriptors(kindFilter, nameFilter) }
@@ -23,9 +23,9 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.Printer
public class InnerClassesScopeWrapper(val workerScope: MemberScope) : MemberScopeImpl() { 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 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 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 * All visible descriptors from current scope possibly filtered by the given name and kind filters
@@ -53,7 +53,7 @@ public interface MemberScope {
companion object { companion object {
public fun empty(ownerDescriptor: DeclarationDescriptor): MemberScope { public fun empty(ownerDescriptor: DeclarationDescriptor): MemberScope {
return object : MemberScopeImpl() { return object : MemberScopeImpl() {
override fun getContainingDeclaration() = ownerDescriptor override val ownerDescriptor = ownerDescriptor
override fun toString() = "Empty scope with owner: $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 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) { override fun printScopeStructure(p: Printer) {
p.println("Static scope for $containingClass") 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 getPackage(name: Name) = workerScope.getPackage(name)
override fun getContainingDeclaration() = workerScope.getContainingDeclaration() override val ownerDescriptor: DeclarationDescriptor
get() = workerScope.ownerDescriptor
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean) = _allDescriptors nameFilter: (Name) -> Boolean) = _allDescriptors
@@ -192,7 +192,7 @@ public class ErrorUtils {
@NotNull @NotNull
@Override @Override
public DeclarationDescriptor getContainingDeclaration() { public DeclarationDescriptor getOwnerDescriptor() {
return ERROR_MODULE; return ERROR_MODULE;
} }
@@ -248,7 +248,7 @@ public class ErrorUtils {
@NotNull @NotNull
@Override @Override
public DeclarationDescriptor getContainingDeclaration() { public DeclarationDescriptor getOwnerDescriptor() {
return ERROR_MODULE; return ERROR_MODULE;
} }
@@ -116,7 +116,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 getContainingDeclaration() = c.containingDeclaration override val ownerDescriptor: DeclarationDescriptor
get() = c.containingDeclaration
protected fun computeDescriptors( protected fun computeDescriptors(
kindFilter: DescriptorKindFilter, kindFilter: DescriptorKindFilter,
@@ -179,7 +180,7 @@ public abstract class DeserializedMemberScope protected constructor(
p.println(javaClass.simpleName, " {") p.println(javaClass.simpleName, " {")
p.pushIndent() p.pushIndent()
p.println("containingDeclaration = " + getContainingDeclaration()) p.println("containingDeclaration = " + ownerDescriptor)
p.popIndent() p.popIndent()
p.println("}") p.println("}")
@@ -40,17 +40,14 @@ private class PackageFragmentWithMissingDependencies(override val fqName: FqName
} }
} }
private class ScopeWithMissingDependencies(val fqName: FqName, val containing: DeclarationDescriptor) : MemberScopeImpl() { private class ScopeWithMissingDependencies(val fqName: FqName, override val ownerDescriptor: DeclarationDescriptor) : MemberScopeImpl() {
override fun getContainingDeclaration(): DeclarationDescriptor {
return containing
}
override fun printScopeStructure(p: Printer) { override fun printScopeStructure(p: Printer) {
p.println("Special scope for decompiler, containing class with any name") p.println("Special scope for decompiler, containing class with any name")
} }
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
return MissingDependencyErrorClassDescriptor(getContainingDeclaration(), fqName.child(name)) return MissingDependencyErrorClassDescriptor(ownerDescriptor, fqName.child(name))
} }
} }
@@ -210,7 +210,7 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
private fun renameKotlinClassTest(renameParamsObject: JsonObject, context: TestContext) { private fun renameKotlinClassTest(renameParamsObject: JsonObject, context: TestContext) {
renameParamsObject.getString("classId") //assertion renameParamsObject.getString("classId") //assertion
doRenameInKotlinClassOrPackage(renameParamsObject, context) { scope -> scope.getContainingDeclaration() as ClassDescriptor } doRenameInKotlinClassOrPackage(renameParamsObject, context) { scope -> scope.ownerDescriptor as ClassDescriptor }
} }
private fun renameKotlinPackageTest(renameParamsObject: JsonObject, context: TestContext) { private fun renameKotlinPackageTest(renameParamsObject: JsonObject, context: TestContext) {