Renamed methods in MemberScope from getSmth to getContributedSmth

This commit is contained in:
Stanislav Erokhin
2015-11-04 14:46:59 +03:00
parent 6f9d9759ce
commit 2c3f58eeb7
104 changed files with 289 additions and 288 deletions
@@ -42,17 +42,17 @@ public fun LexicalScope.getAllAccessibleVariables(name: Name): Collection<Variab
}
public fun LexicalScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor> {
return getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE) } +
collectFunctions(name, NoLookupLocation.FROM_IDE)
return getImplicitReceiversWithInstance().flatMap { it.type.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_IDE) } +
collectFunctions(name, NoLookupLocation.FROM_IDE)
}
public fun LexicalScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> = getImplicitReceiversWithInstance().flatMap {
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE)
it.type.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE)
}
public fun LexicalScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
getImplicitReceiversWithInstance().forEach {
it.type.memberScope.getProperties(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
it.type.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
}
return null
}
@@ -61,7 +61,7 @@ public fun descriptorsEqualWithSubstitution(descriptor1: DeclarationDescriptor?,
public fun ClassDescriptor.findCallableMemberBySignature(signature: CallableMemberDescriptor): CallableMemberDescriptor? {
val descriptorKind = if (signature is FunctionDescriptor) DescriptorKindFilter.FUNCTIONS else DescriptorKindFilter.VARIABLES
return getDefaultType().getMemberScope()
.getDescriptors(descriptorKind)
.getContributedDescriptors(descriptorKind)
.filterIsInstance<CallableMemberDescriptor>()
.firstOrNull {
it.getContainingDeclaration() == this
@@ -239,14 +239,14 @@ public class IDELightClassGenerationSupport(private val project: Project) : Ligh
for (declaration in file.declarations) {
if (declaration is KtFunction) {
val name = declaration.nameAsSafeName
val functions = packageDescriptor.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE)
val functions = packageDescriptor.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_IDE)
for (descriptor in functions) {
ForceResolveUtil.forceResolveAllContents(descriptor)
}
}
else if (declaration is KtProperty) {
val name = declaration.nameAsSafeName
val properties = packageDescriptor.memberScope.getProperties(name, NoLookupLocation.FROM_IDE)
val properties = packageDescriptor.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE)
for (descriptor in properties) {
ForceResolveUtil.forceResolveAllContents(descriptor)
}
@@ -67,7 +67,7 @@ fun PsiMember.getJavaMemberDescriptor(): DeclarationDescriptor? {
}
public fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): FunctionDescriptor? {
return getContainingScope(method)?.getFunctions(method.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(method)
return getContainingScope(method)?.getContributedFunctions(method.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(method)
}
public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructor): ConstructorDescriptor? {
@@ -75,7 +75,7 @@ public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructo
}
public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescriptor? {
return getContainingScope(field)?.getProperties(field.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(field) as? PropertyDescriptor
return getContainingScope(field)?.getContributedVariables(field.name, NoLookupLocation.FROM_IDE)?.findByJavaElement(field) as? PropertyDescriptor
}
private fun JavaDescriptorResolver.getContainingScope(member: JavaMember): MemberScope? {
@@ -199,7 +199,7 @@ public fun buildDecompiledText(
}
}
val allDescriptors = descriptor.secondaryConstructors + descriptor.defaultType.memberScope.getDescriptors()
val allDescriptors = descriptor.secondaryConstructors + descriptor.defaultType.memberScope.getContributedDescriptors()
val (enumEntries, members) = allDescriptors.partition(::isEnumEntry)
for ((index, enumEntry) in enumEntries.withIndex()) {
@@ -77,7 +77,7 @@ public class DeserializerForClassfileDecompiler(
val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents
) { emptyList() }
return membersScope.getDescriptors()
return membersScope.getContributedDescriptors()
}
companion object {
@@ -75,7 +75,7 @@ public class KotlinJavaScriptDeserializerForDecompiler(
val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, deserializationComponents
) { emptyList() }
return membersScope.getDescriptors()
return membersScope.getContributedDescriptors()
}
companion object {
@@ -49,7 +49,7 @@ private class ScopeWithMissingDependencies(val fqName: FqName, val containing: D
p.println("Special scope for decompiler, containing class with any name")
}
override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
return MissingDependencyErrorClassDescriptor(getContainingDeclaration(), fqName.child(name))
}
}
@@ -108,7 +108,7 @@ public class BuiltInsReferenceResolver(val project: Project, val startupManager:
containingDeclaration.getConstructors()
}
else {
memberScope.getDescriptors()
memberScope.getContributedDescriptors()
}
return descriptors.firstOrNull { renderedOriginal == DescriptorRenderer.FQ_NAMES_IN_TYPES.render(it) }
@@ -45,7 +45,7 @@ public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<Tr
val children = ArrayList<TreeElement>()
val defaultType = descriptor.getDefaultType()
for (memberDescriptor in defaultType.getMemberScope().getDescriptors()) {
for (memberDescriptor in defaultType.getMemberScope().getContributedDescriptors()) {
if (memberDescriptor !is CallableMemberDescriptor) continue
when (memberDescriptor.getKind()) {
@@ -54,7 +54,7 @@ object PackageDirectiveCompletion {
val packageMemberScope = resolutionFacade.moduleDescriptor.getPackage(file.packageFqName.parent()).memberScope
val variants = packageMemberScope.getDescriptors(DescriptorKindFilter.PACKAGES, prefixMatcher.asNameFilter())
val variants = packageMemberScope.getContributedDescriptors(DescriptorKindFilter.PACKAGES, prefixMatcher.asNameFilter())
val lookupElementFactory = BasicLookupElementFactory(resolutionFacade.project, InsertHandlerProvider(callType = CallType.PACKAGE_DIRECTIVE, expectedInfosCalculator = { emptyList() }))
for (variant in variants) {
val lookupElement = lookupElementFactory.createLookupElement(variant)
@@ -90,16 +90,16 @@ class StaticMembers(
}
}
classDescriptor.getStaticScope().getDescriptors().forEach(::processMember)
classDescriptor.getStaticScope().getContributedDescriptors().forEach(::processMember)
val companionObject = classDescriptor.getCompanionObjectDescriptor()
if (companionObject != null) {
companionObject.getDefaultType().getMemberScope().getDescriptors()
companionObject.getDefaultType().getMemberScope().getContributedDescriptors()
.filter { !it.isExtension }
.forEach(::processMember)
}
var members = classDescriptor.getDefaultType().getMemberScope().getDescriptors()
var members = classDescriptor.getDefaultType().getMemberScope().getContributedDescriptors()
if (classDescriptor.getKind() != ClassKind.ENUM_CLASS) {
members = members.filter { DescriptorUtils.isNonCompanionObject(it) }
}
@@ -278,7 +278,7 @@ class TypeInstantiationItems(
is ClassDescriptor -> container.getStaticScope()
else -> return
}
val samConstructor = scope.getFunctions(`class`.name, NoLookupLocation.FROM_IDE)
val samConstructor = scope.getContributedFunctions(`class`.name, NoLookupLocation.FROM_IDE)
.filterIsInstance<SamConstructorDescriptor>()
.singleOrNull() ?: return
lookupElementFactory.createLookupElementsInSmartCompletion(samConstructor, bindingContext, useReceiverTypes = false)
@@ -53,7 +53,7 @@ class TypesWithContainsDetector(
private fun hasContainsNoCache(type: FuzzyType): Boolean {
return type.nullability() != TypeNullability.NULLABLE &&
type.type.memberScope.getFunctions(containsName, NoLookupLocation.FROM_IDE).any { isGoodContainsFunction(it, type.freeParameters) }
type.type.memberScope.getContributedFunctions(containsName, NoLookupLocation.FROM_IDE).any { isGoodContainsFunction(it, type.freeParameters) }
|| typesWithExtensionContains.any { type.checkIsSubtypeOf(it) != null }
}
@@ -79,7 +79,7 @@ public class IterableTypesDetection(
}
private fun canBeIterable(type: FuzzyType): Boolean {
return type.type.memberScope.getFunctions(iteratorName, NoLookupLocation.FROM_IDE).isNotEmpty() ||
return type.type.memberScope.getContributedFunctions(iteratorName, NoLookupLocation.FROM_IDE).isNotEmpty() ||
typesWithExtensionIterator.any { type.checkIsSubtypeOf(it) != null }
}
}
@@ -26,7 +26,7 @@ import java.util.*
public class OverrideMembersHandler : OverrideImplementMembersHandler() {
override fun collectMembersToGenerate(descriptor: ClassDescriptor, project: Project): Collection<OverrideMemberChooserObject> {
val result = ArrayList<OverrideMemberChooserObject>()
for (member in descriptor.unsubstitutedMemberScope.getDescriptors()) {
for (member in descriptor.unsubstitutedMemberScope.getContributedDescriptors()) {
if (member is CallableMemberDescriptor
&& (member.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE || member.kind == CallableMemberDescriptor.Kind.DELEGATION)) {
val overridden = member.overriddenDescriptors
@@ -56,7 +56,7 @@ private tailrec fun ClassDescriptor.findDeclaredFunction (
filter: (FunctionDescriptor) -> Boolean
): FunctionDescriptor? {
unsubstitutedMemberScope
.getFunctions(Name.identifier(name), NoLookupLocation.FROM_IDE)
.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_IDE)
.firstOrNull { it.containingDeclaration == this && it.kind == CallableMemberDescriptor.Kind.DECLARATION && filter(it) }
?.let { return it }
@@ -174,7 +174,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
val containingClass = originalFunctionDescriptor.containingDeclaration as? ClassDescriptor ?: return emptyList()
// SAM adapters for static functions
for (staticFunWithSameName in containingClass.staticScope.getFunctions(functionResolvedCall.resultingDescriptor.name, NoLookupLocation.FROM_IDE)) {
for (staticFunWithSameName in containingClass.staticScope.getContributedFunctions(functionResolvedCall.resultingDescriptor.name, NoLookupLocation.FROM_IDE)) {
if (staticFunWithSameName is SamAdapterDescriptor<*>) {
if (isSamAdapterSuitableForCall(staticFunWithSameName, originalFunctionDescriptor, samConstructorCallArguments.size())) {
return samConstructorCallArguments.check { canBeReplaced(functionCall, it) } ?: emptyList()
@@ -179,7 +179,7 @@ class ChangeMemberFunctionSignatureFix private constructor(
val name = functionDescriptor.name
return containingClass.defaultType.supertypes()
.flatMap { supertype -> supertype.memberScope.getFunctions(name, NoLookupLocation.FROM_IDE) }
.flatMap { supertype -> supertype.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_IDE) }
.filter { it.kind.isReal && it.modality.isOverridable }
}
}
@@ -126,7 +126,7 @@ object MissingIteratorExclExclFixFactory : KotlinSingleIntentionActionFactory()
if (descriptor !is ClassDescriptor) return false
val memberScope = descriptor.unsubstitutedMemberScope
val functions = memberScope.getFunctions(OperatorNameConventions.ITERATOR, NoLookupLocation.FROM_IDE)
val functions = memberScope.getContributedFunctions(OperatorNameConventions.ITERATOR, NoLookupLocation.FROM_IDE)
return functions.any { it.isOperator() && OperatorChecks.canBeOperator(it) }
}
@@ -237,7 +237,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
val topLevelScope = resolutionFacade.getFileResolutionScope(file)
val conflictCandidates: List<ClassifierDescriptor> = classNamesToImport
.flatMap {
importedScopes.map { scope -> scope.getClassifier(it, NoLookupLocation.FROM_IDE) }.filterNotNull()
importedScopes.map { scope -> scope.getContributedClassifier(it, NoLookupLocation.FROM_IDE) }.filterNotNull()
}
.filter { importedClass ->
isVisible(importedClass)
@@ -272,7 +272,7 @@ public class ImportInsertHelperImpl(private val project: Project) : ImportInsert
}
val parentScope = getMemberScope(fqName.parent(), moduleDescriptor) ?: return null
val classifier = parentScope.getClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)
val classifier = parentScope.getContributedClassifier(fqName.shortName(), NoLookupLocation.FROM_IDE)
val classDescriptor = classifier as? ClassDescriptor ?: return null
return classDescriptor.getDefaultType().getMemberScope()
}
@@ -79,7 +79,7 @@ public abstract class TextConsistencyBaseTest : KotlinLightCodeInsightFixtureTes
module.resolveTopLevelClass(classId.asSingleFqName(), NoLookupLocation.FROM_TEST)
override fun resolveDeclarationsInFacade(facadeFqName: FqName): Collection<DeclarationDescriptor> =
module.getPackage(facadeFqName.parent()).memberScope.getDescriptors().filter {
module.getPackage(facadeFqName.parent()).memberScope.getContributedDescriptors().filter {
it is CallableMemberDescriptor &&
it.module != module.builtIns.builtInsModule &&
isFromFacade(it, facadeFqName)
@@ -43,7 +43,7 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() {
myFixture.configureByFile(getTestName(false) + ".kt")
val declaration = (myFixture.getFile() as KtFile).getDeclarations().single { it.getName() == "Bar" }
val descriptor = declaration.resolveToDescriptor() as ClassDescriptor
val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getFunctions(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single()
val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getContributedFunctions(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single()
val doc = KDocFinder.findKDoc(overriddenFunctionDescriptor)
Assert.assertEquals("Doc for method xyzzy", doc!!.getContent())
}
@@ -52,7 +52,7 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() {
myFixture.configureByFile(getTestName(false) + ".kt")
val declaration = (myFixture.getFile() as KtFile).getDeclarations().single { it.getName() == "Bar" }
val descriptor = declaration.resolveToDescriptor() as ClassDescriptor
val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getFunctions(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single()
val overriddenFunctionDescriptor = descriptor.defaultType.memberScope.getContributedFunctions(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single()
val doc = KDocFinder.findKDoc(overriddenFunctionDescriptor)
Assert.assertEquals("Doc for method xyzzy", doc!!.getContent())
}
@@ -61,7 +61,7 @@ public class KDocFinderTest() : LightPlatformCodeInsightFixtureTestCase() {
myFixture.configureByFile(getTestName(false) + ".kt")
val declaration = (myFixture.getFile() as KtFile).getDeclarations().single { it.getName() == "Foo" }
val descriptor = declaration.resolveToDescriptor() as ClassDescriptor
val propertyDescriptor = descriptor.defaultType.memberScope.getProperties(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single()
val propertyDescriptor = descriptor.defaultType.memberScope.getContributedVariables(Name.identifier("xyzzy"), NoLookupLocation.FROM_TEST).single()
val doc = KDocFinder.findKDoc(propertyDescriptor)
Assert.assertEquals("Doc for property xyzzy", doc!!.getContent())
}
@@ -198,13 +198,13 @@ public abstract class AbstractRenameTest : KotlinMultiFileTestCase() {
private fun renameKotlinFunctionTest(renameParamsObject: JsonObject, context: TestContext) {
val oldMethodName = Name.identifier(renameParamsObject.getString("oldName"))
doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getFunctions(oldMethodName, NoLookupLocation.FROM_TEST).first() }
doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getContributedFunctions(oldMethodName, NoLookupLocation.FROM_TEST).first() }
}
private fun renameKotlinPropertyTest(renameParamsObject: JsonObject, context: TestContext) {
val oldPropertyName = Name.identifier(renameParamsObject.getString("oldName"))
doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getProperties(oldPropertyName, NoLookupLocation.FROM_TEST).first() }
doRenameInKotlinClassOrPackage(renameParamsObject, context) { it.getContributedVariables(oldPropertyName, NoLookupLocation.FROM_TEST).first() }
}
private fun renameKotlinClassTest(renameParamsObject: JsonObject, context: TestContext) {