Unify 'lateinit' diagnostics
This commit is contained in:
@@ -360,12 +360,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetSimpleNameExpression> BACKING_FIELD_OLD_SYNTAX = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetSimpleNameExpression> BACKING_FIELD_USAGE_FORBIDDEN = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_LATEINIT_MODIFIER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_LATEINIT_MODIFIER_IMMUTABLE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_LATEINIT_MODIFIER_ABSTRACT_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_LATEINIT_MODIFIER_PRIMARY_CONSTRUCTOR_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_LATEINIT_MODIFIER_NULLABLE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> INAPPLICABLE_LATEINIT_MODIFIER_PRIMITIVE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> INAPPLICABLE_LATEINIT_MODIFIER = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<JetModifierListOwner, String, ClassDescriptor> ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS = DiagnosticFactory2.create(ERROR, ABSTRACT_MODIFIER);
|
||||
|
||||
|
||||
+1
-6
@@ -214,12 +214,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DELEGATED_PROPERTY_IN_INTERFACE, "Delegated properties are not allowed in interfaces");
|
||||
MAP.put(LOCAL_VARIABLE_WITH_DELEGATE, "Local variables are not allowed to have delegates");
|
||||
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER, "''lateinit'' modifier is allowed only on member properties with a backing field");
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER_IMMUTABLE, "''lateinit'' modifier is allowed only on mutable properties");
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER_ABSTRACT_PROPERTY, "''lateinit'' modifier is not allowed on abstract properties");
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER_PRIMARY_CONSTRUCTOR_PARAMETER, "''lateinit'' modifier is not allowed on primary constructor parameters");
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER_NULLABLE, "''lateinit'' modifier is not allowed on nullable properties");
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER_PRIMITIVE, "''lateinit'' modifier is not allowed on primitive type properties");
|
||||
MAP.put(INAPPLICABLE_LATEINIT_MODIFIER, "''lateinit'' modifier {0}", STRING);
|
||||
|
||||
MAP.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility");
|
||||
MAP.put(PRIVATE_SETTER_ON_NON_PRIVATE_LATE_INIT_VAR, "Private setter is not allowed on non-private lateinit property");
|
||||
|
||||
@@ -514,8 +514,7 @@ public class DeclarationsChecker {
|
||||
if (modifier == null) return;
|
||||
|
||||
if (!propertyDescriptor.isVar()) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER_IMMUTABLE.on(modifier));
|
||||
return;
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is allowed only on mutable properties"));
|
||||
}
|
||||
|
||||
boolean returnTypeIsNullable = true;
|
||||
@@ -528,32 +527,29 @@ public class DeclarationsChecker {
|
||||
}
|
||||
|
||||
if (returnTypeIsNullable) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER_NULLABLE.on(modifier));
|
||||
return;
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on nullable properties"));
|
||||
}
|
||||
|
||||
if (returnTypeIsPrimitive) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER_PRIMITIVE.on(modifier));
|
||||
return;
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on primitive type properties"));
|
||||
}
|
||||
|
||||
if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER_ABSTRACT_PROPERTY.on(modifier));
|
||||
return;
|
||||
boolean isAbstract = propertyDescriptor.getModality() == Modality.ABSTRACT;
|
||||
if (isAbstract) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on abstract properties"));
|
||||
}
|
||||
|
||||
if (property instanceof JetParameter) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER_PRIMARY_CONSTRUCTOR_PARAMETER.on(modifier));
|
||||
return;
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on primary constructor parameters"));
|
||||
}
|
||||
|
||||
boolean hasBackingField =
|
||||
Boolean.TRUE.equals(trace.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor));
|
||||
|
||||
boolean hasDelegateOrInitializer = false;
|
||||
|
||||
boolean hasDelegateExpressionOrInitializer = false;
|
||||
if (property instanceof JetProperty) {
|
||||
hasDelegateOrInitializer = ((JetProperty) property).hasDelegateExpressionOrInitializer();
|
||||
hasDelegateExpressionOrInitializer = ((JetProperty) property).hasDelegateExpressionOrInitializer();
|
||||
if (hasDelegateExpressionOrInitializer) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier,
|
||||
"is not allowed on properties with initializer or on delegated properties"));
|
||||
}
|
||||
}
|
||||
|
||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||
@@ -567,9 +563,19 @@ public class DeclarationsChecker {
|
||||
customGetterOrSetter |= setter.hasBody();
|
||||
}
|
||||
|
||||
if (!hasBackingField || hasDelegateOrInitializer || customGetterOrSetter
|
||||
|| propertyDescriptor.getExtensionReceiverParameter() != null) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier));
|
||||
if (!hasDelegateExpressionOrInitializer && customGetterOrSetter) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on properties with a custom getter or setter"));
|
||||
}
|
||||
|
||||
boolean hasBackingField =
|
||||
Boolean.TRUE.equals(trace.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor));
|
||||
|
||||
if (!isAbstract && !customGetterOrSetter && !hasDelegateExpressionOrInitializer && !hasBackingField) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on properties without backing field"));
|
||||
}
|
||||
|
||||
if (propertyDescriptor.getExtensionReceiverParameter() != null) {
|
||||
trace.report(INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on extension properties"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user