Replace function MemberScope.getContainingDeclaration() to property ownerDescriptor
This commit is contained in:
+18
-17
@@ -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
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+6
-8
@@ -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("}")
|
||||
|
||||
+12
-14
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user