Redundant annotation target warning

This commit is contained in:
Yan Zhulanow
2015-08-04 21:38:39 +03:00
parent 5cb74a2b12
commit 866552f6ab
3 changed files with 5 additions and 0 deletions
@@ -137,6 +137,7 @@ public interface Errors {
DiagnosticFactory0<PsiElement> INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE = 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);
// Classes and traits
@@ -130,6 +130,7 @@ public class DefaultErrorMessages {
MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "Property must be mutable");
MAP.put(INAPPLICABLE_RECEIVER_TARGET, "''@receiver:'' annotations could be applied only to 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(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING);
MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in interface");
@@ -67,6 +67,9 @@ public object AnnotationUseSiteTargetChecker {
if (containingDeclaration !is ConstructorDescriptor || !containingDeclaration.isPrimary) {
report(annotation, INAPPLICABLE_PARAM_TARGET)
}
else if (!annotated.hasValOrVar()) {
report(annotationWithTarget, REDUNDANT_ANNOTATION_TARGET)
}
}
}
AnnotationUseSiteTarget.SETTER_PARAMETER -> checkMutableProperty(descriptor, annotationWithTarget)