Minor. Reformat StaticMembers.kt
This commit is contained in:
+59
-35
@@ -37,16 +37,16 @@ import java.util.*
|
|||||||
|
|
||||||
// adds java static members, enum members and members from companion object
|
// adds java static members, enum members and members from companion object
|
||||||
class StaticMembers(
|
class StaticMembers(
|
||||||
private val bindingContext: BindingContext,
|
private val bindingContext: BindingContext,
|
||||||
private val lookupElementFactory: LookupElementFactory,
|
private val lookupElementFactory: LookupElementFactory,
|
||||||
private val resolutionFacade: ResolutionFacade,
|
private val resolutionFacade: ResolutionFacade,
|
||||||
private val moduleDescriptor: ModuleDescriptor
|
private val moduleDescriptor: ModuleDescriptor
|
||||||
) {
|
) {
|
||||||
fun addToCollection(
|
fun addToCollection(
|
||||||
collection: MutableCollection<LookupElement>,
|
collection: MutableCollection<LookupElement>,
|
||||||
expectedInfos: Collection<ExpectedInfo>,
|
expectedInfos: Collection<ExpectedInfo>,
|
||||||
context: KtSimpleNameExpression,
|
context: KtSimpleNameExpression,
|
||||||
enumEntriesToSkip: Set<DeclarationDescriptor>
|
enumEntriesToSkip: Set<DeclarationDescriptor>
|
||||||
) {
|
) {
|
||||||
val expectedInfosByClass = HashMap<ClassDescriptor, MutableList<ExpectedInfo>>()
|
val expectedInfosByClass = HashMap<ClassDescriptor, MutableList<ExpectedInfo>>()
|
||||||
for (expectedInfo in expectedInfos) {
|
for (expectedInfo in expectedInfos) {
|
||||||
@@ -56,41 +56,62 @@ class StaticMembers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expectedInfo.additionalData is PropertyDelegateAdditionalData) {
|
if (expectedInfo.additionalData is PropertyDelegateAdditionalData) {
|
||||||
val delegatesClass = resolutionFacade.resolveImportReference(moduleDescriptor, FqName("kotlin.properties.Delegates")).singleOrNull()
|
val delegatesClass =
|
||||||
|
resolutionFacade.resolveImportReference(moduleDescriptor, FqName("kotlin.properties.Delegates")).singleOrNull()
|
||||||
if (delegatesClass is ClassDescriptor) {
|
if (delegatesClass is ClassDescriptor) {
|
||||||
addToCollection(collection, delegatesClass, listOf(expectedInfo), context, enumEntriesToSkip, SmartCompletionItemPriority.DELEGATES_STATIC_MEMBER)
|
addToCollection(
|
||||||
|
collection,
|
||||||
|
delegatesClass,
|
||||||
|
listOf(expectedInfo),
|
||||||
|
context,
|
||||||
|
enumEntriesToSkip,
|
||||||
|
SmartCompletionItemPriority.DELEGATES_STATIC_MEMBER
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((classDescriptor, expectedInfosForClass) in expectedInfosByClass) {
|
for ((classDescriptor, expectedInfosForClass) in expectedInfosByClass) {
|
||||||
if (!classDescriptor.name.isSpecial) {
|
if (!classDescriptor.name.isSpecial) {
|
||||||
addToCollection(collection, classDescriptor, expectedInfosForClass, context, enumEntriesToSkip, SmartCompletionItemPriority.STATIC_MEMBER)
|
addToCollection(
|
||||||
|
collection,
|
||||||
|
classDescriptor,
|
||||||
|
expectedInfosForClass,
|
||||||
|
context,
|
||||||
|
enumEntriesToSkip,
|
||||||
|
SmartCompletionItemPriority.STATIC_MEMBER
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addToCollection(
|
private fun addToCollection(
|
||||||
collection: MutableCollection<LookupElement>,
|
collection: MutableCollection<LookupElement>,
|
||||||
classDescriptor: ClassDescriptor,
|
classDescriptor: ClassDescriptor,
|
||||||
expectedInfos: Collection<ExpectedInfo>,
|
expectedInfos: Collection<ExpectedInfo>,
|
||||||
context: KtSimpleNameExpression,
|
context: KtSimpleNameExpression,
|
||||||
enumEntriesToSkip: Set<DeclarationDescriptor>,
|
enumEntriesToSkip: Set<DeclarationDescriptor>,
|
||||||
priority: SmartCompletionItemPriority
|
priority: SmartCompletionItemPriority
|
||||||
) {
|
) {
|
||||||
fun processMember(descriptor: DeclarationDescriptor) {
|
fun processMember(descriptor: DeclarationDescriptor) {
|
||||||
if (descriptor is DeclarationDescriptorWithVisibility && !descriptor.isVisible(context, null, bindingContext, resolutionFacade)) return
|
if (descriptor is DeclarationDescriptorWithVisibility && !descriptor.isVisible(
|
||||||
|
context,
|
||||||
|
null,
|
||||||
|
bindingContext,
|
||||||
|
resolutionFacade
|
||||||
|
)
|
||||||
|
) return
|
||||||
|
|
||||||
val matcher: (ExpectedInfo) -> ExpectedInfoMatch
|
val matcher: (ExpectedInfo) -> ExpectedInfoMatch = when {
|
||||||
if (descriptor is CallableDescriptor) {
|
descriptor is CallableDescriptor -> {
|
||||||
val returnType = descriptor.fuzzyReturnType() ?: return
|
val returnType = descriptor.fuzzyReturnType() ?: return
|
||||||
matcher = { expectedInfo -> returnType.matchExpectedInfo(expectedInfo) }
|
{ expectedInfo -> returnType.matchExpectedInfo(expectedInfo) }
|
||||||
}
|
}
|
||||||
else if (DescriptorUtils.isEnumEntry(descriptor) && !enumEntriesToSkip.contains(descriptor)) {
|
DescriptorUtils.isEnumEntry(descriptor) && !enumEntriesToSkip.contains(descriptor) -> {
|
||||||
matcher = { ExpectedInfoMatch.match(TypeSubstitutor.EMPTY) } /* we do not need to check type of enum entry because it's taken from proper enum */
|
/* we do not need to check type of enum entry because it's taken from proper enum */
|
||||||
}
|
{ ExpectedInfoMatch.match(TypeSubstitutor.EMPTY) }
|
||||||
else {
|
}
|
||||||
return
|
else -> return
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.addLookupElements(descriptor, expectedInfos, matcher) { createLookupElements(it, priority) }
|
collection.addLookupElements(descriptor, expectedInfos, matcher) { createLookupElements(it, priority) }
|
||||||
@@ -101,8 +122,8 @@ class StaticMembers(
|
|||||||
val companionObject = classDescriptor.companionObjectDescriptor
|
val companionObject = classDescriptor.companionObjectDescriptor
|
||||||
if (companionObject != null) {
|
if (companionObject != null) {
|
||||||
companionObject.defaultType.memberScope.getContributedDescriptors()
|
companionObject.defaultType.memberScope.getContributedDescriptors()
|
||||||
.filter { !it.isExtension }
|
.filter { !it.isExtension }
|
||||||
.forEach(::processMember)
|
.forEach(::processMember)
|
||||||
}
|
}
|
||||||
|
|
||||||
val members = classDescriptor.defaultType.memberScope.getContributedDescriptors().filter { member ->
|
val members = classDescriptor.defaultType.memberScope.getContributedDescriptors().filter { member ->
|
||||||
@@ -115,11 +136,14 @@ class StaticMembers(
|
|||||||
members.forEach(::processMember)
|
members.forEach(::processMember)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createLookupElements(memberDescriptor: DeclarationDescriptor, priority: SmartCompletionItemPriority): Collection<LookupElement> {
|
private fun createLookupElements(
|
||||||
|
memberDescriptor: DeclarationDescriptor,
|
||||||
|
priority: SmartCompletionItemPriority
|
||||||
|
): Collection<LookupElement> {
|
||||||
return lookupElementFactory.createStandardLookupElementsForDescriptor(memberDescriptor, useReceiverTypes = false)
|
return lookupElementFactory.createStandardLookupElementsForDescriptor(memberDescriptor, useReceiverTypes = false)
|
||||||
.map {
|
.map {
|
||||||
it.decorateAsStaticMember(memberDescriptor, classNameAsLookupString = true)!!
|
it.decorateAsStaticMember(memberDescriptor, classNameAsLookupString = true)!!
|
||||||
.assignSmartCompletionPriority(priority)
|
.assignSmartCompletionPriority(priority)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user