Support @get and @set annotations
This commit is contained in:
@@ -133,6 +133,9 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_FIELD_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_FIELD_TARGET_NO_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_GET_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_SET_TARGET = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Classes and traits
|
||||
|
||||
|
||||
+3
@@ -126,6 +126,9 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(INAPPLICABLE_FIELD_TARGET, "''@field:'' annotations could be applied only to property declarations");
|
||||
MAP.put(INAPPLICABLE_FIELD_TARGET_NO_BACKING_FIELD, "Property has neither a backing field nor a delegate");
|
||||
MAP.put(INAPPLICABLE_GET_TARGET, "''@get:'' annotations could be applied only to property declarations");
|
||||
MAP.put(INAPPLICABLE_SET_TARGET, "''@set:'' annotations could be applied only to property declarations");
|
||||
MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "Property must be mutable");
|
||||
|
||||
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");
|
||||
|
||||
@@ -38,6 +38,8 @@ public class JetAnnotationUseSiteTarget : JetElementImplStub<KotlinPlaceHolderSt
|
||||
return when (node.getElementType()) {
|
||||
JetTokens.FIELD_KEYWORD -> AnnotationUseSiteTarget.FIELD
|
||||
JetTokens.FILE_KEYWORD -> AnnotationUseSiteTarget.FILE
|
||||
JetTokens.GET_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_GETTER
|
||||
JetTokens.SET_KEYWORD -> AnnotationUseSiteTarget.PROPERTY_SETTER
|
||||
else -> throw IllegalStateException("Unknown annotation target " + node.getText())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,27 @@ public class ModifiersChecker {
|
||||
break;
|
||||
case FILE:
|
||||
throw new IllegalArgumentException("@file annotations are not allowed here");
|
||||
case PROPERTY_GETTER:
|
||||
reportIfNotPropertyDescriptor(descriptor, annotation, INAPPLICABLE_GET_TARGET);
|
||||
break;
|
||||
case PROPERTY_SETTER: {
|
||||
reportIfNotMutableProperty(descriptor, annotation, INAPPLICABLE_SET_TARGET);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reportIfNotMutableProperty(
|
||||
DeclarationDescriptor descriptor,
|
||||
AnnotationDescriptor annotation,
|
||||
DiagnosticFactory0<PsiElement> diagnosticFactory
|
||||
) {
|
||||
reportIfNotPropertyDescriptor(descriptor, annotation, diagnosticFactory);
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
if (!((PropertyDescriptor) descriptor).isVar()) {
|
||||
reportAnnotationTargetNotApplicable(annotation, INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user