check modifiers for package declarations
removed specific errors for illegal 'abstract' modifier
This commit is contained in:
@@ -107,7 +107,6 @@ public interface Errors {
|
||||
DiagnosticFactory3<JetExpression, Name, JetType, JetType> COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR, DEFAULT);
|
||||
|
||||
SimpleDiagnosticFactory<JetModifierListOwner> ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS = SimpleDiagnosticFactory.create(ERROR, ABSTRACT_MODIFIER);
|
||||
SimpleDiagnosticFactory<JetProperty> ABSTRACT_PROPERTY_NOT_IN_CLASS = SimpleDiagnosticFactory.create(ERROR, ABSTRACT_MODIFIER);
|
||||
SimpleDiagnosticFactory<JetExpression> ABSTRACT_PROPERTY_WITH_INITIALIZER = SimpleDiagnosticFactory.create(ERROR);
|
||||
SimpleDiagnosticFactory<JetPropertyAccessor> ABSTRACT_PROPERTY_WITH_GETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||
SimpleDiagnosticFactory<JetPropertyAccessor>ABSTRACT_PROPERTY_WITH_SETTER = SimpleDiagnosticFactory.create(ERROR);
|
||||
@@ -124,7 +123,6 @@ public interface Errors {
|
||||
DiagnosticFactory2<JetFunction, String, ClassDescriptor> ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS = DiagnosticFactory2.create(ERROR, ABSTRACT_MODIFIER);
|
||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = DiagnosticFactory1.create(ERROR, ABSTRACT_MODIFIER);
|
||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = DiagnosticFactory1.create(ERROR, NAMED_ELEMENT);
|
||||
DiagnosticFactory1<JetModifierListOwner, SimpleFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = DiagnosticFactory1.create(ERROR, ABSTRACT_MODIFIER);
|
||||
|
||||
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = DiagnosticFactory1.create(ERROR, NAMED_ELEMENT);
|
||||
SimpleDiagnosticFactory<JetNamedDeclaration> NON_FINAL_MEMBER_IN_FINAL_CLASS = SimpleDiagnosticFactory.create(WARNING, positionModifier(JetTokens.OPEN_KEYWORD));
|
||||
|
||||
-2
@@ -121,7 +121,6 @@ public class DefaultErrorMessages {
|
||||
TO_STRING, RENDER_TYPE, RENDER_TYPE);
|
||||
|
||||
MAP.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, "This property cannot be declared abstract");
|
||||
MAP.put(ABSTRACT_PROPERTY_NOT_IN_CLASS, "A property may be abstract only when defined in a class or trait");
|
||||
MAP.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, "Property with initializer cannot be abstract");
|
||||
MAP.put(ABSTRACT_PROPERTY_WITH_GETTER, "Property with getter implementation cannot be abstract");
|
||||
MAP.put(ABSTRACT_PROPERTY_WITH_SETTER, "Property with setter implementation cannot be abstract");
|
||||
@@ -138,7 +137,6 @@ public class DefaultErrorMessages {
|
||||
MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", NAME, NAME);
|
||||
MAP.put(ABSTRACT_FUNCTION_WITH_BODY, "A function ''{0}'' with body cannot be abstract", NAME);
|
||||
MAP.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without a body must be abstract", NAME);
|
||||
MAP.put(NON_MEMBER_ABSTRACT_FUNCTION, "Function ''{0}'' is not a class or trait member and cannot be abstract", NAME);
|
||||
|
||||
MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME);
|
||||
MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class");
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -125,11 +126,13 @@ public class DeclarationsChecker {
|
||||
|
||||
private void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor) {
|
||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||
ClassDescriptor classDescriptor = (containingDeclaration instanceof ClassDescriptor)
|
||||
? (ClassDescriptor) containingDeclaration
|
||||
: null;
|
||||
checkPropertyAbstractness(property, propertyDescriptor, classDescriptor);
|
||||
checkPropertyInitializer(property, propertyDescriptor, classDescriptor);
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
checkPropertyAbstractness(property, propertyDescriptor, (ClassDescriptor) containingDeclaration);
|
||||
}
|
||||
else {
|
||||
modifiersChecker.checkIllegalModalityModifiers(property);
|
||||
}
|
||||
checkPropertyInitializer(property, propertyDescriptor);
|
||||
checkAccessors(property, propertyDescriptor);
|
||||
checkDeclaredTypeInPublicMember(property, propertyDescriptor);
|
||||
}
|
||||
@@ -149,17 +152,17 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPropertyAbstractness(JetProperty property, PropertyDescriptor propertyDescriptor, ClassDescriptor classDescriptor) {
|
||||
private void checkPropertyAbstractness(
|
||||
@NotNull JetProperty property,
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull ClassDescriptor classDescriptor
|
||||
) {
|
||||
JetPropertyAccessor getter = property.getGetter();
|
||||
JetPropertyAccessor setter = property.getSetter();
|
||||
JetModifierList modifierList = property.getModifierList();
|
||||
ASTNode abstractNode = modifierList != null ? modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD) : null;
|
||||
|
||||
if (abstractNode != null) { //has abstract modifier
|
||||
if (classDescriptor == null) {
|
||||
trace.report(ABSTRACT_PROPERTY_NOT_IN_CLASS.on(property));
|
||||
return;
|
||||
}
|
||||
if (!(classDescriptor.getModality() == Modality.ABSTRACT) && classDescriptor.getKind() != ClassKind.ENUM_CLASS) {
|
||||
JetClass classElement = (JetClass) BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
|
||||
String name = property.getName();
|
||||
@@ -190,7 +193,10 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, ClassDescriptor classDescriptor) {
|
||||
private void checkPropertyInitializer(
|
||||
@NotNull JetProperty property,
|
||||
@NotNull PropertyDescriptor propertyDescriptor
|
||||
) {
|
||||
JetPropertyAccessor getter = property.getGetter();
|
||||
JetPropertyAccessor setter = property.getSetter();
|
||||
boolean hasAccessorImplementation = (getter != null && getter.getBodyExpression() != null) ||
|
||||
@@ -202,8 +208,8 @@ public class DeclarationsChecker {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean inTrait = classDescriptor != null && classDescriptor.getKind() == ClassKind.TRAIT;
|
||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||
boolean inTrait = containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor)containingDeclaration).getKind() == ClassKind.TRAIT;
|
||||
JetExpression initializer = property.getInitializer();
|
||||
boolean backingFieldRequired = trace.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor);
|
||||
|
||||
@@ -213,7 +219,7 @@ public class DeclarationsChecker {
|
||||
if (initializer == null) {
|
||||
boolean error = false;
|
||||
if (backingFieldRequired && !inTrait && !trace.getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor)) {
|
||||
if (classDescriptor == null || hasAccessorImplementation) {
|
||||
if (!(containingDeclaration instanceof ClassDescriptor) || hasAccessorImplementation) {
|
||||
error = true;
|
||||
trace.report(MUST_BE_INITIALIZED.on(property));
|
||||
}
|
||||
@@ -259,15 +265,10 @@ public class DeclarationsChecker {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (hasAbstractModifier) {
|
||||
trace.report(NON_MEMBER_ABSTRACT_FUNCTION.on(function, functionDescriptor));
|
||||
}
|
||||
modifiersChecker.checkIllegalModalityModifiers(function);
|
||||
if (function.getBodyExpression() == null && !hasAbstractModifier) {
|
||||
trace.report(NON_MEMBER_FUNCTION_NO_BODY.on(function, functionDescriptor));
|
||||
}
|
||||
if (function.hasModifier(JetTokens.OVERRIDE_KEYWORD)) {
|
||||
trace.report(ILLEGAL_MODIFIER.on(function.getModifierList().getModifierNode(JetTokens.OVERRIDE_KEYWORD).getPsi(), JetTokens.OVERRIDE_KEYWORD));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAccessors(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user