Replace function MemberScope.getContainingDeclaration() to property ownerDescriptor
This commit is contained in:
+1
-1
@@ -39,7 +39,7 @@ public object SamConversionResolverImpl : SamConversionResolver {
|
||||
override fun resolveSamConstructor(name: Name, scope: MemberScope, location: LookupLocation): SamConstructorDescriptor? {
|
||||
val classifier = scope.getContributedClassifier(name, location) as? LazyJavaClassDescriptor ?: return null
|
||||
if (classifier.getFunctionTypeForSamInterface() == null) return null
|
||||
return SingleAbstractMethodUtils.createSamConstructorFunction(scope.getContainingDeclaration(), classifier)
|
||||
return SingleAbstractMethodUtils.createSamConstructorFunction(scope.ownerDescriptor, classifier)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ class PropagationHeuristics {
|
||||
arrayTypeFromSuper.getConstructor(),
|
||||
arrayTypeFromSuper.isMarkedNullable(),
|
||||
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. " +
|
||||
"To fix it, add annotation with Kotlin signature to super method with type "
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ public fun resolvePossiblyAmbiguousCallableReference(
|
||||
fun resolveInScope(traceTitle: String, staticScope: MemberScope): OverloadResolutionResults<CallableDescriptor> {
|
||||
|
||||
// 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) {
|
||||
p.println(toString())
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class DynamicCallableDescriptors(private val builtIns: KotlinBuiltIns) {
|
||||
val dynamicType = createDynamicType(builtIns)
|
||||
|
||||
fun createDynamicDescriptorScope(call: Call, owner: DeclarationDescriptor) = object : MemberScopeImpl() {
|
||||
override fun getContainingDeclaration() = owner
|
||||
override val ownerDescriptor: DeclarationDescriptor get() = owner
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(javaClass.getSimpleName(), ": dynamic candidates for " + call)
|
||||
|
||||
@@ -86,7 +86,7 @@ public class ResolveSessionUtils {
|
||||
scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope();
|
||||
}
|
||||
|
||||
return (ClassDescriptor) scope.getContainingDeclaration();
|
||||
return (ClassDescriptor) scope.getOwnerDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ protected constructor(
|
||||
}.toReadOnlyList()
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration() = thisDescriptor
|
||||
override val ownerDescriptor: DeclarationDescriptor get() = thisDescriptor
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassDescriptor? {
|
||||
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 {
|
||||
|
||||
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?
|
||||
= 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)
|
||||
|
||||
@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 {
|
||||
override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
|
||||
|
||||
@@ -161,7 +161,7 @@ public class TypeIntersector {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
public DeclarationDescriptor getOwnerDescriptor() {
|
||||
throw new UnsupportedOperationException("Should not call getContainingDeclaration on intersection scope " + this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class LazyOperationsLog(
|
||||
public fun getText(): String {
|
||||
val groupedByOwner = records.groupByTo(IdentityHashMap()) {
|
||||
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()) }
|
||||
|
||||
return groupedByOwner.map {
|
||||
|
||||
+2
-2
@@ -40,14 +40,14 @@ private fun validateDeserializedScope(scope: MemberScope) {
|
||||
val relevantDescriptors = scope.getContributedDescriptors().filter { member ->
|
||||
member is CallableMemberDescriptor && member.getKind().isReal() || (!isPackageViewScope && member is ClassDescriptor)
|
||||
}
|
||||
checkSorted(relevantDescriptors, scope.getContainingDeclaration())
|
||||
checkSorted(relevantDescriptors, scope.ownerDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
//NOTE: see TypeUtils#IntersectionScope#getContainingDeclaration()
|
||||
private fun MemberScope.safeGetContainingDeclaration(): DeclarationDescriptor? {
|
||||
return try {
|
||||
getContainingDeclaration()
|
||||
ownerDescriptor
|
||||
}
|
||||
catch (e: UnsupportedOperationException) {
|
||||
null
|
||||
|
||||
+1
-3
@@ -213,10 +213,8 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
|
||||
|
||||
private class ScopeWithClassifiers(
|
||||
classifiers: List<ClassifierDescriptor>,
|
||||
val ownerDescriptor: DeclarationDescriptor
|
||||
override val ownerDescriptor: DeclarationDescriptor
|
||||
) : MemberScopeImpl() {
|
||||
override fun getContainingDeclaration() = ownerDescriptor
|
||||
|
||||
private val classifierMap = HashMap<Name, ClassifierDescriptor>()
|
||||
val redeclarationHandler = RedeclarationHandler.THROW_EXCEPTION
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ public class TypeUnifierTest extends KotlinLiteFixture {
|
||||
}
|
||||
|
||||
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,
|
||||
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
public fun MemberScope.asLexicalScope(): LexicalScope {
|
||||
val importingScope = memberScopeAsImportingScope()
|
||||
return object : BaseLexicalScope(importingScope, getContainingDeclaration()) {
|
||||
return object : BaseLexicalScope(importingScope, ownerDescriptor) {
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println("Util scope for tests")
|
||||
}
|
||||
|
||||
+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()
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
+1
-1
@@ -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) }
|
||||
|
||||
|
||||
+3
-3
@@ -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"
|
||||
|
||||
|
||||
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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("}")
|
||||
|
||||
+2
-5
@@ -40,17 +40,14 @@ private class PackageFragmentWithMissingDependencies(override val fqName: FqName
|
||||
}
|
||||
}
|
||||
|
||||
private class ScopeWithMissingDependencies(val fqName: FqName, val containing: DeclarationDescriptor) : MemberScopeImpl() {
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||
return containing
|
||||
}
|
||||
private class ScopeWithMissingDependencies(val fqName: FqName, override val ownerDescriptor: DeclarationDescriptor) : MemberScopeImpl() {
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println("Special scope for decompiler, containing class with any name")
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user