More correct shadowed declarations filtering in completion

This commit is contained in:
Valentin Kipyatkov
2015-10-30 20:13:13 +03:00
parent 67cf9f9510
commit c11bf32594
7 changed files with 37 additions and 11 deletions
@@ -172,7 +172,7 @@ class BasicCompletionSession(
val contextVariableTypesForSmartCompletion = withCollectRequiredContextVariableTypes(::completeWithSmartCompletion)
fun completeReferenceVariants(lookupElementFactory: LookupElementFactory) {
val (imported, notImported) = referenceVariants!!
val (imported, notImported) = referenceVariantsWithNonInitializedVarExcluded!!
collector.addDescriptorElements(imported, lookupElementFactory)
collector.addDescriptorElements(notImported, lookupElementFactory, notImported = true)
}
@@ -284,6 +284,9 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
if (nameExpression != null && descriptorKindFilter != null) collectReferenceVariants(descriptorKindFilter!!, nameExpression) else null
}
protected val referenceVariantsWithNonInitializedVarExcluded: ReferenceVariants? by lazy {
referenceVariants?.let { ReferenceVariants(referenceVariantsHelper.excludeNonInitializedVariable(it.imported, position), it.notImportedExtensions) }
}
private fun collectReferenceVariants(descriptorKindFilter: DescriptorKindFilter, nameExpression: KtSimpleNameExpression, runtimeReceiver: ExpressionReceiver? = null): ReferenceVariants {
var variants = referenceVariantsHelper.getReferenceVariants(
@@ -292,6 +295,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
descriptorNameFilter,
filterOutJavaGettersAndSetters = false,
filterOutShadowed = false,
excludeNonInitializedVariable = false,
useReceiverType = runtimeReceiver?.type)
val shadowedDeclarationsFilter = if (runtimeReceiver != null)
@@ -78,7 +78,7 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
val filter = smartCompletion!!.descriptorFilter
var contextVariableTypesForReferenceVariants = filter?.let {
withCollectRequiredContextVariableTypes { lookupElementFactory ->
val (imported, notImported) = referenceVariants ?: return@withCollectRequiredContextVariableTypes
val (imported, notImported) = referenceVariantsWithNonInitializedVarExcluded ?: return@withCollectRequiredContextVariableTypes
imported.forEach { collector.addElements(filter(it, lookupElementFactory)) }
notImported.forEach { collector.addElements(filter(it, lookupElementFactory), notImported = true) }
}
@@ -0,0 +1,7 @@
val xxx: String = ""
class C {
val xxx = x<caret>
}
// ABSENT: xxx
@@ -1929,6 +1929,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("InInitializer7.kt")
public void testInInitializer7() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/InInitializer7.kt");
doTest(fileName);
}
@TestMetadata("Locals1.kt")
public void testLocals1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/Locals1.kt");
@@ -1929,6 +1929,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("InInitializer7.kt")
public void testInInitializer7() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/InInitializer7.kt");
doTest(fileName);
}
@TestMetadata("Locals1.kt")
public void testLocals1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/shadowing/Locals1.kt");