changeset 56944:d5b1f8f224cd records-and-sealed

adding support for type annotations on records
author vromero
date Wed, 17 Jul 2019 13:21:19 -0400
parents 716120c32641
children 63cb5c34b41e d5ddf73923db
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java test/langtools/tools/javac/records/annotations/BadAnnotations.java test/langtools/tools/javac/records/annotations/BadAnnotations.out
diffstat 3 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 17 10:27:54 2019 -0400
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 17 13:21:19 2019 -0400
@@ -2864,7 +2864,12 @@
             Name[] targets = getTargetNames(a, s);
             boolean appliesToRecords = false;
             for (Name target : targets) {
-                appliesToRecords = target == names.FIELD || target == names.PARAMETER || target == names.METHOD;
+                appliesToRecords =
+                                target == names.FIELD ||
+                                target == names.PARAMETER ||
+                                target == names.METHOD ||
+                                target == names.TYPE_USE ||
+                                target == names.TYPE_PARAMETER;
                 if (appliesToRecords) {
                     break;
                 }
--- a/test/langtools/tools/javac/records/annotations/BadAnnotations.java	Wed Jul 17 10:27:54 2019 -0400
+++ b/test/langtools/tools/javac/records/annotations/BadAnnotations.java	Wed Jul 17 13:21:19 2019 -0400
@@ -4,12 +4,10 @@
  * @compile/fail/ref=BadAnnotations.out -XDrawDiagnostics BadAnnotations.java
  */
 
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
 
 class BadAnnotations {
+    // negative cases
     @Target({ ElementType.CONSTRUCTOR })
     @interface Foo1 {}
     record R1(@Foo1 int i) {}
@@ -46,4 +44,13 @@
     // no target applies to all
     @interface Foo9 {}
     record R9(@Foo9 int i) {}
+
+    // type annotations are allowed too
+    @Target({ ElementType.TYPE_USE })
+    @interface Foo10 {}
+    record R10(@Foo10 int i) {}
+
+    @Target({ ElementType.TYPE_PARAMETER })
+    @interface Foo11 {}
+    record R11(@Foo11 int i) {}
 }
--- a/test/langtools/tools/javac/records/annotations/BadAnnotations.out	Wed Jul 17 10:27:54 2019 -0400
+++ b/test/langtools/tools/javac/records/annotations/BadAnnotations.out	Wed Jul 17 13:21:19 2019 -0400
@@ -1,6 +1,6 @@
-BadAnnotations.java:15:15: compiler.err.annotation.type.not.applicable
-BadAnnotations.java:19:15: compiler.err.annotation.type.not.applicable
-BadAnnotations.java:23:15: compiler.err.annotation.type.not.applicable
-BadAnnotations.java:27:15: compiler.err.annotation.type.not.applicable
-BadAnnotations.java:31:15: compiler.err.annotation.type.not.applicable
+BadAnnotations.java:13:15: compiler.err.annotation.type.not.applicable
+BadAnnotations.java:17:15: compiler.err.annotation.type.not.applicable
+BadAnnotations.java:21:15: compiler.err.annotation.type.not.applicable
+BadAnnotations.java:25:15: compiler.err.annotation.type.not.applicable
+BadAnnotations.java:29:15: compiler.err.annotation.type.not.applicable
 5 errors