Fixed filtering of annotation classes in annotation completion broken recently

This commit is contained in:
Valentin Kipyatkov
2015-10-19 21:33:17 +03:00
parent d5126213d3
commit b4501a6b98
4 changed files with 32 additions and 3 deletions
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion
import org.jetbrains.kotlin.idea.completion.smart.SmartCompletionItemPriority
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
import org.jetbrains.kotlin.idea.util.CallType
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -75,10 +76,12 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
PARAMETER_NAME(descriptorKindFilter = null, classKindFilter = null),
SUPER_QUALIFIER(descriptorKindFilter = DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classKindFilter = null)
SUPER_QUALIFIER(descriptorKindFilter = DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS, classKindFilter = null),
ANNOTATION(descriptorKindFilter = CallType.ANNOTATION.descriptorKindFilter, classKindFilter = { it == ClassKind.ANNOTATION_CLASS })
}
private val completionKind = calcCompletionKind()
private val completionKind = detectCompletionKind()
override val descriptorKindFilter = if (isNoQualifierContext()) {
// it's an optimization because obtaining top-level packages from scope is very slow, we obtains them in other way
@@ -104,7 +107,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
override val expectedInfos: Collection<ExpectedInfo>
get() = smartCompletion?.expectedInfos ?: emptyList()
private fun calcCompletionKind(): CompletionKind {
private fun detectCompletionKind(): CompletionKind {
if (nameExpression != null && NamedArgumentCompletion.isOnlyNamedArgumentExpected(nameExpression)) {
return CompletionKind.NAMED_ARGUMENTS_ONLY
}
@@ -117,6 +120,10 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
CompletionKind.KEYWORDS_ONLY
}
if (callTypeAndReceiver is CallTypeAndReceiver.ANNOTATION) {
return CompletionKind.ANNOTATION // we need special completion kind for it to filter non-imported classes with classKindFilter
}
// Check that completion in the type annotation context and if there's a qualified
// expression we are at first of it
val typeReference = position.getStrictParentOfType<KtTypeReference>()
@@ -0,0 +1,10 @@
annotation class III
@I<caret>
annotation class A
// INVOCATION_COUNT: 2
// EXIST: III
// EXIST_JAVA_ONLY: Inherited
// ABSENT: Icon
// ABSENT: IllegalAccessException
@@ -771,6 +771,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("OnlyAnnotations.kt")
public void testOnlyAnnotations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/OnlyAnnotations.kt");
doTest(fileName);
}
@TestMetadata("ParameterAnnotation1.kt")
public void testParameterAnnotation1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt");
@@ -771,6 +771,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("OnlyAnnotations.kt")
public void testOnlyAnnotations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/OnlyAnnotations.kt");
doTest(fileName);
}
@TestMetadata("ParameterAnnotation1.kt")
public void testParameterAnnotation1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt");