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? {
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")
@@ -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 "
@@ -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
@@ -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 {
@@ -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
@@ -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")
}