Report warning (1.2) or error (1.3) on local annotations
#KT-23277 Fixed #KT-23589 Fixed
This commit is contained in:
@@ -227,6 +227,9 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtAnnotationEntry> ANNOTATION_USED_AS_ANNOTATION_ARGUMENT = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> ANNOTATION_ARGUMENT_IS_NON_CONST = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory0<KtClassOrObject> LOCAL_ANNOTATION_CLASS = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtClassOrObject> LOCAL_ANNOTATION_CLASS_ERROR = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, FqName> ILLEGAL_KOTLIN_VERSION_STRING_VALUE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> NEWER_VERSION_IN_SINCE_KOTLIN = DiagnosticFactory1.create(WARNING);
|
||||
|
||||
|
||||
+3
@@ -831,6 +831,9 @@ public class DefaultErrorMessages {
|
||||
MAP.put(ANNOTATION_USED_AS_ANNOTATION_ARGUMENT, "An annotation can't be used as the annotations argument");
|
||||
MAP.put(ANNOTATION_ARGUMENT_IS_NON_CONST, "An annotation argument must be a compile-time constant");
|
||||
|
||||
MAP.put(LOCAL_ANNOTATION_CLASS, "Local annotation classes are deprecated and will be unsupported in a future release");
|
||||
MAP.put(LOCAL_ANNOTATION_CLASS_ERROR, "Annotation class cannot be local");
|
||||
|
||||
MAP.put(CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, "Const 'val' are only allowed on top level or in objects");
|
||||
MAP.put(CONST_VAL_WITH_DELEGATE, "Const 'val' should not have a delegate");
|
||||
MAP.put(CONST_VAL_WITH_GETTER, "Const 'val' should not have a getter");
|
||||
|
||||
@@ -309,6 +309,7 @@ class DeclarationsChecker(
|
||||
|
||||
private fun checkClass(classDescriptor: ClassDescriptorWithResolutionScopes, classOrObject: KtClassOrObject) {
|
||||
checkSupertypesForConsistency(classDescriptor, classOrObject)
|
||||
checkLocalAnnotation(classDescriptor, classOrObject)
|
||||
checkTypesInClassHeader(classOrObject)
|
||||
|
||||
when (classOrObject) {
|
||||
@@ -328,6 +329,16 @@ class DeclarationsChecker(
|
||||
checkPrivateExpectedDeclaration(classOrObject, classDescriptor)
|
||||
}
|
||||
|
||||
private fun checkLocalAnnotation(classDescriptor: ClassDescriptor, classOrObject: KtClassOrObject) {
|
||||
if (classDescriptor.kind == ClassKind.ANNOTATION_CLASS && DescriptorUtils.isLocal(classDescriptor)) {
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.ProhibitLocalAnnotations)) {
|
||||
trace.report(LOCAL_ANNOTATION_CLASS_ERROR.on(classOrObject))
|
||||
} else {
|
||||
trace.report(LOCAL_ANNOTATION_CLASS.on(classOrObject))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkTypesInClassHeader(classOrObject: KtClassOrObject) {
|
||||
fun KtTypeReference.type(): KotlinType? = trace.bindingContext.get(TYPE, this)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user