diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt index b2c955d279d..3ea800243bd 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/BasicCompletionSession.kt @@ -30,8 +30,6 @@ import com.intellij.psi.util.PsiTreeUtil import com.intellij.util.ProcessingContext import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.idea.completion.smart.ExpectedInfoMatch import org.jetbrains.kotlin.idea.completion.smart.SMART_COMPLETION_ITEM_PRIORITY_KEY import org.jetbrains.kotlin.idea.completion.smart.SmartCompletion @@ -42,7 +40,10 @@ import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.* +import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter @@ -68,16 +69,6 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, classKindFilter = { it != ClassKind.ENUM_ENTRY } ), - ANNOTATION_TYPES( - descriptorKindFilter = ANNOTATION_TYPES_FILTER, - classKindFilter = { it == ClassKind.ANNOTATION_CLASS } - ), - - ANNOTATION_TYPES_OR_PARAMETER_NAME( - descriptorKindFilter = ANNOTATION_TYPES_FILTER, - classKindFilter = { it == ClassKind.ANNOTATION_CLASS } - ), - KEYWORDS_ONLY(descriptorKindFilter = null, classKindFilter = null), NAMED_ARGUMENTS_ONLY(descriptorKindFilter = null, classKindFilter = null), @@ -126,18 +117,6 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, CompletionKind.KEYWORDS_ONLY } - val annotationEntry = position.getStrictParentOfType() - if (annotationEntry != null) { - val valueArgList = position.getStrictParentOfType() - if (valueArgList == null || !annotationEntry.isAncestor(valueArgList)) { - val parent = annotationEntry.getParent() - if (parent is JetDeclarationModifierList && parent.getParent() is JetParameter) { - return CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME - } - return CompletionKind.ANNOTATION_TYPES - } - } - // 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() @@ -156,7 +135,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, } private fun shouldCompleteParameterNameAndType(): Boolean { - if (completionKind != CompletionKind.PARAMETER_NAME && completionKind != CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME) return false + if (completionKind != CompletionKind.PARAMETER_NAME) return false val parameter = position.getNonStrictParentOfType()!! val list = parameter.parent as? JetParameterList ?: return false @@ -170,7 +149,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, } public fun shouldDisableAutoPopup(): Boolean { - if (completionKind == CompletionKind.PARAMETER_NAME || completionKind == CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME) { + if (completionKind == CompletionKind.PARAMETER_NAME) { if (!shouldCompleteParameterNameAndType() || TemplateManager.getInstance(project).getActiveTemplate(parameters.editor) != null) { return true } @@ -395,17 +374,4 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration, return sorter } - - private companion object { - object NonAnnotationClassifierExclude : DescriptorKindExclude() { - override fun excludes(descriptor: DeclarationDescriptor): Boolean { - if (descriptor !is ClassifierDescriptor) return false - return descriptor !is ClassDescriptor || descriptor.getKind() != ClassKind.ANNOTATION_CLASS - } - - override val fullyExcludedDescriptorKinds: Int get() = 0 - } - - val ANNOTATION_TYPES_FILTER = DescriptorKindFilter(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude - } } \ No newline at end of file diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index 46cde7c6182..2e8be4986f6 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -84,7 +84,6 @@ public class KotlinCompletionContributor : CompletionContributor() { else -> specialLambdaSignatureDummyIdentifier(tokenBefore) ?: specialExtensionReceiverDummyIdentifier(tokenBefore) ?: specialInTypeArgsDummyIdentifier(tokenBefore) - ?: specialInParameterListDummyIdentifier(tokenBefore) ?: specialInArgumentListDummyIdentifier(tokenBefore) ?: DEFAULT_DUMMY_IDENTIFIER } @@ -389,22 +388,6 @@ public class KotlinCompletionContributor : CompletionContributor() { } } - private fun specialInParameterListDummyIdentifier(tokenBefore: PsiElement?): String? { - if (tokenBefore == null) return null - var parent = tokenBefore.getParent() - while (parent != null) { - if (parent is JetParameterList) { - val balance = countParenthesisBalance(tokenBefore, parent) - val count = if (balance > 1) balance - 1 else 0 - return CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + ")".repeat(count) + " a: B" - } - if (parent is JetTypeElement) return null - if (parent is JetAnnotationEntry) return null - parent = parent.getParent() - } - return null - } - private fun specialInArgumentListDummyIdentifier(tokenBefore: PsiElement?): String? { // If we insert $ in the argument list of a delegation specifier, this will break parsing // and the following block will not be attached as a body to the constructor. Therefore diff --git a/idea/idea-completion/testData/basic/common/annotations/AnnotationTarget.kt b/idea/idea-completion/testData/basic/common/annotations/AnnotationTarget.kt index f06aa54f499..a663b953d8c 100644 --- a/idea/idea-completion/testData/basic/common/annotations/AnnotationTarget.kt +++ b/idea/idea-completion/testData/basic/common/annotations/AnnotationTarget.kt @@ -1,3 +1,3 @@ - annotation class Annotated +@ annotation class Annotated // EXIST: Target diff --git a/idea/idea-completion/testData/basic/common/annotations/Deprecated2.kt b/idea/idea-completion/testData/basic/common/annotations/Deprecated2.kt index 353cd16bd12..18d56047ab6 100644 --- a/idea/idea-completion/testData/basic/common/annotations/Deprecated2.kt +++ b/idea/idea-completion/testData/basic/common/annotations/Deprecated2.kt @@ -1,4 +1,4 @@ -@Dep +@Deprecate fun foo() { } // INVOCATION_COUNT: 2 diff --git a/idea/idea-completion/testData/basic/common/annotations/FunctionAnnotation1.kt b/idea/idea-completion/testData/basic/common/annotations/FunctionAnnotation1.kt index ab522384ebf..803eb66473e 100644 --- a/idea/idea-completion/testData/basic/common/annotations/FunctionAnnotation1.kt +++ b/idea/idea-completion/testData/basic/common/annotations/FunctionAnnotation1.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 - +@ fun some() {} // INVOCATION_COUNT: 0 diff --git a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt index c25f17fe0a6..5286e22ab1d 100644 --- a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt +++ b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation1.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 -fun foo() { } +fun foo(@) { } // INVOCATION_COUNT: 1 // EXIST: Hello diff --git a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation2.kt b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation2.kt index aba251d6a55..41da1b1aba4 100644 --- a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation2.kt +++ b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation2.kt @@ -1,6 +1,6 @@ annotation class SHello -fun foo(S) { } +fun foo(@S) { } // INVOCATION_COUNT: 1 // EXIST: SHello diff --git a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation3.kt b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation3.kt index ef38e4ba7c4..6cc5190f3d2 100644 --- a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation3.kt +++ b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation3.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 -fun foo(p: String, ) { } +fun foo(p: String, @) { } // INVOCATION_COUNT: 1 // EXIST: Hello diff --git a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation4.kt b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation4.kt index eb8f3307da9..8a0211b59a6 100644 --- a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation4.kt +++ b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation4.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 -fun foo(@Volatile ) { } +fun foo(@Volatile @) { } // INVOCATION_COUNT: 1 // EXIST: Hello diff --git a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation5.kt b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation5.kt index 2dbc7f7ee01..2a7e68d889e 100644 --- a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation5.kt +++ b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation5.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 -fun foo( +fun foo(@ // INVOCATION_COUNT: 1 // EXIST: Hello diff --git a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation7.kt b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation7.kt index e543c4137de..220d6dc3e1a 100644 --- a/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation7.kt +++ b/idea/idea-completion/testData/basic/common/annotations/ParameterAnnotation7.kt @@ -1,4 +1,4 @@ -fun foo(kotlin.) { } +fun foo(@kotlin.) { } // INVOCATION_COUNT: 1 // EXIST: Suppress diff --git a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation1.kt b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation1.kt index fe8cb83b506..d1bcbcb537d 100644 --- a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation1.kt +++ b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation1.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 - +@ // INVOCATION_COUNT: 0 // EXIST: Hello diff --git a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation3.kt b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation3.kt index 74bf3878c24..db9eafab578 100644 --- a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation3.kt +++ b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotation3.kt @@ -1,7 +1,7 @@ annotation class Hello val v = 1 - +@ class C // INVOCATION_COUNT: 0 diff --git a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg1.kt b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg1.kt index 2bf71dd2bff..5314e14eca7 100644 --- a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg1.kt +++ b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg1.kt @@ -1,6 +1,6 @@ import java.lang.annotation.* -Retention( +@Retention( // INVOCATION_COUNT: 0 // EXIST_JAVA_ONLY: RetentionPolicy diff --git a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg2.kt b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg2.kt index 403d251f2c7..afc0b973b50 100644 --- a/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg2.kt +++ b/idea/idea-completion/testData/basic/common/annotations/TopLevelAnnotationArg2.kt @@ -1,6 +1,6 @@ import java.lang.annotation.* -Retention(RetentionPolicy. +@Retention(RetentionPolicy. // INVOCATION_COUNT: 0 // EXIST_JAVA_ONLY: SOURCE diff --git a/idea/idea-completion/testData/weighers/basic/DeprecatedFun.kt b/idea/idea-completion/testData/weighers/basic/DeprecatedFun.kt index 90cbdf2c1c4..d75593ca1d7 100644 --- a/idea/idea-completion/testData/weighers/basic/DeprecatedFun.kt +++ b/idea/idea-completion/testData/weighers/basic/DeprecatedFun.kt @@ -1,5 +1,5 @@ fun foo1() {} -Deprecated("Use foo3 instead") fun foo2() {} +@Deprecated("Use foo3 instead") fun foo2() {} fun foo3() {} fun test() { diff --git a/idea/idea-completion/testData/weighers/basic/parameterNameAndType/Deprecated.kt b/idea/idea-completion/testData/weighers/basic/parameterNameAndType/Deprecated.kt index 0672b7c1c36..0b096b4c7ec 100644 --- a/idea/idea-completion/testData/weighers/basic/parameterNameAndType/Deprecated.kt +++ b/idea/idea-completion/testData/weighers/basic/parameterNameAndType/Deprecated.kt @@ -1,5 +1,5 @@ class MyClassA -Deprecated class MyClassB +@Deprecated class MyClassB class MyClassC fun foo(myCla)