From a83539705efdc40d12cfe8eb96b24dc5a791105d Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 15 Oct 2015 18:56:52 +0300 Subject: [PATCH] Fixed completion handler for annotations (because the parser does not parse "@ xxx" as annotation anymore) --- .../handlers/KotlinClassifierInsertHandler.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt index 91dd951bfcc..457d923fa5b 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/handlers/KotlinClassifierInsertHandler.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.completion.isAfterDot import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject +import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.name.FqNameUnsafe @@ -59,10 +60,15 @@ object KotlinClassifierInsertHandler : BaseDeclarationInsertHandler() { if (target != null && IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(target) == qualifiedName) return } - val tempPrefix = if (nameRef != null) - " " // insert space so that any preceding spaces inserted by formatter on reference shortening are deleted - else - "$;val v:" // if we have no reference in the current context we have a more complicated prefix to get one + val tempPrefix = if (nameRef != null) { + val isAnnotation = CallTypeAndReceiver.detect(nameRef) is CallTypeAndReceiver.ANNOTATION + // we insert space so that any preceding spaces inserted by formatter on reference shortening are deleted + // (but not for annotations where spaces are not allowed after @) + if (isAnnotation) "" else " " + } + else { + "$;val v:" // if we have no reference in the current context we have a more complicated prefix to get one + } val tempSuffix = ".xxx" // we add "xxx" after dot because of some bugs in resolve (see KT-5145) document.replaceString(startOffset, context.getTailOffset(), tempPrefix + qualifiedName + tempSuffix)