Annotations inheritance. Either prohibit or implement correctly #KT-3225 Fixed

This commit is contained in:
Natalia Ukhorskaya
2013-12-18 19:31:28 +04:00
parent cce6b952bd
commit 5d2cb2f97b
5 changed files with 19 additions and 0 deletions
@@ -111,6 +111,7 @@ public interface Errors {
// Annotations
DiagnosticFactory0<JetDelegationSpecifierList> SUPERTYPES_FOR_ANNOTATION_CLASS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetParameter> MISSING_VAL_ON_ANNOTATION_PARAMETER = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetCallExpression> ANNOTATION_CLASS_CONSTRUCTOR_CALL = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<JetAnnotationEntry, String> NOT_AN_ANNOTATION_CLASS = DiagnosticFactory1.create(ERROR);
@@ -451,6 +451,7 @@ public class DefaultErrorMessages {
MAP.put(TYPE_PARAMETER_AS_REIFIED, "Cannot use ''{0}'' as reified type parameter. Use a class instead.", NAME);
MAP.put(SUPERTYPES_FOR_ANNOTATION_CLASS, "Annotation class cannot have supertypes");
MAP.put(MISSING_VAL_ON_ANNOTATION_PARAMETER, "'val' keyword is missing on annotation parameter");
MAP.put(ANNOTATION_CLASS_CONSTRUCTOR_CALL, "Annotation class cannot be instantiated");
MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", TO_STRING);
@@ -283,6 +283,10 @@ public class BodyResolver {
delegationSpecifier.accept(visitor);
}
if (DescriptorUtils.isAnnotationClass(descriptor) && jetClass.getDelegationSpecifierList() != null) {
trace.report(SUPERTYPES_FOR_ANNOTATION_CLASS.on(jetClass.getDelegationSpecifierList()));
}
Set<TypeConstructor> parentEnum =
jetClass instanceof JetEnumEntry
? Collections.singleton(((ClassDescriptor) descriptor.getContainingDeclaration()).getTypeConstructor())
@@ -0,0 +1,8 @@
val a = object: T {}
open class C
trait T
annotation class Ann: <!SUPERTYPES_FOR_ANNOTATION_CLASS!>C()<!>
annotation class Ann2: <!SUPERTYPES_FOR_ANNOTATION_CLASS!>T<!>
annotation class Ann3: <!SUPERTYPES_FOR_ANNOTATION_CLASS!>T by a<!>
annotation class Ann4: <!SUPERTYPES_FOR_ANNOTATION_CLASS!>C(), T<!>
@@ -540,6 +540,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForObject.kt");
}
@TestMetadata("annotationInheritance.kt")
public void testAnnotationInheritance() throws Exception {
doTest("compiler/testData/diagnostics/tests/annotations/annotationInheritance.kt");
}
@TestMetadata("annotationModifier.kt")
public void testAnnotationModifier() throws Exception {
doTest("compiler/testData/diagnostics/tests/annotations/annotationModifier.kt");