Do not report diagnostic about annotation with receiver target twice

This commit is contained in:
Mikhail Zarechenskiy
2017-09-11 19:25:53 +03:00
parent 2048a74302
commit e16d16fdb7
9 changed files with 14 additions and 40 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtCallableDeclaration
@@ -44,6 +45,8 @@ class MoveReceiverAnnotationFix(element: KtAnnotationEntry) : KotlinQuickFixActi
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
val entry = diagnostic.psiElement as? KtAnnotationEntry ?: return null
if (entry.useSiteTarget?.getAnnotationUseSiteTarget() != AnnotationUseSiteTarget.RECEIVER) return null
val declaration = entry.getParentOfType<KtCallableDeclaration>(true) ?: return null
if (declaration.receiverTypeReference == null) return null
@@ -508,7 +508,7 @@ class QuickFixRegistrar : QuickFixContributor {
RETURN_NOT_ALLOWED.registerFactory(ChangeToLabeledReturnFix)
INAPPLICABLE_RECEIVER_TARGET.registerFactory(MoveReceiverAnnotationFix)
WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET.registerFactory(MoveReceiverAnnotationFix)
NO_CONSTRUCTOR.registerFactory(RemoveNoConstructorFix)
@@ -1,5 +1,5 @@
// "Move annotation to receiver type" "false"
// ERROR: '@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations
// ERROR: This annotation is not applicable to target 'top level function' and use site target '@receiver'
// ACTION: Make internal
// ACTION: Make private
@@ -1,5 +1,5 @@
// "Move annotation to receiver type" "false"
// ERROR: '@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations
// ERROR: This annotation is not applicable to target 'top level property without backing field or delegate' and use site target '@receiver'
// ACTION: Make internal
// ACTION: Make private
// ACTION: Specify type explicitly