[kotlin] Move completion tests under the 'kotlin.completion.*' module group (KTIJ-22392)

GitOrigin-RevId: 6bbf0b17b51d6599d18b02769f5e0da2701c998b
This commit is contained in:
Yan Zhulanow
2022-08-10 14:47:25 +09:00
committed by intellij-monorepo-bot
parent d3833464e1
commit edccbb93f8
2992 changed files with 4475 additions and 4378 deletions

3
.idea/modules.xml generated
View File

@@ -1119,6 +1119,8 @@
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/completion/impl-k1/kotlin.completion.impl-k1.iml" filepath="$PROJECT_DIR$/plugins/kotlin/completion/impl-k1/kotlin.completion.impl-k1.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/completion/impl-k2/kotlin.completion.impl-k2.iml" filepath="$PROJECT_DIR$/plugins/kotlin/completion/impl-k2/kotlin.completion.impl-k2.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/completion/impl-shared/kotlin.completion.impl-shared.iml" filepath="$PROJECT_DIR$/plugins/kotlin/completion/impl-shared/kotlin.completion.impl-shared.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/completion/tests-k1/kotlin.completion.tests-k1.iml" filepath="$PROJECT_DIR$/plugins/kotlin/completion/tests-k1/kotlin.completion.tests-k1.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/completion/tests-shared/kotlin.completion.tests-shared.iml" filepath="$PROJECT_DIR$/plugins/kotlin/completion/tests-shared/kotlin.completion.tests-shared.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/copyright/kotlin.copyright.iml" filepath="$PROJECT_DIR$/plugins/kotlin/copyright/kotlin.copyright.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/copyright/tests/kotlin.copyright.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/copyright/tests/kotlin.copyright.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/core/kotlin.core.iml" filepath="$PROJECT_DIR$/plugins/kotlin/core/kotlin.core.iml" />
@@ -1174,6 +1176,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/maven/tests/kotlin.maven.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/maven/tests/kotlin.maven.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/migration/kotlin.migration.iml" filepath="$PROJECT_DIR$/plugins/kotlin/migration/kotlin.migration.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/ml-completion/kotlin.ml-completion.iml" filepath="$PROJECT_DIR$/plugins/kotlin/ml-completion/kotlin.ml-completion.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/ml-completion/tests/kotlin.ml-completion.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/ml-completion/tests/kotlin.ml-completion.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/native/kotlin.native.iml" filepath="$PROJECT_DIR$/plugins/kotlin/native/kotlin.native.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/native/tests/kotlin.native.tests.iml" filepath="$PROJECT_DIR$/plugins/kotlin/native/tests/kotlin.native.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/kotlin/navigation/kotlin.navigation.iml" filepath="$PROJECT_DIR$/plugins/kotlin/navigation/kotlin.navigation.iml" />

View File

@@ -52,5 +52,8 @@
<orderEntry type="module" module-name="kotlin.code-insight.intentions-shared.tests.k1" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.code-insight.inspections-shared.tests.k1" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.code-insight.impl-base" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.completion.tests-shared" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.completion.tests-k1" scope="RUNTIME" />
<orderEntry type="module" module-name="kotlin.ml-completion.tests" scope="RUNTIME" />
</component>
</module>

View File

@@ -0,0 +1,11 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.core.completion
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.name.Name
interface DeclarationLookupObject : Iconable {
val psiElement: PsiElement?
val name: Name?
}

View File

@@ -2,7 +2,6 @@
package org.jetbrains.kotlin.idea.core.completion
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiElement
import com.intellij.util.PlatformIcons
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
@@ -10,15 +9,13 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import javax.swing.Icon
interface DeclarationLookupObject : Iconable {
val psiElement: PsiElement?
interface DescriptorBasedDeclarationLookupObject : DeclarationLookupObject {
val descriptor: DeclarationDescriptor?
val name: Name?
val importableFqName: FqName?
val isDeprecated: Boolean
}
data class PackageLookupObject(val fqName: FqName) : DeclarationLookupObject {
data class PackageLookupObject(val fqName: FqName) : DescriptorBasedDeclarationLookupObject {
override val psiElement: PsiElement? get() = null
override val descriptor: DeclarationDescriptor? get() = null
override val name: Name get() = fqName.shortName()

View File

@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.idea.completion.smart.*
import org.jetbrains.kotlin.idea.core.ExpectedInfo
import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
import org.jetbrains.kotlin.idea.core.NotPropertiesService
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference.ShorteningMode.FORCED_SHORTENING
import org.jetbrains.kotlin.idea.references.mainReference
@@ -484,7 +484,7 @@ class BasicCompletionSession(
receiverTypes = receiverTypes,
standardLookupElementsPostProcessor = { lookupElement ->
val lookupDescriptor = lookupElement.`object`
.safeAs<DeclarationLookupObject>()
.safeAs<DescriptorBasedDeclarationLookupObject>()
?.descriptor as? MemberDescriptor
?: return@copy lookupElement

View File

@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.idea.completion.handlers.BaseDeclarationInsertHandle
import org.jetbrains.kotlin.idea.completion.handlers.KotlinClassifierInsertHandler
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionCompositeDeclarativeInsertHandler
import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.PackageLookupObject
import org.jetbrains.kotlin.idea.core.unwrapIfFakeOverride
import org.jetbrains.kotlin.idea.highlighter.dsl.DslKotlinHighlightingVisitorExtension
@@ -42,7 +42,7 @@ class BasicLookupElementFactory(
parameterNamesInFunctionalTypes = false
}
private fun getIcon(lookupObject: DeclarationLookupObject, descriptor: DeclarationDescriptor, flags: Int): Icon? {
private fun getIcon(lookupObject: DescriptorBasedDeclarationLookupObject, descriptor: DeclarationDescriptor, flags: Int): Icon? {
// KotlinDescriptorIconProvider does not use declaration if it is KtElement,
// so, do not try to look up psiElement for known Kotlin descriptors as it could be a heavy deserialization (e.g. from kotlin libs)
val declaration = when (descriptor) {
@@ -143,7 +143,7 @@ class BasicLookupElementFactory(
return createLookupElementForPackage(descriptor.fqName)
}
val lookupObject: DeclarationLookupObject
val lookupObject: DescriptorBasedDeclarationLookupObject
val name: String = when (descriptor) {
is ConstructorDescriptor -> {
// for constructor use name and icon of containing class

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.util.descriptorsEqualWithSubstitution
*/
abstract class DeclarationLookupObjectImpl(
final override val descriptor: DeclarationDescriptor?
) : DeclarationLookupObject {
) : DescriptorBasedDeclarationLookupObject {
override val name: Name?
get() = descriptor?.name ?: (psiElement as? PsiNamedElement)?.name?.let { Name.identifier(it) }

View File

@@ -8,11 +8,11 @@ import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementAction
import com.intellij.openapi.project.Project
import com.intellij.util.Consumer
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
class KotlinExcludeFromCompletionLookupActionProvider : LookupActionProvider {
override fun fillActions(element: LookupElement, lookup: Lookup, consumer: Consumer<LookupElementAction>) {
val lookupObject = element.`object` as? DeclarationLookupObject ?: return
val lookupObject = element.`object` as? DescriptorBasedDeclarationLookupObject ?: return
val project = lookup.psiFile?.project ?: return

View File

@@ -9,7 +9,6 @@ import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementDecorator
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.openapi.editor.Editor
import com.intellij.ui.JBColor
import com.intellij.util.SmartList
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
import org.jetbrains.kotlin.builtins.isFunctionType
@@ -65,8 +64,6 @@ class LookupElementFactory(
val parameter = descriptor.original.valueParameters.singleOrNull() ?: return false
return parameter.type.isBuiltinFunctionalType
}
val CAST_REQUIRED_COLOR = JBColor(0x4E4040, 0x969696)
}
val insertHandlerProvider = basicFactory.insertHandlerProvider
@@ -309,7 +306,7 @@ class LookupElementFactory(
if (style == Style.BOLD) {
presentation.isItemTextBold = true
} else {
presentation.itemTextForeground = CAST_REQUIRED_COLOR
presentation.itemTextForeground = KOTLIN_CAST_REQUIRED_COLOR
// gray all tail fragments too:
val fragments = presentation.tailFragments
presentation.clearTail()

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.idea.completion.handlers.WithExpressionPrefixInsertHandler
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.intentions.InsertExplicitTypeArgumentsIntention
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
@@ -96,7 +96,7 @@ class LookupElementsCollector(
return
}
if (!allowExpectDeclarations) {
val descriptor = (element.`object` as? DeclarationLookupObject)?.descriptor
val descriptor = (element.`object` as? DescriptorBasedDeclarationLookupObject)?.descriptor
if ((descriptor as? MemberDescriptor)?.isExpect == true) return
}
@@ -117,7 +117,7 @@ class LookupElementsCollector(
result = postProcessor(result)
}
val declarationLookupObject = result.`object` as? DeclarationLookupObject
val declarationLookupObject = result.`object` as? DescriptorBasedDeclarationLookupObject
if (declarationLookupObject != null) {
result = DeclarationLookupObjectLookupElementDecorator(result, declarationLookupObject)
}
@@ -178,7 +178,7 @@ private class JustTypingLookupElementDecorator(element: LookupElement, private v
private class DeclarationLookupObjectLookupElementDecorator(
element: LookupElement,
private val declarationLookupObject: DeclarationLookupObject
private val declarationLookupObject: DescriptorBasedDeclarationLookupObject
) : LookupElementDecorator<LookupElement>(element) {
override fun getPsiElement() = declarationLookupObject.psiElement
}

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.KotlinDescriptorIconProvider
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMembersHandler
import org.jetbrains.kotlin.idea.core.overrideImplement.generateMember
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
@@ -49,7 +49,7 @@ class OverridesCompletion(
val baseClass = descriptor.containingDeclaration as ClassDescriptor
val baseClassName = baseClass.name.asString()
val baseIcon = (lookupElement.`object` as DeclarationLookupObject).getIcon(0)
val baseIcon = (lookupElement.`object` as DescriptorBasedDeclarationLookupObject).getIcon(0)
val isImplement = descriptor.modality == Modality.ABSTRACT
val additionalIcon = if (isImplement)
AllIcons.Gutter.ImplementingMethod

View File

@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.renderer.DescriptorRenderer
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
class KotlinCompletionStatistician : CompletionStatistician() {
override fun serialize(element: LookupElement, location: CompletionLocation): StatisticsInfo? {
val o = (element.`object` as? DeclarationLookupObject) ?: return null
val o = (element.`object` as? DescriptorBasedDeclarationLookupObject) ?: return null
val context = element.getUserDataDeep(STATISTICS_INFO_CONTEXT_KEY) ?: ""

View File

@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.completion.smart.*
import org.jetbrains.kotlin.idea.core.ExpectedInfo
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.PackageLookupObject
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.util.CallType
@@ -46,7 +47,7 @@ class NotImportedWeigher(private val classifier: ImportableFqNameClassifier) : L
override fun weigh(element: LookupElement): Comparable<*> {
if (element.getUserData(NOT_IMPORTED_KEY) == null) return Weight.default
val o = element.`object` as? DeclarationLookupObject
val o = element.`object` as? DescriptorBasedDeclarationLookupObject
val fqName = o?.importableFqName ?: return Weight.default
return when (classifier.classify(fqName, o is PackageLookupObject)) {
ImportableFqNameClassifier.Classification.siblingImported -> Weight.siblingImported
@@ -61,7 +62,7 @@ class NotImportedStaticMemberWeigher(private val classifier: ImportableFqNameCla
LookupElementWeigher("kotlin.notImportedMember") {
override fun weigh(element: LookupElement): Comparable<*>? {
if (element.priority != ItemPriority.STATIC_MEMBER) return null
val fqName = (element.`object` as DeclarationLookupObject).importableFqName ?: return null
val fqName = (element.`object` as DescriptorBasedDeclarationLookupObject).importableFqName ?: return null
return classifier.classify(fqName.parent(), false)
}
}
@@ -75,7 +76,7 @@ class ImportedWeigher(private val classifier: ImportableFqNameClassifier) : Look
}
override fun weigh(element: LookupElement): Comparable<*>? {
val o = element.`object` as? DeclarationLookupObject
val o = element.`object` as? DescriptorBasedDeclarationLookupObject
val fqName = o?.importableFqName ?: return null
return when (classifier.classify(fqName, o is PackageLookupObject)) {
ImportableFqNameClassifier.Classification.fromCurrentPackage -> Weight.currentPackage
@@ -90,7 +91,7 @@ class ImportedWeigher(private val classifier: ImportableFqNameClassifier) : Look
// analog of LookupElementProximityWeigher which does not work for us
object KotlinLookupElementProximityWeigher : CompletionWeigher() {
override fun weigh(element: LookupElement, location: CompletionLocation): Comparable<Nothing>? {
val psiElement = (element.`object` as? DeclarationLookupObject)?.psiElement ?: return null
val psiElement = (element.`object` as? DescriptorBasedDeclarationLookupObject)?.psiElement ?: return null
return PsiProximityComparator.getProximity({ psiElement }, location.completionParameters.position, location.processingContext)
}
}
@@ -120,7 +121,7 @@ object KindWeigher : LookupElementWeigher("kotlin.kind") {
return when (val o = element.`object`) {
is PackageLookupObject -> Weight.packages
is DeclarationLookupObject -> {
is DescriptorBasedDeclarationLookupObject -> {
when (val descriptor = o.descriptor) {
is VariableDescriptor, is FunctionDescriptor -> Weight.callable
is ClassDescriptor -> if (descriptor.kind == ClassKind.ENUM_ENTRY) Weight.enumMember else Weight.default
@@ -198,7 +199,7 @@ object VariableOrFunctionWeigher : LookupElementWeigher("kotlin.variableOrFuncti
}
override fun weigh(element: LookupElement): Comparable<*>? {
val descriptor = (element.`object` as? DeclarationLookupObject)?.descriptor ?: return null
val descriptor = (element.`object` as? DescriptorBasedDeclarationLookupObject)?.descriptor ?: return null
return when (descriptor) {
is VariableDescriptor -> Weight.variable
is FunctionDescriptor -> Weight.function
@@ -212,7 +213,7 @@ object VariableOrFunctionWeigher : LookupElementWeigher("kotlin.variableOrFuncti
*/
object PreferGetSetMethodsToPropertyWeigher : LookupElementWeigher("kotlin.preferGetSetMethodsToProperty", false, true) {
override fun weigh(element: LookupElement, context: WeighingContext): Int {
val property = (element.`object` as? DeclarationLookupObject)?.descriptor as? PropertyDescriptor ?: return 0
val property = (element.`object` as? DescriptorBasedDeclarationLookupObject)?.descriptor as? PropertyDescriptor ?: return 0
val prefixMatcher = context.itemMatcher(element)
if (prefixMatcher.prefixMatches(property.name.asString())) return 0
val matchedLookupStrings = element.allLookupStrings.filter { prefixMatcher.prefixMatches(it) }
@@ -222,7 +223,7 @@ object PreferGetSetMethodsToPropertyWeigher : LookupElementWeigher("kotlin.prefe
object DeprecatedWeigher : LookupElementWeigher("kotlin.deprecated") {
override fun weigh(element: LookupElement): Int {
val o = element.`object` as? DeclarationLookupObject ?: return 0
val o = element.`object` as? DescriptorBasedDeclarationLookupObject ?: return 0
return if (o.isDeprecated) 1 else 0
}
}
@@ -236,7 +237,7 @@ object KotlinUnwantedLookupElementWeigher : LookupElementWeigher("kotlin.unwante
private val flowCollectFqName = FqName("kotlinx.coroutines.flow.Flow.collect")
override fun weigh(element: LookupElement): Int {
val descriptor = (element.`object` as? DeclarationLookupObject)?.descriptor ?: return 0
val descriptor = (element.`object` as? DescriptorBasedDeclarationLookupObject)?.descriptor ?: return 0
return if (descriptor.fqNameSafe == flowCollectFqName) 1 else 0
}
}
@@ -259,7 +260,7 @@ object PreferMatchingItemWeigher : LookupElementWeigher("kotlin.preferMatching",
return when (val o = element.`object`) {
is KeywordLookupObject -> Weight.keywordExactMatch
is DeclarationLookupObject -> {
is DescriptorBasedDeclarationLookupObject -> {
val smartCompletionPriority = element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY)
when {
smartCompletionPriority != null && smartCompletionPriority != SmartCompletionItemPriority.DEFAULT -> Weight.specialExactMatch
@@ -313,14 +314,14 @@ class SmartCompletionInBasicWeigher(
val o = element.`object`
if ((o as? DeclarationLookupObject)?.descriptor in descriptorsToSkip) return DESCRIPTOR_TO_SKIP_WEIGHT
if ((o as? DescriptorBasedDeclarationLookupObject)?.descriptor in descriptorsToSkip) return DESCRIPTOR_TO_SKIP_WEIGHT
if (expectedInfos.isEmpty()) return NO_MATCH_WEIGHT
val smartCastCalculator = smartCompletion.smartCastCalculator
val (fuzzyTypes, name) = when (o) {
is DeclarationLookupObject -> {
is DescriptorBasedDeclarationLookupObject -> {
val descriptor = o.descriptor ?: return NO_MATCH_WEIGHT
descriptor.fuzzyTypesForSmartCompletion(
smartCastCalculator,
@@ -363,7 +364,7 @@ class PreferContextElementsWeigher(context: DeclarationDescriptor) : LookupEleme
private val contextElementNames = contextElements.map { it.name }.toSet()
override fun weigh(element: LookupElement): Boolean {
val lookupObject = element.`object` as? DeclarationLookupObject ?: return false
val lookupObject = element.`object` as? DescriptorBasedDeclarationLookupObject ?: return false
val descriptor = lookupObject.descriptor ?: return false
return descriptor.isContextElement()
}
@@ -391,7 +392,7 @@ object ByNameAlphabeticalWeigher : LookupElementWeigher("kotlin.byNameAlphabetic
object PreferLessParametersWeigher : LookupElementWeigher("kotlin.preferLessParameters") {
override fun weigh(element: LookupElement): Int? {
val lookupObject = element.`object` as? DeclarationLookupObject ?: return null
val lookupObject = element.`object` as? DescriptorBasedDeclarationLookupObject ?: return null
val function = lookupObject.descriptor as? FunctionDescriptor ?: return null
return function.valueParameters.size
}
@@ -400,7 +401,7 @@ object PreferLessParametersWeigher : LookupElementWeigher("kotlin.preferLessPara
class CallableReferenceWeigher(private val callType: CallType<*>) : LookupElementWeigher("kotlin.callableReference") {
override fun weigh(element: LookupElement): Int? {
if (callType == CallType.CALLABLE_REFERENCE || element.getUserData(SMART_COMPLETION_ITEM_PRIORITY_KEY) == SmartCompletionItemPriority.CALLABLE_REFERENCE) {
val descriptor = (element.`object` as? DeclarationLookupObject)?.descriptor as? CallableDescriptor
val descriptor = (element.`object` as? DescriptorBasedDeclarationLookupObject)?.descriptor as? CallableDescriptor
return if (descriptor?.returnType?.isNothing() == true) 1 else 0
}
return null

View File

@@ -8,7 +8,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.psi.*
@@ -20,7 +20,7 @@ object CastReceiverInsertHandler {
if (qualifiedExpression != null) {
val receiver = qualifiedExpression.receiverExpression
val descriptor = (item.`object` as? DeclarationLookupObject)?.descriptor as CallableDescriptor
val descriptor = (item.`object` as? DescriptorBasedDeclarationLookupObject)?.descriptor as CallableDescriptor
val project = context.project
val thisObj =

View File

@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.idea.base.analysis.withRootPrefixIfNeeded
import org.jetbrains.kotlin.idea.completion.isArtificialImportAliasedDescriptor
import org.jetbrains.kotlin.idea.completion.shortenReferences
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.util.CallType
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
@@ -28,7 +28,7 @@ abstract class KotlinCallableInsertHandler(val callType: CallType<*>) : BaseDecl
val file = context.file
val o = item.`object`
if (file is KtFile && o is DeclarationLookupObject) {
if (file is KtFile && o is DescriptorBasedDeclarationLookupObject) {
val descriptor = o.descriptor as? CallableDescriptor ?: return
if (descriptor.extensionReceiverParameter != null || callType == CallType.CALLABLE_REFERENCE) {
if (DescriptorUtils.isTopLevelDeclaration(descriptor) && !descriptor.isArtificialImportAliasedDescriptor) {

View File

@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.idea.completion.PsiClassLookupObject
import org.jetbrains.kotlin.idea.completion.isAfterDot
import org.jetbrains.kotlin.idea.completion.isArtificialImportAliasedDescriptor
import org.jetbrains.kotlin.idea.completion.shortenReferences
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.ImportDescriptorResult
@@ -49,7 +49,7 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() {
val startOffset = context.startOffset
val document = context.document
val lookupObject = item.`object` as DeclarationLookupObject
val lookupObject = item.`object` as DescriptorBasedDeclarationLookupObject
// never need to insert import or use qualified name for import-aliased class
val descriptor = lookupObject.descriptor
if (descriptor?.isArtificialImportAliasedDescriptor == true) return
@@ -116,7 +116,7 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() {
}
}
private fun qualifiedName(lookupObject: DeclarationLookupObject): String {
private fun qualifiedName(lookupObject: DescriptorBasedDeclarationLookupObject): String {
return if (lookupObject.descriptor != null) {
IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(lookupObject.descriptor as ClassifierDescriptor)
} else {

View File

@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.completion.*
import org.jetbrains.kotlin.idea.core.ExpectedInfo
import org.jetbrains.kotlin.idea.core.ExpectedInfos
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.core.completion.DescriptorBasedDeclarationLookupObject
import org.jetbrains.kotlin.idea.core.fuzzyType
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
import org.jetbrains.kotlin.resolve.sam.SamConstructorDescriptorKindExclude
@@ -216,7 +216,7 @@ class SmartCompletionSession(
)
private fun wrapStandardLookupElement(lookupElement: LookupElement): LookupElement {
val descriptor = (lookupElement.`object` as DeclarationLookupObject).descriptor
val descriptor = (lookupElement.`object` as DescriptorBasedDeclarationLookupObject).descriptor
var element = lookupElement
if (descriptor is FunctionDescriptor && descriptor.valueParameters.isNotEmpty()) {

View File

@@ -7,6 +7,8 @@ import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.psi.PsiElement
import com.intellij.openapi.util.Key
import com.intellij.ui.JBColor
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
import org.jetbrains.kotlin.lexer.KtTokens
@@ -20,6 +22,9 @@ import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
import org.jetbrains.kotlin.renderer.render
@ApiStatus.Internal
val KOTLIN_CAST_REQUIRED_COLOR = JBColor(0x4E4040, 0x969696)
val PsiElement.isInsideKtTypeReference: Boolean
get() = getNonStrictParentOfType<KtTypeReference>() != null

Some files were not shown because too many files have changed in this diff Show More