1 /*
   2  * Copyright (c) 2009, 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 population of reference info for class extends clauses
  30  * @modules jdk.compiler/com.sun.tools.classfile
  31  * @compile -g Driver.java ReferenceInfoUtil.java ClassExtends.java
  32  * @run main Driver ClassExtends
  33  */
  34 public class ClassExtends {
  35 
  36     @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1)
  37     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1)
  38     public String regularClass() {
  39         return "class %TEST_CLASS_NAME% extends @TA Object implements Cloneable, @TB Runnable {"
  40                + "  public void run() { } }";
  41     }
  42 
  43     @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1)
  44     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1)
  45     public String regularClassRepeatableAnnotation() {
  46         return "class %TEST_CLASS_NAME% extends @RTA @RTA Object implements Cloneable, @RTB @RTB Runnable {"
  47                 + "  public void run() { } }";
  48     }
  49 
  50     @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1,
  51             genericLocation = { 3, 0 })
  52     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1,
  53             genericLocation  = { 3, 1 })
  54     public String regularClassExtendsParametrized() {
  55         return "class %TEST_CLASS_NAME% extends HashMap<@TA String, String> implements Cloneable, Map<String, @TB String>{ } ";
  56     }
  57 
  58     @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1,
  59             genericLocation = { 3, 0 })
  60     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1,
  61             genericLocation  = { 3, 1 })
  62     public String regularClassExtendsParametrizedRepeatableAnnotation() {
  63         return "class %TEST_CLASS_NAME% extends HashMap<@RTA @RTA String, String> implements Cloneable, Map<String, @RTB @RTB String>{ } ";
  64     }
  65 
  66     @TADescription(annotation = "TA", type = CLASS_EXTENDS, typeIndex = -1)
  67     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1)
  68     public String abstractClass() {
  69         return "abstract class %TEST_CLASS_NAME% extends @TA Date implements Cloneable, @TB Runnable {"
  70                + "  public void run() { } }";
  71     }
  72 
  73     @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1)
  74     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1)
  75     public String abstractClassRepeatableAnnotation() {
  76         return "abstract class %TEST_CLASS_NAME% extends @RTA @RTA Date implements Cloneable, @RTB @RTB Runnable {"
  77                 + "  public void run() { } }";
  78     }
  79 
  80     @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = -1,
  81             genericLocation = { 3, 0 })
  82     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1,
  83             genericLocation  = { 3, 1 })
  84     public String abstractClassExtendsParametrized() {
  85         return "abstract class %TEST_CLASS_NAME% extends HashMap<@RTA @RTA String, String> implements Cloneable, Map<String, @RTB @RTB String>{ } ";
  86     }
  87 
  88     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1)
  89     public String regularInterface() {
  90         return "interface %TEST_CLASS_NAME% extends Cloneable, @TB Runnable { }";
  91     }
  92 
  93     @TADescription(annotation = "RTAs", type = CLASS_EXTENDS, typeIndex = 1)
  94     public String regularInterfaceRepetableAnnotation() {
  95         return "interface %TEST_CLASS_NAME% extends Cloneable, @RTA @RTA Runnable { }";
  96     }
  97 
  98     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1,
  99             genericLocation  = { 3, 1 })
 100     public String regularInterfaceExtendsParametrized() {
 101         return "interface %TEST_CLASS_NAME% extends Cloneable, Map<String, @TB String>{ } ";
 102     }
 103 
 104     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1,
 105             genericLocation  = { 3, 1 })
 106     public String regularInterfaceExtendsParametrizedRepeatableAnnotation() {
 107         return "interface %TEST_CLASS_NAME% extends Cloneable, Map<String, @RTB @RTB String>{ } ";
 108     }
 109 
 110     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1)
 111     public String regularEnum() {
 112         return "enum %TEST_CLASS_NAME% implements Cloneable, @TB Runnable { TEST; public void run() { } }";
 113     }
 114 
 115     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1)
 116     public String regularEnumRepeatableAnnotation() {
 117         return "enum %TEST_CLASS_NAME% implements Cloneable, @RTB @RTB Runnable { TEST; public void run() { } }";
 118     }
 119 
 120     @TADescription(annotation = "TB", type = CLASS_EXTENDS, typeIndex = 1,
 121             genericLocation  = { 3, 0 })
 122     public String regularEnumExtendsParametrized() {
 123         return
 124             "enum %TEST_CLASS_NAME% implements Cloneable, Comparator<@TB String> { TEST;  "
 125             + "public int compare(String a, String b) { return 0; }}";
 126     }
 127 
 128     @TADescription(annotation = "RTBs", type = CLASS_EXTENDS, typeIndex = 1,
 129             genericLocation  = { 3, 0 })
 130     public String regularEnumExtendsParametrizedRepeatableAnnotation() {
 131         return
 132                 "enum %TEST_CLASS_NAME% implements Cloneable, Comparator<@RTB @RTB String> { TEST;  "
 133                         + "public int compare(String a, String b) { return 0; }}";
 134     }
 135 }