'annotation' keyword should be allowed only on classes
#KT-2785 Fixed
This commit is contained in:
@@ -116,6 +116,8 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<PsiElement> ANNOTATION_CLASS_WITH_BODY = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<PsiElement> ANNOTATION_CLASS_WITH_BODY = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<JetTypeReference> INVALID_TYPE_OF_ANNOTATION_MEMBER = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetTypeReference> INVALID_TYPE_OF_ANNOTATION_MEMBER = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<JetTypeReference> NULLABLE_TYPE_OF_ANNOTATION_MEMBER = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetTypeReference> NULLABLE_TYPE_OF_ANNOTATION_MEMBER = DiagnosticFactory0.create(ERROR);
|
||||||
|
DiagnosticFactory0<JetModifierListOwner> ILLEGAL_ANNOTATION_KEYWORD = DiagnosticFactory0
|
||||||
|
.create(ERROR, modifierSetPosition(JetTokens.ANNOTATION_KEYWORD));
|
||||||
|
|
||||||
// Classes and traits
|
// Classes and traits
|
||||||
|
|
||||||
|
|||||||
+1
@@ -436,6 +436,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class");
|
MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class");
|
||||||
MAP.put(INVALID_TYPE_OF_ANNOTATION_MEMBER, "Invalid type of annotation member");
|
MAP.put(INVALID_TYPE_OF_ANNOTATION_MEMBER, "Invalid type of annotation member");
|
||||||
MAP.put(NULLABLE_TYPE_OF_ANNOTATION_MEMBER, "An annotation parameter cannot be nullable");
|
MAP.put(NULLABLE_TYPE_OF_ANNOTATION_MEMBER, "An annotation parameter cannot be nullable");
|
||||||
|
MAP.put(ILLEGAL_ANNOTATION_KEYWORD, "''annotation'' keyword is only applicable for class");
|
||||||
|
|
||||||
MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters");
|
MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters");
|
||||||
|
|
||||||
|
|||||||
@@ -90,14 +90,17 @@ public class DeclarationsChecker {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorIfHasEnumModifier(JetModifierListOwner declaration) {
|
private void reportErrorIfHasIllegalModifier(JetModifierListOwner declaration) {
|
||||||
if (declaration.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
if (declaration.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
||||||
trace.report(ILLEGAL_ENUM_ANNOTATION.on(declaration));
|
trace.report(ILLEGAL_ENUM_ANNOTATION.on(declaration));
|
||||||
}
|
}
|
||||||
|
if (declaration.hasModifier(JetTokens.ANNOTATION_KEYWORD)) {
|
||||||
|
trace.report(ILLEGAL_ANNOTATION_KEYWORD.on(declaration));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkObject(JetObjectDeclaration declaration) {
|
private void checkObject(JetObjectDeclaration declaration) {
|
||||||
reportErrorIfHasEnumModifier(declaration);
|
reportErrorIfHasIllegalModifier(declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkClass(JetClass aClass, MutableClassDescriptor classDescriptor) {
|
private void checkClass(JetClass aClass, MutableClassDescriptor classDescriptor) {
|
||||||
@@ -114,7 +117,7 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkTraitModifiers(JetClass aClass) {
|
private void checkTraitModifiers(JetClass aClass) {
|
||||||
reportErrorIfHasEnumModifier(aClass);
|
reportErrorIfHasIllegalModifier(aClass);
|
||||||
JetModifierList modifierList = aClass.getModifierList();
|
JetModifierList modifierList = aClass.getModifierList();
|
||||||
if (modifierList == null) return;
|
if (modifierList == null) return;
|
||||||
if (modifierList.hasModifier(JetTokens.FINAL_KEYWORD)) {
|
if (modifierList.hasModifier(JetTokens.FINAL_KEYWORD)) {
|
||||||
@@ -140,7 +143,7 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor) {
|
private void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor) {
|
||||||
reportErrorIfHasEnumModifier(property);
|
reportErrorIfHasIllegalModifier(property);
|
||||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration instanceof ClassDescriptor) {
|
if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
checkPropertyAbstractness(property, propertyDescriptor, (ClassDescriptor) containingDeclaration);
|
checkPropertyAbstractness(property, propertyDescriptor, (ClassDescriptor) containingDeclaration);
|
||||||
@@ -270,7 +273,7 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
|
protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
|
||||||
reportErrorIfHasEnumModifier(function);
|
reportErrorIfHasIllegalModifier(function);
|
||||||
DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
|
||||||
boolean hasAbstractModifier = function.hasModifier(JetTokens.ABSTRACT_KEYWORD);
|
boolean hasAbstractModifier = function.hasModifier(JetTokens.ABSTRACT_KEYWORD);
|
||||||
checkDeclaredTypeInPublicMember(function, functionDescriptor);
|
checkDeclaredTypeInPublicMember(function, functionDescriptor);
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
annotation class B
|
||||||
|
|
||||||
|
class A {
|
||||||
|
<!ILLEGAL_ANNOTATION_KEYWORD!>annotation<!> class object {}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!ILLEGAL_ANNOTATION_KEYWORD!>annotation<!> object O {}
|
||||||
|
|
||||||
|
<!ILLEGAL_ANNOTATION_KEYWORD!>annotation<!> trait T {}
|
||||||
|
|
||||||
|
<!ILLEGAL_ANNOTATION_KEYWORD!>annotation<!> fun f() = 0
|
||||||
|
|
||||||
|
<!ILLEGAL_ANNOTATION_KEYWORD!>annotation<!> val x = 0
|
||||||
|
|
||||||
|
<!ILLEGAL_ANNOTATION_KEYWORD!>annotation<!> var y = 0
|
||||||
@@ -550,6 +550,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForObject.kt");
|
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("annotationModifier.kt")
|
||||||
|
public void testAnnotationModifier() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/annotations/annotationModifier.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("AnnotationsForClasses.kt")
|
@TestMetadata("AnnotationsForClasses.kt")
|
||||||
public void testAnnotationsForClasses() throws Exception {
|
public void testAnnotationsForClasses() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt");
|
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user