1 /*
   2  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
  25 
  26 /*
  27  * @test
  28  * @summary Test population of reference info for field
  29  * @compile -g Driver.java ReferenceInfoUtil.java Fields.java
  30  * @run main Driver Fields
  31  */
  32 public class Fields {
  33     // field types
  34     @TADescription(annotation = "TA", type = FIELD)
  35     public String fieldAsPrimitive() {
  36         return "@TA int test;";
  37     }
  38 
  39     @TADescription(annotation = "TA", type = FIELD)
  40     public String fieldAsObject() {
  41         return "@TA Object test;";
  42     }
  43 
  44     @TADescriptions({
  45         @TADescription(annotation = "TA", type = FIELD),
  46         @TADescription(annotation = "TB", type = FIELD,
  47                 genericLocation = { 3, 0 }),
  48         @TADescription(annotation = "TC", type = FIELD,
  49                 genericLocation = { 3, 1 }),
  50         @TADescription(annotation = "TD", type = FIELD,
  51                 genericLocation = { 3, 1, 3, 0 })
  52     })
  53     public String fieldAsParametrized() {
  54         return "@TA Map<@TB String, @TC List<@TD String>> test;";
  55     }
  56 
  57     @TADescriptions({
  58         @TADescription(annotation = "TA", type = FIELD),
  59         @TADescription(annotation = "TB", type = FIELD,
  60                 genericLocation = { 0, 0 }),
  61         @TADescription(annotation = "TC", type = FIELD,
  62                 genericLocation = { 0, 0, 0, 0 })
  63     })
  64     public String fieldAsArray() {
  65         return "@TC String @TA [] @TB [] test;";
  66     }
  67 
  68     @TADescriptions({
  69         @TADescription(annotation = "TA", type = FIELD),
  70         @TADescription(annotation = "TB", type = FIELD,
  71                 genericLocation = { 0, 0 }),
  72         @TADescription(annotation = "TC", type = FIELD,
  73                 genericLocation = { 0, 0, 0, 0 })
  74     })
  75     public String fieldAsArrayOld() {
  76         return "@TC String test @TA [] @TB [];";
  77     }
  78 
  79     @TADescriptions({})
  80     public String fieldWithDeclarationAnnotatin() {
  81         return "@Decl String test;";
  82     }
  83 
  84     @TADescriptions({})
  85     public String fieldWithNoTargetAnno() {
  86         return "@A String test;";
  87     }
  88 
  89     // Smoke tests
  90     @TADescription(annotation = "TA", type = FIELD)
  91     public String interfacefieldAsObject() {
  92         return "interface Test { @TA String test = null; }";
  93     }
  94 
  95     @TADescription(annotation = "TA", type = FIELD)
  96     public String abstractfieldAsObject() {
  97         return "abstract class Test { @TA String test; }";
  98     }
  99 
 100     @TADescriptions({
 101         @TADescription(annotation = "TA", type = FIELD),
 102         @TADescription(annotation = "TB", type = FIELD,
 103                 genericLocation = { 3, 0 }),
 104         @TADescription(annotation = "TC", type = FIELD,
 105                 genericLocation = { 3, 1 }),
 106         @TADescription(annotation = "TD", type = FIELD,
 107                 genericLocation = { 3, 1, 3, 0 })
 108     })
 109     public String interfacefieldAsParametrized() {
 110         return "interface Test { @TA Map<@TB String, @TC List<@TD String>> test = null; }";
 111     }
 112 
 113 
 114     @TADescriptions({
 115         @TADescription(annotation = "TA", type = FIELD),
 116         @TADescription(annotation = "TB", type = FIELD,
 117                 genericLocation = { 3, 0 }),
 118         @TADescription(annotation = "TC", type = FIELD,
 119                 genericLocation = { 3, 1 }),
 120         @TADescription(annotation = "TD", type = FIELD,
 121                 genericLocation = { 3, 1, 3, 0 })
 122     })
 123     public String staticFieldAsParametrized() {
 124         return "static @TA Map<@TB String, @TC List<@TD String>> test;";
 125     }
 126 }