1 /*
   2  * Copyright (c) 2012, 2015, 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  * @bug 8042451
  29  * @summary Test that the examples from the manual are stored as expected
  30  * @modules jdk.jdeps/com.sun.tools.classfile
  31  * @compile -g Driver.java ReferenceInfoUtil.java FromSpecification.java
  32  * @run main Driver FromSpecification
  33  */
  34 public class FromSpecification {
  35 
  36     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  37     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  38                 genericLocation = {3, 0}, paramIndex = 0)
  39     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
  40                 genericLocation = {3, 0, 2, 0}, paramIndex = 0)
  41     @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
  42                 genericLocation = {3, 1}, paramIndex = 0)
  43     @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER,
  44                 genericLocation = {3, 1, 3, 0}, paramIndex = 0)
  45     public String testSpec1() {
  46         return "void test(@TA Map<@TB ? extends @TC String, @TD List<@TE Object>> a) { }";
  47     }
  48 
  49     @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  50     @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER,
  51                 genericLocation = {0, 0}, paramIndex = 0)
  52     @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER,
  53                 genericLocation = {0, 0, 0, 0}, paramIndex = 0)
  54     @TADescription(annotation = "TI", type = METHOD_FORMAL_PARAMETER,
  55                 genericLocation = {0, 0, 0, 0, 0, 0}, paramIndex = 0)
  56     public String testSpec2() {
  57         return "void test(@TI String @TF [] @TG [] @TH [] a) { }";
  58     }
  59 
  60     // Note first "1, 0" for top-level class Test.
  61     @TADescription(annotation = "TJ", type = METHOD_FORMAL_PARAMETER,
  62                 genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0)
  63     @TADescription(annotation = "TK", type = METHOD_FORMAL_PARAMETER,
  64                 genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0)
  65     @TADescription(annotation = "TL", type = METHOD_FORMAL_PARAMETER,
  66                 genericLocation = {1, 0, 1, 0}, paramIndex = 0)
  67     @TADescription(annotation = "TM", type = METHOD_FORMAL_PARAMETER,
  68                 genericLocation = {1, 0}, paramIndex = 0)
  69     public String testSpec3() {
  70         return "class %TEST_CLASS_NAME% { class O1 { class O2 { class O3 { class NestedStatic {} } } }" +
  71                 "void test(@TM O1.@TL O2.@TK O3.@TJ NestedStatic a) { } }";
  72     }
  73 
  74     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER, paramIndex = 0)
  75     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  76                 genericLocation = {3, 0}, paramIndex = 0)
  77     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
  78                 genericLocation = {3, 0, 3, 0}, paramIndex = 0)
  79     @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
  80                 genericLocation = {3, 0, 3, 0, 0, 0}, paramIndex = 0)
  81     @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER,
  82                 genericLocation = {3, 0, 3, 0, 0, 0, 0, 0}, paramIndex = 0)
  83     @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER,
  84                 genericLocation = {3, 0, 3, 0, 0, 0, 0, 0, 0, 0}, paramIndex = 0)
  85     @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER,
  86                 genericLocation = {3, 1}, paramIndex = 0)
  87     @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER,
  88                 genericLocation = {3, 1, 3, 0}, paramIndex = 0)
  89     public String testSpec4() {
  90         return "void test(@TA Map<@TB Comparable<@TF Object @TC [] @TD [] @TE []>, @TG List<@TH String>> a) { }";
  91     }
  92 
  93     // Note first "1, 0" for top-level class Test.
  94     @TADescription(annotation = "TA", type = METHOD_FORMAL_PARAMETER,
  95                 genericLocation = {1, 0, 1, 0, 1, 0, 1, 0}, paramIndex = 0)
  96     @TADescription(annotation = "TB", type = METHOD_FORMAL_PARAMETER,
  97                 genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 0}, paramIndex = 0)
  98     @TADescription(annotation = "TC", type = METHOD_FORMAL_PARAMETER,
  99                 genericLocation = {1, 0, 1, 0, 1, 0, 1, 0, 3, 1}, paramIndex = 0)
 100     @TADescription(annotation = "TD", type = METHOD_FORMAL_PARAMETER,
 101                 genericLocation = {1, 0, 1, 0, 1, 0}, paramIndex = 0)
 102     @TADescription(annotation = "TE", type = METHOD_FORMAL_PARAMETER,
 103                 genericLocation = {1, 0, 1, 0}, paramIndex = 0)
 104     @TADescription(annotation = "TF", type = METHOD_FORMAL_PARAMETER,
 105                 genericLocation = {1, 0, 1, 0, 3, 0}, paramIndex = 0)
 106     @TADescription(annotation = "TG", type = METHOD_FORMAL_PARAMETER,
 107                 genericLocation = {1, 0, 1, 0, 3, 1}, paramIndex = 0)
 108     @TADescription(annotation = "TH", type = METHOD_FORMAL_PARAMETER,
 109                 genericLocation = {1, 0}, paramIndex = 0)
 110     public String testSpec5() {
 111         return "class %TEST_CLASS_NAME% { class O1 { class O2<A, B> { class O3 { class Nested<X, Y> {} } } }" +
 112                 "void test(@TH O1.@TE O2<@TF String, @TG String>.@TD O3.@TA Nested<@TB String, @TC String> a) { } }";
 113     }
 114 }