1 /*
   2  * @test /nodynamiccopyright/
   3  * @summary bad declaration annotations on records
   4  * @compile/fail/ref=BadAnnotations.out -XDrawDiagnostics BadAnnotations.java
   5  */
   6 
   7 import java.lang.annotation.*;
   8 
   9 class BadAnnotations {
  10     // negative cases
  11     @Target({ ElementType.CONSTRUCTOR })
  12     @interface Foo1 {}
  13     record R1(@Foo1 int i) {}
  14 
  15     @Target({ ElementType.TYPE })
  16     @interface Foo2 {}
  17     record R2(@Foo2 int i) {}
  18 
  19     @Target({ ElementType.LOCAL_VARIABLE })
  20     @interface Foo3 {}
  21     record R3(@Foo3 int i) {}
  22 
  23     @Target({ ElementType.PACKAGE })
  24     @interface Foo4 {}
  25     record R4(@Foo4 int i) {}
  26 
  27     @Target({ ElementType.MODULE })
  28     @interface Foo5 {}
  29     record R5(@Foo5 int i) {}
  30 
  31     // positive cases
  32     @Target({ ElementType.FIELD })
  33     @interface Foo6 {}
  34     record R6(@Foo6 int i) {}
  35 
  36     @Target({ ElementType.METHOD })
  37     @interface Foo7 {}
  38     record R7(@Foo7 int i) {}
  39 
  40     @Target({ ElementType.PARAMETER })
  41     @interface Foo8 {}
  42     record R8(@Foo8 int i) {}
  43 
  44     // no target applies to all
  45     @interface Foo9 {}
  46     record R9(@Foo9 int i) {}
  47 
  48     // type annotations are allowed too
  49     @Target({ ElementType.TYPE_USE })
  50     @interface Foo10 {}
  51     record R10(@Foo10 int i) {}
  52 
  53     @Target({ ElementType.TYPE_PARAMETER })
  54     @interface Foo11 {}
  55     record R11(@Foo11 int i) {}
  56 }