Do not report diagnostic about annotation with receiver target twice
This commit is contained in:
@@ -244,7 +244,6 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, String> INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_TARGET_PROPERTY_HAS_NO_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_TARGET_PROPERTY_HAS_NO_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_RECEIVER_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_PARAM_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> REDUNDANT_ANNOTATION_TARGET = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<KtAnnotationUseSiteTarget> INAPPLICABLE_FILE_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
-1
@@ -158,7 +158,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "''@{0}:'' annotations could be applied only to mutable properties", TO_STRING);
|
||||
MAP.put(INAPPLICABLE_TARGET_PROPERTY_HAS_NO_DELEGATE, "'@delegate:' annotations could be applied only to delegated properties");
|
||||
MAP.put(INAPPLICABLE_TARGET_PROPERTY_HAS_NO_BACKING_FIELD, "'@field:' annotations could be applied only to properties with backing fields");
|
||||
MAP.put(INAPPLICABLE_RECEIVER_TARGET, "'@receiver:' annotations can only be applied to the receiver type of extension function or extension property declarations");
|
||||
MAP.put(INAPPLICABLE_PARAM_TARGET, "'@param:' annotations could be applied only to primary constructor parameters");
|
||||
MAP.put(REDUNDANT_ANNOTATION_TARGET, "Redundant annotation target ''{0}''", STRING);
|
||||
MAP.put(INAPPLICABLE_FILE_TARGET, "'@file:' annotations can only be applied before package declaration");
|
||||
|
||||
+1
-28
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
@@ -37,32 +36,6 @@ object AnnotationUseSiteTargetChecker {
|
||||
trace.checkDeclaration(parameter, parameterDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor is CallableDescriptor) trace.checkReceiverAnnotations(descriptor)
|
||||
}
|
||||
|
||||
private fun BindingTrace.checkReceiverAnnotations(descriptor: CallableDescriptor) {
|
||||
val extensionReceiver = descriptor.extensionReceiverParameter ?: return
|
||||
for (annotationWithTarget in extensionReceiver.type.annotations.getUseSiteTargetedAnnotations()) {
|
||||
val target = annotationWithTarget.target ?: continue
|
||||
fun annotationEntry() = DescriptorToSourceUtils.getSourceFromAnnotation(annotationWithTarget.annotation)
|
||||
|
||||
when (target) {
|
||||
AnnotationUseSiteTarget.RECEIVER -> {}
|
||||
AnnotationUseSiteTarget.FIELD,
|
||||
AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD,
|
||||
AnnotationUseSiteTarget.PROPERTY,
|
||||
AnnotationUseSiteTarget.PROPERTY_GETTER,
|
||||
AnnotationUseSiteTarget.PROPERTY_SETTER,
|
||||
AnnotationUseSiteTarget.SETTER_PARAMETER -> {
|
||||
annotationEntry()?.let { report(INAPPLICABLE_TARGET_ON_PROPERTY.on(it, target.renderName)) }
|
||||
}
|
||||
AnnotationUseSiteTarget.CONSTRUCTOR_PARAMETER -> annotationEntry()?.let { report(INAPPLICABLE_PARAM_TARGET.on(it)) }
|
||||
AnnotationUseSiteTarget.FILE -> {
|
||||
annotationEntry()?.useSiteTarget?.let { reportDiagnosticOnce(INAPPLICABLE_FILE_TARGET.on(it)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun BindingTrace.checkDeclaration(annotated: KtAnnotated, descriptor: DeclarationDescriptor) {
|
||||
@@ -92,7 +65,7 @@ object AnnotationUseSiteTargetChecker {
|
||||
}
|
||||
AnnotationUseSiteTarget.SETTER_PARAMETER -> checkIfMutableProperty(annotated, annotation)
|
||||
AnnotationUseSiteTarget.FILE -> reportDiagnosticOnce(INAPPLICABLE_FILE_TARGET.on(useSiteTarget))
|
||||
AnnotationUseSiteTarget.RECEIVER -> report(INAPPLICABLE_RECEIVER_TARGET.on(annotation))
|
||||
AnnotationUseSiteTarget.RECEIVER -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,17 +1,17 @@
|
||||
annotation class Ann
|
||||
|
||||
<!INAPPLICABLE_RECEIVER_TARGET, WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
class SomeClass {
|
||||
|
||||
<!INAPPLICABLE_RECEIVER_TARGET, WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
constructor(<!INAPPLICABLE_RECEIVER_TARGET, WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!> <!UNUSED_PARAMETER!>a<!>: String)
|
||||
<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
constructor(<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!> <!UNUSED_PARAMETER!>a<!>: String)
|
||||
|
||||
<!INAPPLICABLE_RECEIVER_TARGET, WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
protected val simpleProperty: String = "text"
|
||||
|
||||
<!INAPPLICABLE_RECEIVER_TARGET, WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
fun anotherFun() {
|
||||
<!INAPPLICABLE_RECEIVER_TARGET, WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@receiver:Ann<!>
|
||||
val <!UNUSED_VARIABLE!>localVariable<!> = 5
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -7,4 +7,4 @@ fun test2() {}
|
||||
|
||||
class OnType(x: <!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@file<!SYNTAX!><!> Suppress("")<!> Int)
|
||||
|
||||
fun <!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@<!INAPPLICABLE_FILE_TARGET!>file<!> : Suppress("")<!> Int.test3() {}
|
||||
fun <!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@file : Suppress("")<!> Int.test3() {}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user