--- /dev/null Thu Aug 8 00:10:00 2013 +++ new/test/type-annotations/AnnotationTest.java Thu Aug 8 00:09:59 2013 @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @bug 8013497 + * @summary Tests for type annotation. + * @author Charlie Wang + */ +import java.util.LinkedHashMap; +import java.util.Map; + +public abstract class AnnotationTest { + + // combinations of annotations to test + public final String[] annotationCombinations = new String[]{ + "", + Helper.Declaration.ANNOTATION_TYPE_1 + " ", + Helper.Declaration.ANNOTATION_TYPE_1 + " " + + Helper.Declaration.ANNOTATION_TYPE_2 + " " + + Helper.Declaration.ANNOTATION_TYPE_3 + " ", + Helper.Declaration.ANNOTATION_TYPE_2 + " " + + Helper.Declaration.ANNOTATION_TYPE_2 + " " + + Helper.Declaration.ANNOTATION_TYPE_2 + " ", + Helper.Declaration.ANNOTATION_TYPE_3 + " " + + Helper.Declaration.ANNOTATION_TYPE_3 + " " + + Helper.Declaration.ANNOTATION_TYPE_3 + " ", + Helper.Declaration.ANNOTATION_TYPE_3 + " "}; + // unique index number for class names generated for test + public static int clsIdx = 0; + // a place to hold class name -- annotation correspondence + public static Map testInput = new LinkedHashMap<>(); + + public AnnotationTest() { + clsIdx = 0; + testInput.clear(); + } + + public void test() throws Exception { + if (!checkResult()) { + throw new RuntimeException("test fail."); + } else { + System.out.println("Pass."); + } + } + + public static synchronized String genBaseClass(String str) { + Map lhm = new LinkedHashMap<>(); + String testCode = ""; + lhm.put(Helper.Declaration.IMPORT, null); + lhm.put(Helper.Declaration.CLASS, str); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_3, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_3, ""); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + return testCode; + } + + protected Class loadClass(Object clsName) throws Exception { + // Get Class object for the compiled class + Class cls = null; + if (clsName instanceof String) { + cls = Helper.loadClass((String) clsName); + } else { + cls = (Class) clsName; + } + return cls; + } + + protected void compileCode(Class tcg) throws Exception { + String testCode = GenTestCode(tcg); + Helper.debugPrint(testCode); + ClassLoader parentClassLoader = getClass().getClassLoader(); + // compile files into classes + Helper.genClass(testCode, parentClassLoader, + TestCaseGenerator.testBaseClsName); + } + + protected String GenTestCode(Class tcg) { + String testCode = ""; + for (Object tc : tcg.getEnumConstants()) { + for (String anno : annotationCombinations) { + testCode += ((TestCaseGenerator) tc).genTestCase(anno); + } + } + return testCode; + } + + protected abstract boolean checkResult() throws Exception; +} --- /dev/null Thu Aug 8 00:10:02 2013 +++ new/test/type-annotations/DeclarationGenerator.java Thu Aug 8 00:10:01 2013 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @bug 8013497 + * @summary Construct source used for annotation test. + * @author Charlie Wang + */ +public interface DeclarationGenerator { + + public String getSrc(String... annoStr); +} --- /dev/null Thu Aug 8 00:10:03 2013 +++ new/test/type-annotations/Helper.java Thu Aug 8 00:10:03 2013 @@ -0,0 +1,974 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @bug 8013497 + * @summary Utility class for constructing, compiling and execute code + * @author Charlie Wang + */ +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.JavaCompiler; +import javax.tools.JavaCompiler.CompilationTask; +import javax.tools.JavaFileObject.Kind; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.StandardJavaFileManager; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; +import com.sun.source.util.JavacTask; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.AnnotatedArrayType; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.Map; + +/** + * Helper provides below features for annotation test: + * 1. Code construction - SrcType + * SrcType contains all parts of source code needed to construct a class + * for annotation test. In each enum's getSrc(), it supports to replace [#ANNO] + * and [TYPE] AND [NAME], which is usually all the elements needed to construct + * a small snippet like package, class, method, field etc. + * 2. Code compile and load + * compilecode() and loadClass compiles test code and then load it to + * memory. All users need to do is to construct a class code, send it to Helper, + * then they would get a class object of the test object which is enough for + * annotation test. + */ +public class Helper { + + // Set it to true to get more debug information + static final boolean DEBUG = false; + + public enum Declaration implements DeclarationGenerator { + + PACKAGE_INFO("[#ANNO] \npackage #NAME; \n"), + PACKAGE("\npackage #NAME; \n"), + IMPORT("\nimport java.io.*;\n" + + "import java.util.*;\n" + + "import java.lang.*;\n" + + "import java.lang.reflect.*;\n" + + "import java.lang.annotation.*;\n") { + public String getSrc(String... annoStr) { + if (null == annoStr) { + return template; + } else if (0 == annoStr.length) { + return ""; + } else if (1 == annoStr.length) { + return annoStr[0]; + } else { + throw new RuntimeException("illegal input for declaration!"); + } + } + }, + CLASS("\n[#ANNO] \nclass #NAME"), + INTERFACE("\n[#ANNO] \ninterface #NAME"), + EXTENDS(" extends [#ANNO] #NAME"), + IMPLEMENTS(" implements [[#ANNO] #NAME, ]") { + public String getSrc(String... annoStr) { + return IMPLEMENTS.replaceMultipleAnnoStr(annoStr); + } + }, + GENERICS1("<[[#ANNO1] #TYPE1 [#INHERITANCE [#ANNO2] #TYPE2], ]>") { + // input should be like ["@realanno1 Type1 + //extends @realanno2 Type2", "@realanno3 Type3 + //super @realanno4 Type4"] + public String getSrc(String... annoStr) { + if (null == annoStr || 0 == annoStr.length) { + return ""; + } + + String temp = template; + for (String as : annoStr) { + temp = temp.replaceAll("\\[\\[#ANNO1\\] #TYPE1 " + + "\\[#INHERITANCE \\[#ANNO2\\] #TYPE2\\], \\]", + "[#ANNO1] #TYPE1 [#INHERITANCE [#ANNO2] #TYPE2], " + + "[[#TMP_ANNO1] #TMP_TYPE1 [#TMP_INHERITANCE " + + "[#TMP_ANNO2] #TMP_TYPE2], ]"); + + int j = 0; // index of ) + String ss = as.trim(); + + // put @anno to [#ANNO1] + String[] sa = GENERICS1.replaceAnnoStr(ss, temp, + "\\[#ANNO1\\]", " [#ANNO1]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE1 + if (0 == ss.length()) { + throw new RuntimeException("illegal generics1."); + } + j = ss.indexOf(" "); + String type = (j == -1 ? ss : ss.substring(0, j)); + temp = temp.replaceFirst("#TYPE1", type); + if (-1 != j) { + ss = ss.substring(j).trim(); + } + + // get #INHERITANCE + if (ss.startsWith("extends") || ss.startsWith("super")) { + temp = temp.replaceAll("\\[#INHERITANCE " + + "\\[#ANNO2\\] #TYPE2\\]", + "#INHERITANCE \\[#ANNO2\\] #TYPE2"); + + j = ss.indexOf(" "); + if (-1 == j) { + throw new RuntimeException("illegal generics1."); + } + String inheritance = ss.substring(0, j); + temp = temp.replaceFirst("#INHERITANCE", inheritance); + ss = ss.substring(j).trim(); + + // put @anno to [#ANNO2] + sa = GENERICS1.replaceAnnoStr(ss, temp, "\\[#ANNO2\\]", + " [#ANNO2]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE2 + if (0 == ss.length() || -1 < ss.indexOf(" ")) { + throw new RuntimeException("illegal generics1."); + } + type = ss; + temp = temp.replaceFirst("#TYPE2", type); + } else { + temp = temp.replaceAll("\\[#INHERITANCE \\[#ANNO2\\] " + + "#TYPE2\\]", ""); + } + temp = temp.replaceAll("TMP_", ""); + } + + return temp.replaceAll(", \\[\\[#ANNO1\\] #TYPE1 " + + "\\[#INHERITANCE \\[#ANNO2\\] #TYPE2\\], \\]", ""); + } + }, + GENERICS2("<[[#ANNO1] #TYPE1 " + + "extends [#ANNO2] #TYPE2 & [#ANNO3] #TYPE3, ]>") { + // input should be like ["@realanno1 Type1 + // @realanno2 Type2" "@realanno3 Type3] + public String getSrc(String... annoStr) { + if (null == annoStr || 0 == annoStr.length) { + return ""; + } + String temp = template; + for (String as : annoStr) { + temp = temp.replaceAll("\\[\\[#ANNO1\\] #TYPE1 " + + "extends \\[#ANNO2\\] #TYPE2 " + + "& \\[#ANNO3\\] #TYPE3, \\]", + "[#ANNO1\\] #TYPE1 extends \\[#ANNO2\\] #TYPE2 " + + "& \\[#ANNO3\\] #TYPE3, " + + "\\[\\[#TMP_ANNO1\\] #TTMP_YPE1 " + + "extends \\[#TMP_ANNO2\\] #TMP_TYPE2 " + + "& \\[#TMP_ANNO3\\] #TMP_TYPE3, \\]"); + int j = 0; + String ss = as.trim(); + // put @anno to [#ANNO1] + String[] sa = GENERICS2.replaceAnnoStr(ss, temp, + "\\[#ANNO1\\]", " [#ANNO1]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE1 + if (0 == ss.length()) { + throw new RuntimeException("illegal generics2."); + } + j = ss.indexOf(" "); + if (-1 == j) { + throw new RuntimeException("illegal generics2."); + } + String type = ss.substring(0, j).trim(); + ss = ss.substring(j).trim(); + temp = temp.replaceFirst("#TYPE1", type); + + // put @anno to [#ANNO2] + sa = GENERICS2.replaceAnnoStr(ss, temp, "\\[#ANNO2\\]", + " [#ANNO2]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE2 + if (0 == ss.length()) { + throw new RuntimeException("illegal generics2."); + } + j = ss.indexOf(" "); + if (-1 == j) { + throw new RuntimeException("illegal generics2."); + } + type = ss.substring(0, j).trim(); + ss = ss.substring(j).trim(); + temp = temp.replaceFirst("#TYPE2", type); + + // put @anno to [#ANNO3] + sa = GENERICS2.replaceAnnoStr(ss, temp, "\\[#ANNO3\\]", + " [#ANNO3]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE1 + if (0 == ss.length()) { + throw new RuntimeException("illegal generics2."); + } + j = ss.indexOf(" "); + if (-1 != j) { + throw new RuntimeException("illegal generics2."); + } + type = ss.trim(); + temp = temp.replaceFirst("#TYPE3", type); + + temp = temp.replaceAll("TMP_", ""); + } + + return temp.replaceAll(", \\[\\[#ANNO1\\] #TYPE1 " + + "extends \\[#ANNO2\\] #TYPE2 " + + "& \\[#ANNO3\\] #TYPE3, \\]", ""); + } + }, + CLASS_BODY_START(" {\n") { + public String getSrc(String... annoStr) { + if (0 == annoStr.length) { + return ""; + } else { + return template; + } + } + }, + FIELD_TYPE(" public [#ANNO] #NAME"), + FIELD_ARRAY(" [[#ANNO] [] ] ") { + // input should be like ["@A() @B()", "@C() @D()"...] + public String getSrc(String... annoStr) { + if (null == annoStr || 0 == annoStr.length) { + return ""; + } + + String temp = template; + for (String as : annoStr) { + temp = temp.replaceAll("\\[\\[#ANNO\\] \\[\\] \\]", + "[#ANNO] [] [[#TMP_ANNO] [] ]"); + // replace "[#ANNO]..." with "@realannotation [#ANNO]..." + String ss = as.trim(); + String[] sa = FIELD_ARRAY.replaceAnnoStr(ss, temp, + "\\[#ANNO\\]", " [#ANNO]"); + ss = sa[0]; + temp = sa[1].replaceAll("TMP_", ""); + } + return temp.replaceAll("\\[\\[#ANNO\\] \\[\\] \\]", ""); + } + }, + FIELD_NAME(" #NAME;\n"), + CONSTRUCTOR_HEADER("\n public [#ANNO] #NAME"), + METHOD_HEADER("\n public [#ANNO] #TYPE #NAME") { + // input should be like "@realanno Type method" + public String getSrc(String... annoStr) { + if (0 == annoStr.length) { + return ""; + } + + String temp = template; + for (String as : annoStr) { + int j = 0; // index of ")" + String ss = as.trim(); + + String[] sa = METHOD_HEADER.replaceAnnoStr(ss, temp, + "\\[#ANNO\\]", " [#ANNO]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE + if (j == ss.length()) { + throw new RuntimeException("illegal method head."); + } + j = ss.indexOf(" ") + 1; + if (0 == j) { + throw new RuntimeException("illegal method head."); + } + String type = ss.substring(0, j); + temp = temp.replaceFirst("#TYPE", type); + ss = ss.substring(j).trim(); + + // get #NAME + if (0 <= ss.indexOf(" ") || 0 == ss.length()) { + throw new RuntimeException("illegal method head."); + } + temp = temp.replaceFirst("#NAME", ss); + } + + return temp; + } + }, + METHOD_PARAMETER("([[#ANNO] #TYPE #NAME, ])") { + // input should be like "@realanno Type arg" + public String getSrc(String... annoStr) { + if (null == annoStr || 0 == annoStr.length) { + return ""; + } + + if (1 == annoStr.length && "".equals(annoStr[0])) { + return "()"; + } + + String temp = template; + for (String as : annoStr) { + temp = temp.replaceFirst("\\[\\[#ANNO\\] #TYPE #NAME, \\]", + "[#ANNO] #TYPE #NAME, " + + "[[#TMP_ANNO] #TMP_TYPE #TMP_NAME, ]"); + + int j = 0; + String ss = as.trim(); + + String[] sa = METHOD_PARAMETER.replaceAnnoStr(ss, temp, + "\\[#ANNO\\]", " [#ANNO]"); + ss = sa[0]; + temp = sa[1]; + + // get #TYPE + if (j == ss.length()) { + throw new RuntimeException("illegal method parameter."); + } + j = ss.indexOf(" ") + 1; + if (0 == j) { + throw new RuntimeException("illegal method parameter."); + } + String type = ss.substring(0, j); + temp = temp.replaceFirst("#TYPE", type); + ss = ss.substring(j).trim(); + + // get #NAME + if (0 <= ss.indexOf(" ") || 0 == ss.length()) { + throw new RuntimeException("illegal method parameter."); + } + temp = temp.replaceFirst("#NAME", ss); + + temp = temp.replaceAll("TMP_", ""); + } + + return temp.replaceAll(", \\[\\[#ANNO\\] #TYPE #NAME, \\]", ""); + } + }, + METHOD_EXCEPTION(" throws [[#ANNO] #NAME, ]") { + public String getSrc(String... annoStr) { + return METHOD_EXCEPTION.replaceMultipleAnnoStr(annoStr); + } + }, + METHOD_BODY(" {return null;}\n") { + public String getSrc(String... annoStr) { + if (null == annoStr || 0 == annoStr.length) { + return ""; + } else if (1 == annoStr.length && !"".equals(annoStr[0])) { + return annoStr[0]; + } else { + return template; + } + } + }, + CLASS_BODY_END("\n}\n") { + public String getSrc(String... annoStr) { + return CLASS_BODY_END.getDefSrc(annoStr); + } + }, + ANNOTATION_TYPE_1("\n@Target(ElementType.TYPE_USE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\n@Repeatable(TypeAnno1Container.class)" + + "\n@interface TypeAnno1 {" + + "\n String value();" + + "\n}") { + public String getSrc(String... annoStr) { + return ANNOTATION_TYPE_1.getDefSrc(annoStr); + } + + public String toString() { + return "@TypeAnno1(\"TypeAnno1\")"; + } + }, + ANNOTATION_TYPE_2("\n@Target(ElementType.TYPE_USE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\n@Repeatable(TypeAnno2Container.class)" + + "\n@interface TypeAnno2 {" + + "\n String value();" + + "\n}") { + public String getSrc(String... annoStr) { + return ANNOTATION_TYPE_2.getDefSrc(annoStr); + } + + public String toString() { + return "@TypeAnno2(\"TypeAnno2\")"; + } + }, + ANNOTATION_TYPE_3("\n@Target(ElementType.TYPE_USE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\n@Repeatable(TypeAnno3Container.class)" + + "\n@interface TypeAnno3 {" + + "\n}") { + public String getSrc(String... annoStr) { + return ANNOTATION_TYPE_3.getDefSrc(annoStr); + } + + public String toString() { + return "@TypeAnno3"; + } + }, + CONTAINING_ANNOTATION_TYPE_1("\n@Target(ElementType.TYPE_USE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\n@interface TypeAnno1Container {" + + "\n TypeAnno1[] value();" + + "\n}") { + public String getSrc(String... annoStr) { + return CONTAINING_ANNOTATION_TYPE_1.getDefSrc(annoStr); + } + }, + CONTAINING_ANNOTATION_TYPE_2("\n@Target(ElementType.TYPE_USE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\n@interface TypeAnno2Container {" + + "\n TypeAnno2[] value();" + + "\n}") { + public String getSrc(String... annoStr) { + return CONTAINING_ANNOTATION_TYPE_2.getDefSrc(annoStr); + } + }, + CONTAINING_ANNOTATION_TYPE_3("\n@Target(ElementType.TYPE_USE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\n@interface TypeAnno3Container {" + + "\n TypeAnno3[] value();" + + "\n}") { + public String getSrc(String... annoStr) { + return CONTAINING_ANNOTATION_TYPE_3.getDefSrc(annoStr); + } + }, + PACKAGE_ANNOTATION_1("\n@Target(ElementType.PACKAGE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\npublic @interface PkgAnno1 {" + + "\n String value();" + + "\n}") { + public String getSrc(String... annoStr) { + return PACKAGE_ANNOTATION_1.getDefSrc(annoStr); + } + + public String toString() { + return "@pkg.PkgAnno1(\"PkgAnno1\")"; + } + }, + PACKAGE_ANNOTATION_2("\n@Target(ElementType.PACKAGE)" + + "\n@Retention(RetentionPolicy.RUNTIME)" + + "\npublic @interface PkgAnno2 {" + + "\n String value();" + + "\n}") { + public String getSrc(String... annoStr) { + return PACKAGE_ANNOTATION_2.getDefSrc(annoStr); + } + + public String toString() { + return "@pkg.PkgAnno2(\"PkgAnno2\")"; + } + }; + String template = ""; + + private Declaration(String template) { + this.template = template; + } + + /** + * Gets the first annotation of the input string + * @param str a string headed by annotation(s) + * @return [first anno, the rest of the str] + */ + private String[] getFirstAnno(String str) { + if (null == str) { + throw new RuntimeException("illegal input."); + } + + String[] ret = new String[2]; + str = str.trim(); + int i = str.indexOf("@"); + int j = str.indexOf(" "); + if (-1 == j) { + j = str.length(); + } + // annotation check - should be like @A or @A() or @A("...") + if (2 > j - i) { + throw new RuntimeException("illegal annotation."); + } + ret[0] = str.substring(i, j); + ret[1] = str.substring(j).trim(); + return ret; + } + + /** + * Change [#ANNO] #NAME into @annotation name + * @param annoStr @annotation + name to be extracted + * @return desired string with @annotation and name + */ + private String replaceMultipleAnnoStr(String... annoStr) { + if (0 == annoStr.length) { + return ""; + } + + String temp = template; + for (String as : annoStr) { + temp = temp.replaceAll("\\[\\[#ANNO\\] #NAME, \\]", + "[#ANNO] #NAME, [[#TMP_ANNO] #TMP_NAME, ]"); + // replace "[#ANNO]..." with "@realannotation [#ANNO]..." + int i = 0; // index of @ + int j = 0; // index of " " + for (; -1 != as.indexOf("@", j);) { + i = as.indexOf("@", j); + j = as.indexOf(" ", i); + // annotation check - should be like @A or @A() or @A("...") + if (2 > j - i) { + throw new RuntimeException("illegal annotation."); + } + String anno = as.substring(i, j); + temp = temp.replaceFirst("\\[#ANNO\\]", anno + " [#ANNO]"); + + } + String name = as.substring(j, as.length()).trim(); + temp = temp.replaceAll("#NAME", name).replaceAll( + "\\[#ANNO\\]", ""); + temp = temp.replaceAll("\\[\\[#TMP_ANNO\\] #TMP_NAME, \\]", + "[[#ANNO] #NAME, ]"); + } + return temp.replaceAll(", \\[\\[#ANNO\\] #NAME, \\]", ""); + } + + /** + * Extract annotations from input string and put them in + * declarations + * @param ss + * @param temp + * @param decl + * @param rep1 + * @param rep2 + * @return [the rest of the input string after stripping heading + * annotations, the rest of declaration after stripping [ANNO]] + */ + private String[] replaceAnnoStr(String ss, String temp, + String rep1, String rep2) { + while (ss.startsWith("@")) { + String[] sa = getFirstAnno(ss); + String anno = sa[0]; + ss = sa[1].trim(); + temp = temp.replaceFirst(rep1, anno + rep2); + } + temp = temp.replaceAll(rep1, ""); + + return new String[] {ss, temp}; + } + + private String getDefSrc(String... annoStr) { + if (0 == annoStr.length) { + return ""; + } else { + return template; + } + } + + /** + * Get the template + * @return template + */ + public String getTemplate() { + return template; + } + + /** + * Get the desired source code declaration + * @param annoStr @annotation , type, name combinations + * @return desired source code declaration + */ + public String getSrc(String... annoStr) { + if (0 == annoStr.length || 1 == annoStr.length) { + return replaceMultipleAnnoStr(annoStr); + } else { + throw new RuntimeException( + "illegal input for declaration!"); + } + } + } + + /** + * Generate test code declarations with annotations, which is used + * for test + * @param input contains declaration type - input for declaration to be + * generated correspondences + * @param srcType for simple types like field, import etc. that do not need + * auto correction + * @return test code declarations + */ + public synchronized static String genDeclaration( + Map input, Declaration... srcType) { + StringBuilder result = new StringBuilder(); + // default mode, auto-generate code + if (null == srcType || 0 == srcType.length) { + for (Declaration st : Declaration.values()) { + if (input.containsKey(st)) { + Object temp = input.get(st); + if (temp instanceof String) { + result.append(st.getSrc((String) temp)); + } else { + result.append(st.getSrc((String[]) temp)); + } + + // auto correction, in case input misses class brackets + if (Declaration.CLASS == st || Declaration.INTERFACE == st) { + input.put(Declaration.CLASS_BODY_START, ""); + input.put(Declaration.CLASS_BODY_END, ""); + } + } else { + result.append(st.getSrc()); + } + } + } else { + for (Declaration st : input.keySet()) { + Object temp = input.get(st); + if (temp instanceof String) { + result.append((st).getSrc((String) temp)); + } else { + result.append((st).getSrc((String[]) temp)); + } + } + } + + return result.toString(); + } + + // Compile a list of FileObjects + // Used when packages are needed and classes need to be loaded at runtime + static File destDir = new File(System.getProperty("user.dir")); + + /** + * Compile code + * @param diagnostics diagnostics of the compilation + * @param files files to compile + * @return true - successful compilation, false failed compilation + */ + public static boolean compileCode( + DiagnosticCollector diagnostics, + Iterable files) { + boolean ok = false; + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + if (compiler == null) { + throw new RuntimeException("can't get javax.tools.JavaCompiler!"); + } + StandardJavaFileManager fm = compiler.getStandardFileManager( + null, null, null); + if (isPkgInfoPresent(files)) { + JavacTask task = (JavacTask) compiler.getTask(null, fm, diagnostics, + null, null, files); + try { + fm.setLocation(StandardLocation.CLASS_OUTPUT, + Arrays.asList(destDir)); + task.generate(); + } catch (IOException ioe) { + throw new RuntimeException( + "Compilation failed for package level tests", ioe); + } + ok = true; + for (Diagnostic d + : diagnostics.getDiagnostics()) { + if (d.getKind() == Diagnostic.Kind.ERROR) { + ok = false; + break; + } + } + } else { + CompilationTask task = compiler.getTask(null, null, diagnostics, + null, null, files); + ok = task.call(); + } + return ok; + } + + /** + * Check if package needs to be generated + * @param files + * @return true - yes, false - no + */ + static private boolean isPkgInfoPresent( + Iterable files) { + for (JavaFileObject jfo : files) { + String name = jfo.getName(); + if (name.contains("package-info") || name.contains("PkgAnno")) { + return true; + } + } + return false; + } + + static JavaFileObject getFile(String name, String code) throws Exception{ + return new JavaStringFileObject(name, code); + } + + static class JavaStringFileObject extends SimpleJavaFileObject { + + final String theCode; + public JavaStringFileObject(String fileName, String theCode) + throws URISyntaxException { + super(new URI("string:///" + fileName.replace('.', '/') + ".java"), + Kind.SOURCE); + this.theCode = theCode; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return theCode; + } + } + + private static URLClassLoader URLCL = null; + + private static URLClassLoader getClassLoader() throws Exception { + if (null != URLCL) + return URLCL; + + ClassLoader parentClassLoader = new Helper().getClass().getClassLoader(); + URLCL = getClassLoader(parentClassLoader, destDir); + return URLCL; + } + private static URLClassLoader getClassLoader(ClassLoader parentClassLoader, + File... destDirs) throws Exception { + List list = new ArrayList<>(); + for (File f : destDirs) { + list.add(new URL( + "file:" + f.toString().replace("\\", "/") + "/")); + } + return new URLClassLoader(list.toArray(new URL[list.size()]), + parentClassLoader); + } + + /** + * Load class to class loader + * @param className + * @return loaded class + * @throws Exception + */ + public static Class loadClass(String className) throws Exception { + try { + return Class.forName(className, true, getClassLoader()); + } catch (ClassNotFoundException | MalformedURLException e) { + throw new RuntimeException("Error loading class " + className, e); + } + } + + /** + * Generate class from test code + * @param testCode + * @param parentClassLoader + * @param clsName + * @throws Exception + */ + public static void genClass(String testCode, ClassLoader parentClassLoader, + String clsName) throws Exception { + Map lhm = new LinkedHashMap(); + lhm.put(clsName, testCode); + genClasses(parentClassLoader, lhm); + } + + /** + * Generate classes from test code + * @param parentClassLoader + * @param clsList class name - class code correspondences + * @throws Exception + */ + public static void genClasses(ClassLoader parentClassLoader, + Map clsList) throws Exception { + Iterable files = new ArrayList(); + for (String clsName : clsList.keySet()) { + String testCode = clsList.get(clsName); + ((List) files).add(getFile(clsName, testCode)); + + } + DiagnosticCollector diagnostics = + new DiagnosticCollector<>(); + + // Compile the list of JavaFileObjects + try { + Helper.compileCode(diagnostics, files); + } catch (Exception ex) { + throw new RuntimeException( + "Exception when compiling class "); + } + } + + /** + * Get annotations from annotation object + * @param annotation annotation object + * @return annotation string like @Anno("Anno") + * @throws Exception + */ + public static String getAnno(Annotation annotation) throws Exception { + if (null == annotation) { + return ""; + } + StringBuffer result = new StringBuffer(""); + String annoName = ""; + Object value = null; + try { + Method method = annotation.annotationType().getMethod("value", + new Class[]{}); + method.setAccessible(true); + value = method.invoke(annotation, new Object[]{}); + } catch (NoSuchMethodException e) { + //expected exception for annotations without value + } + + if (null == value) { + annoName = annotation.annotationType().getSimpleName(); + result.append("@" + annoName); + result.append(" "); + } else if (value instanceof String) { + annoName = annotation.annotationType().getSimpleName(); + result.append("@" + annoName); + result.append("(\"" + value + "\") "); + } else { + //for repeated anno + Annotation[] av = (Annotation[]) value; + for (int j = 0; j < av.length; j++) { + annoName = av[j].annotationType().getSimpleName(); + value = " "; + try { + Method method = av[j].annotationType().getMethod("value", + new Class[]{}); + method.setAccessible(true); + value = method.invoke(av[j], new Object[]{}); + value = "(\"" + value + "\") "; + } catch (NoSuchMethodException e) { + //expected exception for annotations without value + } + result.append("@" + annoName); + result.append(value); + } + } + return result.toString(); + } + + /** + * Get annotations from annotation object array + * @param annotations annotation objects + * @return annotation string like @Anno1("Anno1")@Anno2("Anno2") + * @throws Exception + */ + public static String getAnno(Annotation[] annotations) throws Exception { + StringBuffer result = new StringBuffer(""); + if (null != annotations) { + for (int i = 0; i < annotations.length; i++) { + String anno = getAnno(annotations[i]); + if (!"".equals(anno)) { + result.append(anno); + } + } + } + return result.toString(); + } + + /** + * Get AnnotatedType type and value, output as string + * @param at + * @return annotation string like @Anno1("Anno1")@Anno2("Anno2") + * @throws Exception + */ + public static String getAT(AnnotatedType at) throws Exception { + Annotation[] annotations = at.getAnnotations(); + return getAnno(annotations); + } + + /** + * Get AnnotatedArrayType type and value, output as string + * @param at + * @return annotation string like @Anno1("Anno1")@Anno2("Anno2") + * @throws Exception + */ + public static String getArrAT(AnnotatedType at) throws Exception { + String ret = ""; + if (at instanceof AnnotatedArrayType) { + at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType(); + ret += getArrAT(at); + } + Annotation[] annotations = at.getAnnotations(); + return getAnno(annotations) + ";" + ret; + } + + /** + * Get multiple AnnotatedType type and value, output as string + * @param as + * @return list of annotations + * @throws Exception + */ + public static List getMultipleAT(AnnotatedType[] as) throws Exception { + List result = new ArrayList(); + for (int i = 0; i < as.length; i++) { + result.add(getAT(as[i])); + } + return result; + } + + /** + * Compare two string of annotations and check if they contain + * the same annotations + * @param anno1 + * @param anno2 + * @return true - yes, false - no + */ + public static boolean compareAnnoWithDiffSeq(String anno1, String anno2) { + String[] annoArr = anno1.split(" "); + List list1 = new ArrayList(); + for (String ar : annoArr) { + if (!"".equals(ar)) { + list1.add(ar); + } + } + annoArr = anno2.split(" "); + List list2 = new ArrayList(); + for (String ar : annoArr) { + if (!"".equals(ar)) { + list2.add(ar); + } + } + Collections.sort(list1); + Collections.sort(list2); + return list1.equals(list2); + } + + /** + * For debug use + * @param string + */ + public static void debugPrint(String string) { + if (DEBUG) { + System.out.println(string); + } + } +} --- /dev/null Thu Aug 8 00:10:05 2013 +++ new/test/type-annotations/TestCaseGenerator.java Thu Aug 8 00:10:04 2013 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @bug 8013497 + * @summary Construct test case used for annotation test. + * @author Charlie Wang + */ +import java.util.LinkedHashMap; +import java.util.Map; + +public interface TestCaseGenerator { + // a place to hold temporary code declarations + public Map lhm = new LinkedHashMap<>(); + public final String typeAnnoClsName = "TypeAnnoCls"; + public final String typeAnnoIntName = "TypeAnnoInt"; + public final String testBaseClsName = "TypeAnnoClsBase"; + public final String testBaseFieldName = "f"; + public final String testBaseMethodName = "m"; + public final String argClsName = "TypeAnno1"; + + /** + * Generate test case code snippet. + * @param str + * @return Test case code snippet + */ + public String genTestCase(String str); +} --- /dev/null Thu Aug 8 00:10:07 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotatedInterfacesTest.java Thu Aug 8 00:10:06 2013 @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8013497 + * @summary test for API: Class.getAnnotatedInterfaces() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ClassGetAnnotatedInterfacesTest + */ +import java.lang.reflect.AnnotatedType; +import java.util.List; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single interface + * 2. Interface extends interface + * 3. Single class + * 4. Class extends class implements interface + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ClassGetAnnotatedInterfacesTest extends AnnotationTest{ + + enum TestCase implements TestCaseGenerator{ + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the + * code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + SINGLEINT() { + /** + * generate single interface: + * [#ANNO] interface TypeAnnoInt1 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.INTERFACE, typeAnnoIntName + clsIdx); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoIntName + clsIdx, null); + clsIdx++; + return testCode; + } + }, + INTEXTINT() { + /** + * generate interface extends interface: + * [#ANNO] interface TypeAnnoInt extends + * [#ANNO] Serializable {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.INTERFACE, typeAnnoIntName + clsIdx); + lhm.put(Helper.Declaration.EXTENDS, str + " Serializable"); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoIntName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + SINGLECLS() { + /** + * generate single class: + * [#ANNO] class TypeAnnoCls3 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, null); + clsIdx++; + return testCode; + } + }, + CLSIMPINTS() { + /** + * generate cls implements interface: + * [#ANNO] class TypeAnnoCls4 implements + * [#ANNO] Serializable, [#ANNO] Cloneable {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.IMPLEMENTS, new String[]{ + str + " Serializable", str + " Cloneable"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + protected String GenTestCode(Class tcg) { + String testCode = ""; + testCode += super.GenTestCode(tcg); + + // special cases + testInput.put(Object.class, null); + testInput.put(int.class, null); + testInput.put(void.class, null); + return testCode; + } + + // compare input with result + protected boolean checkResult() throws Exception { + boolean ret = true; + compileCode(TestCase.class); + for (Object clsName : testInput.keySet()) { + Class cls = loadClass(clsName); + AnnotatedType[] as = cls.getAnnotatedInterfaces(); + List result = Helper.getMultipleAT(as); + if (0 == result.size()) { + if (null != testInput.get(clsName)) { + // should be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed without empty output."); + } + } else { + for (int i = 0; i < result.size(); i++) { + if (!result.get(i).equals(testInput.get(clsName))) { + // annotations not match + ret = false; + Helper.debugPrint(clsName.toString() + + " failed with faulty annotations."); + } + } + } + } + return ret; + } + + public static void main(String[] args) throws Exception { + new ClassGetAnnotatedInterfacesTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:09 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotatedInterfacesTest.txt Thu Aug 8 00:10:08 2013 @@ -0,0 +1,165 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +interface TypeAnnoInt1 { + +} + + +interface TypeAnnoInt2 extends Serializable { + +} + + +class TypeAnnoCls3 { + +} + + +class TypeAnnoCls4 implements Serializable, Cloneable { + +} + + +interface TypeAnnoInt5 { + +} + + +interface TypeAnnoInt6 extends @TypeAnno1("TypeAnno1") Serializable { + +} + + +class TypeAnnoCls7 { + +} + + +class TypeAnnoCls8 implements @TypeAnno1("TypeAnno1") Serializable, @TypeAnno1("TypeAnno1") Cloneable { + +} + + +interface TypeAnnoInt9 { + +} + + +interface TypeAnnoInt10 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable { + +} + + +class TypeAnnoCls11 { + +} + + +class TypeAnnoCls12 implements @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable, @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Cloneable { + +} + + +interface TypeAnnoInt13 { + +} + + +interface TypeAnnoInt14 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable { + +} + + +class TypeAnnoCls15 { + +} + + +class TypeAnnoCls16 implements @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable, @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Cloneable { + +} + + +interface TypeAnnoInt17 { + +} + + +interface TypeAnnoInt18 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable { + +} + + +class TypeAnnoCls19 { + +} + + +class TypeAnnoCls20 implements @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable, @TypeAnno3 @TypeAnno3 @TypeAnno3 Cloneable { + +} + + +interface TypeAnnoInt21 { + +} + + +interface TypeAnnoInt22 extends @TypeAnno3 Serializable { + +} + + +class TypeAnnoCls23 { + +} + + +class TypeAnnoCls24 implements @TypeAnno3 Serializable, @TypeAnno3 Cloneable { + +} + + --- /dev/null Thu Aug 8 00:10:10 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotatedSuperclassTest.java Thu Aug 8 00:10:09 2013 @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Class.getAnnotatedSuperclass() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ClassGetAnnotatedSuperclassTest + */ +import java.lang.reflect.AnnotatedType; +import java.util.List; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single class + * 2. Class extends interface + * 3. Class extends class implements interface + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ClassGetAnnotatedSuperclassTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator{ + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + SINGLECLS() { + /** + * generate single class: + * [#ANNO] class TypeAnnoCls1 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, ""); + clsIdx++; + return testCode; + } + }, + CLSEXTCLS() { + /** + * generate cls extends cls: + * [#ANNO] class TypeAnnoCls2 extends [#ANNO] Object {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLSIMPINT() { + /** + * generate cls implements interface: + * [#ANNO] class TypeAnnoCls3 extends + * [#ANNO] Object implements [#ANNO] Serializable {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + lhm.put(Helper.Declaration.IMPLEMENTS, new String[]{ + str + " Serializable"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + protected String GenTestCode(Class tcg) { + String testCode = ""; + testCode += super.GenTestCode(tcg); + + // special cases + testInput.put(int.class, ""); + testInput.put(int[].class, ""); + testInput.put(void.class, ""); + testInput.put(Object.class, ""); + return testCode; + } + + // compare input with result + protected boolean checkResult() throws Exception { + boolean ret = true; + compileCode(TestCase.class); + for (Object clsName : testInput.keySet()) { + Class cls = loadClass(clsName); + AnnotatedType as = cls.getAnnotatedSuperclass(); + List result = Helper.getMultipleAT(new AnnotatedType[]{as}); + if (0 == result.size()) { + if (null != testInput.get(clsName)) { + // should be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed without empty output."); + } + } else { + for (int i = 0; i < result.size(); i++) { + if (!result.get(i).equals(testInput.get(clsName))) { + // annotations not match + ret = false; + Helper.debugPrint(clsName.toString() + + " failed with faulty annotations."); + } + } + } + } + return ret; + } + + public static void main(String[] args) throws Exception { + new ClassGetAnnotatedSuperclassTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:12 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotatedSuperclassTest.txt Thu Aug 8 00:10:11 2013 @@ -0,0 +1,134 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + +} + + +class TypeAnnoCls2 extends Object { + +} + + +class TypeAnnoCls3 extends Object implements Serializable { + +} + + +class TypeAnnoCls4 { + +} + + +class TypeAnnoCls5 extends @TypeAnno1("TypeAnno1") Object { + +} + + +class TypeAnnoCls6 extends @TypeAnno1("TypeAnno1") Object implements @TypeAnno1("TypeAnno1") Serializable { + +} + + +class TypeAnnoCls7 { + +} + + +class TypeAnnoCls8 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object { + +} + + +class TypeAnnoCls9 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object implements @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable { + +} + + +class TypeAnnoCls10 { + +} + + +class TypeAnnoCls11 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object { + +} + + +class TypeAnnoCls12 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object implements @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable { + +} + + +class TypeAnnoCls13 { + +} + + +class TypeAnnoCls14 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object { + +} + + +class TypeAnnoCls15 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object implements @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable { + +} + + +class TypeAnnoCls16 { + +} + + +class TypeAnnoCls17 extends @TypeAnno3 Object { + +} + + +class TypeAnnoCls18 extends @TypeAnno3 Object implements @TypeAnno3 Serializable { + +} + --- /dev/null Thu Aug 8 00:10:13 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotationsByTypeTest.java Thu Aug 8 00:10:13 2013 @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Class.getAnnotationsByType() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ClassGetAnnotationsByTypeTest + */ +import java.lang.annotation.Annotation; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single interface + * 2. Class extends class + * 3. Class implements interface + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ClassGetAnnotationsByTypeTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + SINGLECLS() { + /** + * generate single class: + * [#ANNO] class TypeAnnoCls1 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, + new String[]{str + " " + typeAnnoClsName + clsIdx}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLS() { + /** + * generate cls extends cls: + * [#ANNO] class TypeAnnoCls2 extends [#ANNO] Object {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, new String[]{ + str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLSIMPINT() { + /** + * generate cls implements interface: + * [#ANNO] class TypeAnnoCls3 extends + * [#ANNO] Object implements [#ANNO] Serializable {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, new String[]{ + str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + lhm.put(Helper.Declaration.IMPLEMENTS, new String[]{ + str + " Serializable"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + boolean ret = true; + compileCode(TestCase.class); + for (Object clsName : testInput.keySet()) { + Class cls = loadClass(clsName); + Class argCls = Helper.loadClass(TestCaseGenerator.argClsName); + Annotation[] as = cls.getAnnotationsByType(argCls); + String result = Helper.getAnno(as); + if (null == result || 0 == result.length()) { + if (-1 != testInput.get(clsName) + .indexOf(TestCaseGenerator.argClsName)) { + // should be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed without empty output."); + } + } else { + if (-1 == testInput.get(clsName) + .indexOf(TestCaseGenerator.argClsName)) { + // should not be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed with faulty annotations."); + } + } + } + return ret; + } + + public static void main(String[] args) throws Exception { + new ClassGetAnnotationsByTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:15 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotationsByTypeTest.txt Thu Aug 8 00:10:14 2013 @@ -0,0 +1,134 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + +} + + +class TypeAnnoCls2 extends Object { + +} + + +class TypeAnnoCls3 extends Object implements Serializable { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls4 { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls5 extends @TypeAnno1("TypeAnno1") Object { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls6 extends @TypeAnno1("TypeAnno1") Object implements @TypeAnno1("TypeAnno1") Serializable { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls7 { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls8 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls9 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object implements @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls10 { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls11 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls12 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object implements @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls13 { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls14 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls15 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object implements @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable { + +} + +@TypeAnno3 +class TypeAnnoCls16 { + +} + +@TypeAnno3 +class TypeAnnoCls17 extends @TypeAnno3 Object { + +} + +@TypeAnno3 +class TypeAnnoCls18 extends @TypeAnno3 Object implements @TypeAnno3 Serializable { + +} + --- /dev/null Thu Aug 8 00:10:17 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotationsTest.java Thu Aug 8 00:10:16 2013 @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Class.getAnnotations() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ClassGetAnnotationsTest + */ +import java.lang.annotation.Annotation; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single interface + * 2. Class extends class + * 3. Class implements interface + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ClassGetAnnotationsTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + SINGLECLS() { + /** + * generate single class: + * [#ANNO] class TypeAnnoCls1 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, + new String[]{str + " " + typeAnnoClsName + clsIdx}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLS() { + /** + * generate cls extends cls: + * [#ANNO] class TypeAnnoCls2 extends [#ANNO] Object {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, + new String[]{str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLSIMPINT() { + /** + * generate cls implements interface: + * [#ANNO] class TypeAnnoCls3 extends + * [#ANNO] Object implements [#ANNO] Serializable {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, new String[]{ + str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + lhm.put(Helper.Declaration.IMPLEMENTS, new String[]{ + str + " Serializable"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + boolean ret = true; + compileCode(TestCase.class); + for (Object clsName : testInput.keySet()) { + Class cls = loadClass(clsName); + Annotation[] as = cls.getAnnotations(); + String result = Helper.getAnno(as); + if (null == result || 0 == result.length()) { + if (!"".equals(testInput.get(clsName))) { + // should be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed without empty output."); + } + } else { + if (!Helper.compareAnnoWithDiffSeq(result, + testInput.get(clsName))) { + // should not be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed with faulty annotations."); + } + } + } + return ret; + } + + public static void main(String[] args) throws Exception { + new ClassGetAnnotationsTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:18 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetAnnotationsTest.txt Thu Aug 8 00:10:17 2013 @@ -0,0 +1,134 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + +} + + +class TypeAnnoCls2 extends Object { + +} + + +class TypeAnnoCls3 extends Object implements Serializable { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls4 { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls5 extends @TypeAnno1("TypeAnno1") Object { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls6 extends @TypeAnno1("TypeAnno1") Object implements @TypeAnno1("TypeAnno1") Serializable { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls7 { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls8 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls9 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object implements @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls10 { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls11 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls12 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object implements @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls13 { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls14 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls15 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object implements @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable { + +} + +@TypeAnno3 +class TypeAnnoCls16 { + +} + +@TypeAnno3 +class TypeAnnoCls17 extends @TypeAnno3 Object { + +} + +@TypeAnno3 +class TypeAnnoCls18 extends @TypeAnno3 Object implements @TypeAnno3 Serializable { + +} + --- /dev/null Thu Aug 8 00:10:20 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetDeclaredAnnotationsByTypeTest.java Thu Aug 8 00:10:19 2013 @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Class.getDeclaredAnnotationsByType() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ClassGetDeclaredAnnotationsByTypeTest + */ +import java.lang.annotation.Annotation; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single interface + * 2. Class extends class + * 3. Class implements interface + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ClassGetDeclaredAnnotationsByTypeTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + SINGLECLS() { + /** + * generate single class: + * [#ANNO] class TypeAnnoCls1 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, + new String[]{str + " " + typeAnnoClsName + clsIdx}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLS() { + /** + * generate cls extends cls: + * [#ANNO] class TypeAnnoCls2 extends [#ANNO] Object {} + * then append annotations on [#ANNO] + * + * input should be like [class name, @anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, new String[]{ + str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLSIMPINT() { + /** + * generate cls implements interface: + * [#ANNO] class TypeAnnoCls3 extends + * [#ANNO] Object implements [#ANNO] Serializable {} + * then append annotations on [#ANNO] + * + * input should be like [class name, @anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, new String[]{ + str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + lhm.put(Helper.Declaration.IMPLEMENTS, new String[]{ + str + " Serializable"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + boolean ret = true; + compileCode(TestCase.class); + for (Object clsName : testInput.keySet()) { + Class cls = loadClass(clsName); + Class argCls = Helper.loadClass(TestCaseGenerator.argClsName); + Annotation[] as = cls.getAnnotationsByType(argCls); + String result = Helper.getAnno(as); + if (null == result || 0 == result.length()) { + if (-1 != testInput.get(clsName).indexOf( + TestCaseGenerator.argClsName)) { + // should be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed without empty output."); + } + } else { + if (-1 == testInput.get(clsName).indexOf( + TestCaseGenerator.argClsName)) { + // should not be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed with faulty annotations."); + } + } + } + return ret; + } + + public static void main(String[] args) throws Exception { + new ClassGetDeclaredAnnotationsByTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:21 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetDeclaredAnnotationsByTypeTest.txt Thu Aug 8 00:10:21 2013 @@ -0,0 +1,135 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + +} + + +class TypeAnnoCls2 extends Object { + +} + + +class TypeAnnoCls3 extends Object implements Serializable { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls4 { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls5 extends @TypeAnno1("TypeAnno1") Object { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls6 extends @TypeAnno1("TypeAnno1") Object implements @TypeAnno1("TypeAnno1") Serializable { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls7 { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls8 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls9 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object implements @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls10 { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls11 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls12 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object implements @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls13 { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls14 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls15 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object implements @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable { + +} + +@TypeAnno3 +class TypeAnnoCls16 { + +} + +@TypeAnno3 +class TypeAnnoCls17 extends @TypeAnno3 Object { + +} + +@TypeAnno3 +class TypeAnnoCls18 extends @TypeAnno3 Object implements @TypeAnno3 Serializable { + +} + + --- /dev/null Thu Aug 8 00:10:23 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetDeclaredAnnotationsTest.java Thu Aug 8 00:10:22 2013 @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Class.getDeclaredAnnotations() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ClassGetDeclaredAnnotationsTest + */ +import java.lang.annotation.Annotation; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single interface + * 2. Class extends class + * 3. Class implements interface + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ClassGetDeclaredAnnotationsTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + SINGLECLS() { + /** + * generate single class: + * [#ANNO] class TypeAnnoCls1 { } + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, + new String[]{str + " " + typeAnnoClsName + clsIdx}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLS() { + /** + * generate cls extends cls: + * [#ANNO] class TypeAnnoCls2 extends [#ANNO] Object {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, + new String[]{str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }, + CLSEXTCLSIMPINT() { + /** + * generate cls implements interface: + * [#ANNO] class TypeAnnoCls3 extends + * [#ANNO] Object implements [#ANNO] Serializable {} + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.CLASS, new String[]{ + str + " " + typeAnnoClsName + clsIdx}); + lhm.put(Helper.Declaration.EXTENDS, new String[]{ + str + " Object"}); + lhm.put(Helper.Declaration.IMPLEMENTS, new String[]{ + str + " Serializable"}); + testCode += Helper.genDeclaration(lhm); + lhm.clear(); + testInput.put(typeAnnoClsName + clsIdx, str); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + boolean ret = true; + compileCode(TestCase.class); + for (Object clsName : testInput.keySet()) { + Class cls = loadClass(clsName); + Annotation[] as = cls.getAnnotations(); + String result = Helper.getAnno(as); + if (null == result || 0 == result.length()) { + if (!"".equals(testInput.get(clsName))) { + // should be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed without empty output."); + } + } else { + if (!Helper.compareAnnoWithDiffSeq(result, + testInput.get(clsName))) { + // should not be empty output + ret = false; + Helper.debugPrint(clsName.toString() + + " failed with faulty annotations."); + } + } + } + return ret; + } + + public static void main(String[] args) throws Exception { + new ClassGetDeclaredAnnotationsTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:25 2013 +++ new/test/type-annotations/java/lang/Class/ClassGetDeclaredAnnotationsTest.txt Thu Aug 8 00:10:24 2013 @@ -0,0 +1,135 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + +} + + +class TypeAnnoCls2 extends Object { + +} + + +class TypeAnnoCls3 extends Object implements Serializable { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls4 { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls5 extends @TypeAnno1("TypeAnno1") Object { + +} + +@TypeAnno1("TypeAnno1") +class TypeAnnoCls6 extends @TypeAnno1("TypeAnno1") Object implements @TypeAnno1("TypeAnno1") Serializable { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls7 { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls8 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object { + +} + +@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 +class TypeAnnoCls9 extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object implements @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls10 { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls11 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object { + +} + +@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") +class TypeAnnoCls12 extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object implements @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls13 { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls14 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object { + +} + +@TypeAnno3 @TypeAnno3 @TypeAnno3 +class TypeAnnoCls15 extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object implements @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable { + +} + +@TypeAnno3 +class TypeAnnoCls16 { + +} + +@TypeAnno3 +class TypeAnnoCls17 extends @TypeAnno3 Object { + +} + +@TypeAnno3 +class TypeAnnoCls18 extends @TypeAnno3 Object implements @TypeAnno3 Serializable { + +} + + --- /dev/null Thu Aug 8 00:10:26 2013 +++ new/test/type-annotations/java/lang/Package/PackageGetDeclaredAnnotationTest.java Thu Aug 8 00:10:26 2013 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8013497 + * @summary test for API: Package.getDeclaredAnnotation() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper pkg.PkgAnno1 pkg.PkgAnno2 pkg.PkgAnno3 pkg.package-info + * @author Charlie Wang + * @run main PackageGetDeclaredAnnotationTest + */ +import java.lang.annotation.Annotation; +import pkg.PkgAnno1; +import pkg.PkgAnno2; +import pkg.PkgAnno3; + +public class PackageGetDeclaredAnnotationTest extends AnnotationTest { + + public boolean checkResult() throws Exception { + Package pkg = PkgAnno1.class.getPackage(); + Annotation anno = pkg.getDeclaredAnnotation(PkgAnno2.class); + if (!"@PkgAnno2(\"PkgAnno2\") ".equals(Helper.getAnno(anno))) { + return false; + } + anno = pkg.getDeclaredAnnotation(PkgAnno3.class); + if (!"".equals(Helper.getAnno(anno))) { + return false; + } + return true; + } + + public static void main(String[] args) throws Exception { + new PackageGetDeclaredAnnotationTest().test(); + } + + @Override + protected String GenTestCode(Class tcg) { + throw new UnsupportedOperationException("Not supported yet."); + } +} --- /dev/null Thu Aug 8 00:10:28 2013 +++ new/test/type-annotations/java/lang/Package/PackageGetDeclaredAnnotationsByTypeTest.java Thu Aug 8 00:10:27 2013 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8013497 + * @summary test for API: Package.getDeclaredAnnotationsByType() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper pkg.PkgAnno1 pkg.PkgAnno2 pkg.PkgAnno3 pkg.package-info + * @author Charlie Wang + * @run main PackageGetDeclaredAnnotationsByTypeTest + */ +import java.lang.annotation.Annotation; +import pkg.PkgAnno1; +import pkg.PkgAnno2; +import pkg.PkgAnno3; + +public class PackageGetDeclaredAnnotationsByTypeTest extends AnnotationTest { + + public boolean checkResult() throws Exception { + Package pkg = PkgAnno1.class.getPackage(); + Annotation[] as = pkg.getDeclaredAnnotationsByType(PkgAnno2.class); + for (Annotation anno : as) { + if (!"@PkgAnno2(\"PkgAnno2\") ".equals(Helper.getAnno(anno))) { + return false; + } + } + as = pkg.getDeclaredAnnotationsByType(PkgAnno3.class); + for (Annotation anno : as) { + if (!"".equals(Helper.getAnno(anno))) { + return false; + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new PackageGetDeclaredAnnotationsByTypeTest().test(); + } + + @Override + protected String GenTestCode(Class tcg) { + throw new UnsupportedOperationException("Not supported yet."); + } +} --- /dev/null Thu Aug 8 00:10:30 2013 +++ new/test/type-annotations/java/lang/Package/PackageGetDeclaredAnnotationsTest.java Thu Aug 8 00:10:29 2013 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8013497 + * @summary test for API: Package.getDeclaredAnnotations() + * @library ../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper pkg.PkgAnno1 pkg.PkgAnno2 pkg.PkgAnno3 pkg.package-info + * @author Charlie Wang + * @run main PackageGetDeclaredAnnotationsTest + */ +import java.lang.annotation.Annotation; +import pkg.PkgAnno1; + +public class PackageGetDeclaredAnnotationsTest extends AnnotationTest { + + public boolean checkResult() throws Exception { + Package pkg = PkgAnno1.class.getPackage(); + Annotation[] as = pkg.getDeclaredAnnotations(); + System.out.println("result: " + Helper.getAnno(as)); + if (!"@PkgAnno1(\"PkgAnno1\") @PkgAnno2(\"PkgAnno2\") " + .equals(Helper.getAnno(as))) { + return false; + } + return true; + } + + public static void main(String[] args) throws Exception { + new PackageGetDeclaredAnnotationsTest().test(); + } + + @Override + protected String GenTestCode(Class tcg) { + throw new UnsupportedOperationException("Not supported yet."); + } +} --- /dev/null Thu Aug 8 00:10:31 2013 +++ new/test/type-annotations/java/lang/Package/pkg/PkgAnno1.java Thu Aug 8 00:10:30 2013 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @bug 8013497 + * @author Charlie Wang + */ +package pkg; +import java.lang.annotation.*; + +@Target(ElementType.PACKAGE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PkgAnno1 { + String value(); +} --- /dev/null Thu Aug 8 00:10:33 2013 +++ new/test/type-annotations/java/lang/Package/pkg/PkgAnno2.java Thu Aug 8 00:10:32 2013 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @bug 8013497 + * @author Charlie Wang + */ +package pkg; +import java.lang.annotation.*; + +@Target(ElementType.PACKAGE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PkgAnno2 { + String value(); +} --- /dev/null Thu Aug 8 00:10:34 2013 +++ new/test/type-annotations/java/lang/Package/pkg/PkgAnno3.java Thu Aug 8 00:10:34 2013 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @bug 8013497 + * @author Charlie Wang + */ +package pkg; +import java.lang.annotation.*; + +@Target(ElementType.PACKAGE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PkgAnno3 { + String value(); +} --- /dev/null Thu Aug 8 00:10:36 2013 +++ new/test/type-annotations/java/lang/Package/pkg/package-info.java Thu Aug 8 00:10:35 2013 @@ -0,0 +1,2 @@ +@PkgAnno1("PkgAnno1") @PkgAnno2("PkgAnno2") +package pkg; --- /dev/null Thu Aug 8 00:10:37 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedArrayType/AnnotatedArrayTypeGetAnnotatedGenericComponentTypeTest.java Thu Aug 8 00:10:37 2013 @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: AnnotatedArrayType.getAnnotatedGenericComponentType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main AnnotatedArrayTypeGetAnnotatedGenericComponentTypeTest + */ +import java.lang.reflect.AnnotatedType; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. 1-dimension array with annotations on type and array"[]" + * 2. 2-dimension array with annotations on type and array"[]" + * 3. 3-dimension array with annotations on type and array"[]" + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class AnnotatedArrayTypeGetAnnotatedGenericComponentTypeTest + extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLSSTART() { + /** + * generate test base, which is the class name used to compile the + * code: import java.io.*; import java.util.*; import java.lang.*; + * import java.lang.reflect.*; import java.lang.annotation.*; class + * testBaseClsName { } + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.IMPORT, null); + lhm.put(Helper.Declaration.CLASS, testBaseClsName); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.CLASS); + lhm.clear(); + return testCode; + } + }, + ARRAYFIELD() { + /** + * generate single dimension array: + * public String [#ANNO] [] f1; + * then append annotations on [#ANNO] + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + + String testCode = ""; + lhm.put(Helper.Declaration.FIELD_TYPE, str + " String"); + lhm.put(Helper.Declaration.FIELD_ARRAY, str); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "1"); + testInput.put(testBaseFieldName + clsIdx + "1", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " String"); + lhm.put(Helper.Declaration.FIELD_ARRAY, + new String[]{str, str}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "2"); + testInput.put(testBaseFieldName + clsIdx + "2", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " String"); + lhm.put(Helper.Declaration.FIELD_ARRAY, + new String[]{str, str, str}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "3"); + testInput.put(testBaseFieldName + clsIdx + "3", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " String"); + lhm.put(Helper.Declaration.FIELD_ARRAY, + new String[]{str, str, str, str}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "4"); + testInput.put(testBaseFieldName + clsIdx + "4", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + TESTBASECLSEND() { + /** + * generate end of the test base class: } + * + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_3, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_3, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + + return testCode; + } + }; + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + protected String GenTestCode(Class tcg) { + String testCode = ""; + testCode += TestCase.TESTBASECLSSTART.genTestCase(null); + for (String anno : annotationCombinations) { + // append annotation on field + testCode += TestCase.ARRAYFIELD.genTestCase(anno); + } + testCode += TestCase.TESTBASECLSEND.genTestCase(null); + + return testCode; + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + Class cls = Helper.loadClass(TestCaseGenerator.testBaseClsName); + for (Object fieldName : testInput.keySet()) { + AnnotatedType at = + cls.getDeclaredField((String) fieldName). + getAnnotatedType(); + String[] result = Helper.getArrAT(at).split(";"); + for (String anno : result) { + if (!"".equals(anno) + && !anno.equals(testInput.get(fieldName))) { + Helper.debugPrint(fieldName + + " failed with faulty annotations."); + return false; + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new AnnotatedArrayTypeGetAnnotatedGenericComponentTypeTest() + .test(); + } +} --- /dev/null Thu Aug 8 00:10:39 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedArrayType/AnnotatedArrayTypeGetAnnotatedGenericComponentTypeTest.txt Thu Aug 8 00:10:38 2013 @@ -0,0 +1,69 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + public String [] f11; + public String [] [] f12; + public String [] [] [] f13; + public String [] [] [] [] f14; + public @TypeAnno1("TypeAnno1") String @TypeAnno1("TypeAnno1") [] f21; + public @TypeAnno1("TypeAnno1") String @TypeAnno1("TypeAnno1") [] @TypeAnno1("TypeAnno1") [] f22; + public @TypeAnno1("TypeAnno1") String @TypeAnno1("TypeAnno1") [] @TypeAnno1("TypeAnno1") [] @TypeAnno1("TypeAnno1") [] f23; + public @TypeAnno1("TypeAnno1") String @TypeAnno1("TypeAnno1") [] @TypeAnno1("TypeAnno1") [] @TypeAnno1("TypeAnno1") [] @TypeAnno1("TypeAnno1") [] f24; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] f31; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] f32; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] f33; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 [] f34; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] f41; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] f42; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] f43; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") [] f44; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 String @TypeAnno3 @TypeAnno3 @TypeAnno3 [] f51; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 String @TypeAnno3 @TypeAnno3 @TypeAnno3 [] @TypeAnno3 @TypeAnno3 @TypeAnno3 [] f52; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 String @TypeAnno3 @TypeAnno3 @TypeAnno3 [] @TypeAnno3 @TypeAnno3 @TypeAnno3 [] @TypeAnno3 @TypeAnno3 @TypeAnno3 [] f53; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 String @TypeAnno3 @TypeAnno3 @TypeAnno3 [] @TypeAnno3 @TypeAnno3 @TypeAnno3 [] @TypeAnno3 @TypeAnno3 @TypeAnno3 [] @TypeAnno3 @TypeAnno3 @TypeAnno3 [] f54; + public @TypeAnno3 String @TypeAnno3 [] f61; + public @TypeAnno3 String @TypeAnno3 [] @TypeAnno3 [] f62; + public @TypeAnno3 String @TypeAnno3 [] @TypeAnno3 [] @TypeAnno3 [] f63; + public @TypeAnno3 String @TypeAnno3 [] @TypeAnno3 [] @TypeAnno3 [] @TypeAnno3 [] f64; + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + --- /dev/null Thu Aug 8 00:10:41 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedParameterizedType/AnnotatedParameterizedTypeGetAnnotatedActualTypeArgumentsTest.java Thu Aug 8 00:10:40 2013 @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: AnnotatedParameterizedType.getAnnotatedActualTypeArguments() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main AnnotatedParameterizedTypeGetAnnotatedActualTypeArgumentsTest + */ +import java.lang.reflect.AnnotatedParameterizedType; +import java.lang.reflect.AnnotatedType; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. generics - + * 2. generics - + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class AnnotatedParameterizedTypeGetAnnotatedActualTypeArgumentsTest + extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLSSTART() { + /** + * generate test base, which is the class name used to compile the + * code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.IMPORT, null); + lhm.put(Helper.Declaration.CLASS, testBaseClsName); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.CLASS); + lhm.clear(); + return testCode; + } + }, + GENERICTYPE() { + /** + * generate generic type: + * public Class<[#ANNO] type> f1; + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.FIELD_TYPE, str + " Class"); + lhm.put(Helper.Declaration.GENERICS1, str + " String"); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "1"); + testInput.put(testBaseFieldName + clsIdx + "1", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " HashMap"); + lhm.put(Helper.Declaration.GENERICS1, + new String[]{str + " String", str + " String"}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "2"); + testInput.put(testBaseFieldName + clsIdx+ "2", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + TESTBASECLSEND() { + /** + * generate end of the test base class: } + * + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_3, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_3, ""); + testCode += Helper.genDeclaration( + lhm, Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + public String GenTestCode(Class tcg) { + String testCode = ""; + testCode += TestCase.TESTBASECLSSTART.genTestCase(null); + for (String anno : annotationCombinations) { + // append annotation on field + testCode += TestCase.GENERICTYPE.genTestCase(anno); + } + testCode += TestCase.TESTBASECLSEND.genTestCase(null); + + return testCode; + } + + // compare input with result + public boolean checkResult() throws Exception { + compileCode(TestCase.class); + + // Get Class object for the compiled class + Class cls = Helper.loadClass(TestCaseGenerator.testBaseClsName); + + for (Object fieldName : testInput.keySet()) { + AnnotatedType[] result = + ((AnnotatedParameterizedType) + cls.getDeclaredField((String) fieldName). + getAnnotatedType()).getAnnotatedActualTypeArguments(); + for (AnnotatedType at : result) { + if (!Helper.getAT(at).equals(testInput.get(fieldName))) { + Helper.debugPrint(fieldName + + " failed with faulty annotations."); + return false; + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new AnnotatedParameterizedTypeGetAnnotatedActualTypeArgumentsTest() + .test(); + } +} --- /dev/null Thu Aug 8 00:10:42 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedParameterizedType/AnnotatedParameterizedTypeGetAnnotatedActualTypeArgumentsTest.txt Thu Aug 8 00:10:42 2013 @@ -0,0 +1,57 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + public Class< String > f11; + public HashMap< String , String > f12; + public @TypeAnno1("TypeAnno1") Class<@TypeAnno1("TypeAnno1") String > f21; + public @TypeAnno1("TypeAnno1") HashMap<@TypeAnno1("TypeAnno1") String , @TypeAnno1("TypeAnno1") String > f22; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Class<@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String > f31; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 HashMap<@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String , @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String > f32; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Class<@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String > f41; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") HashMap<@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String , @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String > f42; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 Class<@TypeAnno3 @TypeAnno3 @TypeAnno3 String > f51; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 HashMap<@TypeAnno3 @TypeAnno3 @TypeAnno3 String , @TypeAnno3 @TypeAnno3 @TypeAnno3 String > f52; + public @TypeAnno3 Class<@TypeAnno3 String > f61; + public @TypeAnno3 HashMap<@TypeAnno3 String , @TypeAnno3 String > f62; + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + --- /dev/null Thu Aug 8 00:10:44 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedType/AnnotatedTypeGetTypeTest.java Thu Aug 8 00:10:43 2013 @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: AnnotatedType.getType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main AnnotatedTypeGetTypeTest + */ +import java.io.Serializable; +import java.lang.annotation.*; +import java.lang.reflect.*; +import java.util.*; + + +/* + * Check if getType returns the type after putting an annotation on it. + */ +public class AnnotatedTypeGetTypeTest extends AnnotationTest { + + public boolean checkResult() throws Exception { + if (!AnnoTypeCls01.class.getAnnotatedInterfaces()[0]. + getType().equals(Serializable.class)) { + return false; + } + if (!AnnoTypeCls02.class.getAnnotatedSuperclass(). + getType().equals(Exception.class)) { + return false; + } + if (!AnnoTypeCls01.class.getDeclaredField("f1").getAnnotatedType(). + getType().equals(String[].class)) { + return false; + } + if (!((AnnotatedWildcardType) ((AnnotatedParameterizedType) + AnnoTypeCls01.class.getDeclaredField("f2").getAnnotatedType()). + getAnnotatedActualTypeArguments()[0]). + getAnnotatedLowerBounds()[0].getType().equals(Object.class)) { + return false; + } + if (!((AnnotatedWildcardType) ((AnnotatedParameterizedType) + AnnoTypeCls01.class.getDeclaredField("f3").getAnnotatedType()) + .getAnnotatedActualTypeArguments()[0]) + .getAnnotatedUpperBounds()[0].getType().equals(Object.class)) { + return false; + } + if (!AnnoTypeCls01.class.getDeclaredMethod("m1", (Class[]) null) + .getAnnotatedExceptionTypes()[0].getType(). + equals(RuntimeException.class)) { + return false; + } + if (!AnnoTypeCls01.class.getDeclaredMethod("m2" + , new Class[] {String.class}).getAnnotatedParameterTypes()[0]. + getType().equals(String.class)) + return false; + if (!AnnoTypeCls01.class.getDeclaredMethod("m3", (Class[]) null) + .getAnnotatedReturnType().getType().equals(Integer.class)) { + return false; + } + if (!AnnoTypeCls01.class.getDeclaredMethod("m4") + .getAnnotatedReceiverType().getType(). + equals(AnnoTypeCls01.class)) { + return false; + } + if (!AnnoTypeCls03.class.getTypeParameters()[0] + .getAnnotatedBounds()[0].getType().equals(Object.class)) { + return false; + } + + return true; + } + + public static void main(String[] args) throws Exception { + new AnnotatedTypeGetTypeTest().test(); + } + + @Override + protected String GenTestCode(Class tcg) { + throw new UnsupportedOperationException("Not supported yet."); + } +} +class AnnoTypeCls01 implements @TypeAnno1("TypeAnno1") Serializable{ + public String @TypeAnno1("TypeAnno1") [] f1 ; + private List f2 ; + private List f3 ; + + public String m1() throws @TypeAnno1("TypeAnno1") RuntimeException { + return null; + } + + public String m2(@TypeAnno1("TypeAnno1") String s) { + return null; + } + + public @TypeAnno1("TypeAnno1") Integer m3() { + return null; + } + + public @TypeAnno1("TypeAnno11")Integer m4( + @TypeAnno1("TypeAnno12") AnnoTypeCls01 this){ + return null; + } +} + +class AnnoTypeCls02 extends @TypeAnno1("TypeAnno1") Exception {} + +class AnnoTypeCls03 {} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} --- /dev/null Thu Aug 8 00:10:45 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedTypeVariable/AnnotatedTypeVariableGetAnnotatedBoundsTest.java Thu Aug 8 00:10:45 2013 @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: AnnotatedTypeVariable.getAnnotatedBounds() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main AnnotatedTypeVariableGetAnnotatedBoundsTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.AnnotatedTypeVariable; +import java.lang.reflect.Method; + + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. generics - + * 2. generics - + * 3. generics - + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class AnnotatedTypeVariableGetAnnotatedBoundsTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the + * code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + NOBOUND() { + /** + * generate test class: + * class TypeAnnoCls { + * T method1(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.GENERICS1, "T"); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "T m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, ""); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + SINGLEBOUND() { + /** + * generate test class: + * class TypeAnnoCls { + * T method1(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.GENERICS1, + "T extends " + str + " Object"); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "T m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + MULTIPLEBOUNDS() { + /** + * generate test class: + * class TypeAnnoCls { + * T method1(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.GENERICS2, + "T " + str + " Object " + str + " Serializable"); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "T m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (Object clsName : testInput.keySet()) { + Class cls = Helper.loadClass((String) clsName); + Method m = cls.getDeclaredMethod("m", (Class[]) null); + AnnotatedType ret = m.getAnnotatedReturnType(); + AnnotatedType[] abs = + ((AnnotatedTypeVariable) ret).getAnnotatedBounds(); + + for (AnnotatedType at : abs) { + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + + " failed with faulty annotations."); + return false; + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new AnnotatedTypeVariableGetAnnotatedBoundsTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:47 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedTypeVariable/AnnotatedTypeVariableGetAnnotatedBoundsTest.txt Thu Aug 8 00:10:46 2013 @@ -0,0 +1,171 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1< T > { + + public T m() {return null;} + +} + + +class TypeAnnoCls2< T extends Object> { + + public T m() {return null;} + +} + + +class TypeAnnoCls3< T extends Object & Serializable> { + + public T m() {return null;} + +} + + +class TypeAnnoCls4< T > { + + public T m() {return null;} + +} + + +class TypeAnnoCls5< T extends @TypeAnno1("TypeAnno1") Object> { + + public T m() {return null;} + +} + + +class TypeAnnoCls6< T extends @TypeAnno1("TypeAnno1") Object & @TypeAnno1("TypeAnno1") Serializable> { + + public T m() {return null;} + +} + + +class TypeAnnoCls7< T > { + + public T m() {return null;} + +} + + +class TypeAnnoCls8< T extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> { + + public T m() {return null;} + +} + + +class TypeAnnoCls9< T extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object & @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable> { + + public T m() {return null;} + +} + + +class TypeAnnoCls10< T > { + + public T m() {return null;} + +} + + +class TypeAnnoCls11< T extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> { + + public T m() {return null;} + +} + + +class TypeAnnoCls12< T extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object & @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable> { + + public T m() {return null;} + +} + + +class TypeAnnoCls13< T > { + + public T m() {return null;} + +} + + +class TypeAnnoCls14< T extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> { + + public T m() {return null;} + +} + + +class TypeAnnoCls15< T extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object & @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable> { + + public T m() {return null;} + +} + + +class TypeAnnoCls16< T > { + + public T m() {return null;} + +} + + +class TypeAnnoCls17< T extends @TypeAnno3 Object> { + + public T m() {return null;} + +} + + +class TypeAnnoCls18< T extends @TypeAnno3 Object & @TypeAnno3 Serializable> { + + public T m() {return null;} + +} + + --- /dev/null Thu Aug 8 00:10:49 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedWildcardType/AnnotatedWildcardTypeGetAnnotatedLowerBoundsTest.java Thu Aug 8 00:10:49 2013 @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: AnnotatedWildcardType.getAnnotatedLowerBounds() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main AnnotatedWildcardTypeGetAnnotatedLowerBoundsTest + */ +import java.lang.reflect.AnnotatedParameterizedType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.AnnotatedWildcardType; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. generics - + * 2. generics - + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class AnnotatedWildcardTypeGetAnnotatedLowerBoundsTest + extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLSSTART() { + /** + * generate test base, which is the class name used to compile the + * code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.IMPORT, null); + lhm.put(Helper.Declaration.CLASS, testBaseClsName); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.CLASS); + lhm.clear(); + return testCode; + } + }, + GENERICTYPE() { + /** + * generate generic type: + * public Class<[#ANNO] type> f1; + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.FIELD_TYPE, str + " Class"); + lhm.put(Helper.Declaration.GENERICS1, + "? super " + str + " Object"); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "1"); + testInput.put(testBaseFieldName + clsIdx + "1", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " HashMap"); + lhm.put(Helper.Declaration.GENERICS1, + new String[]{"? super " + str + " Object", + "? super " + str + " Object"}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "2"); + testInput.put(testBaseFieldName + clsIdx + "2", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " Class"); + lhm.put(Helper.Declaration.GENERICS1, + "? extends " + str + " Object"); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "3"); + testInput.put(testBaseFieldName + clsIdx + "3", ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " HashMap"); + lhm.put(Helper.Declaration.GENERICS1, + new String[]{"? extends " + str + " Object", + "? extends " + str + " Object"}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "4"); + testInput.put(testBaseFieldName + clsIdx + "4", ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + TESTBASECLSEND() { + /** + * generate end of the test base class: } + * + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_3, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_3, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + protected String GenTestCode(Class tcg) { + String testCode = ""; + testCode += TestCase.TESTBASECLSSTART.genTestCase(null); + for (String anno : annotationCombinations) { + // append annotation on field + testCode += TestCase.GENERICTYPE.genTestCase(anno); + } + testCode += TestCase.TESTBASECLSEND.genTestCase(null); + + return testCode; + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + Class cls = Helper.loadClass(TestCaseGenerator.testBaseClsName); + for (Object fieldName : testInput.keySet()) { + AnnotatedType[] result = ((AnnotatedParameterizedType) + cls.getDeclaredField((String) fieldName). + getAnnotatedType()).getAnnotatedActualTypeArguments(); + for (AnnotatedType at : result) { + for (AnnotatedType as : + ((AnnotatedWildcardType) at).getAnnotatedLowerBounds()) { + + if (!Helper.getAT(as).equals(testInput.get(fieldName))) { + Helper.debugPrint( + fieldName + " failed with faulty annotations."); + return false; + } + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new AnnotatedWildcardTypeGetAnnotatedLowerBoundsTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:51 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedWildcardType/AnnotatedWildcardTypeGetAnnotatedLowerBoundsTest.txt Thu Aug 8 00:10:50 2013 @@ -0,0 +1,69 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + public Class< ? super Object> f11; + public HashMap< ? super Object, ? super Object> f12; + public Class< ? extends Object> f13; + public HashMap< ? extends Object, ? extends Object> f14; + public @TypeAnno1("TypeAnno1") Class< ? super @TypeAnno1("TypeAnno1") Object> f21; + public @TypeAnno1("TypeAnno1") HashMap< ? super @TypeAnno1("TypeAnno1") Object, ? super @TypeAnno1("TypeAnno1") Object> f22; + public @TypeAnno1("TypeAnno1") Class< ? extends @TypeAnno1("TypeAnno1") Object> f23; + public @TypeAnno1("TypeAnno1") HashMap< ? extends @TypeAnno1("TypeAnno1") Object, ? extends @TypeAnno1("TypeAnno1") Object> f24; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Class< ? super @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f31; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 HashMap< ? super @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object, ? super @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f32; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Class< ? extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f33; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 HashMap< ? extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object, ? extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f34; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Class< ? super @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f41; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") HashMap< ? super @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object, ? super @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f42; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Class< ? extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f43; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") HashMap< ? extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object, ? extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f44; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 Class< ? super @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f51; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 HashMap< ? super @TypeAnno3 @TypeAnno3 @TypeAnno3 Object, ? super @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f52; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 Class< ? extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f53; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 HashMap< ? extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object, ? extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f54; + public @TypeAnno3 Class< ? super @TypeAnno3 Object> f61; + public @TypeAnno3 HashMap< ? super @TypeAnno3 Object, ? super @TypeAnno3 Object> f62; + public @TypeAnno3 Class< ? extends @TypeAnno3 Object> f63; + public @TypeAnno3 HashMap< ? extends @TypeAnno3 Object, ? extends @TypeAnno3 Object> f64; + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + --- /dev/null Thu Aug 8 00:10:53 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedWildcardType/AnnotatedWildcardTypeGetAnnotatedUpperBoundsTest.java Thu Aug 8 00:10:52 2013 @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: AnnotatedWildcardType.getAnnotatedUpperBounds() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main AnnotatedWildcardTypeGetAnnotatedUpperBoundsTest + */ +import java.lang.reflect.AnnotatedParameterizedType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.AnnotatedWildcardType; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. generics - + * 2. generics - + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class AnnotatedWildcardTypeGetAnnotatedUpperBoundsTest + extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLSSTART() { + /** + * generate test base, which is the class name used to compile the + * code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.IMPORT, null); + lhm.put(Helper.Declaration.CLASS, testBaseClsName); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.CLASS); + lhm.clear(); + return testCode; + } + }, + GENERICTYPE() { + /** + * generate generic type: + * public Class<[#ANNO] type> f1; + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.FIELD_TYPE, str + " Class"); + lhm.put(Helper.Declaration.GENERICS1, + "? extends " + str + " Object"); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "1"); + testInput.put(testBaseFieldName + clsIdx + "1", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " HashMap"); + lhm.put(Helper.Declaration.GENERICS1, + new String[]{"? extends " + str + " Object", + "? extends " + str + " Object"}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "2"); + testInput.put(testBaseFieldName + clsIdx + "2", str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " Class"); + lhm.put(Helper.Declaration.GENERICS1, "? super " + + str + " Object"); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "3"); + testInput.put(testBaseFieldName + clsIdx + "3", ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + + lhm.put(Helper.Declaration.FIELD_TYPE, str + " HashMap"); + lhm.put(Helper.Declaration.GENERICS1, + new String[]{"? super " + str + " Object", + "? super " + str + " Object"}); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx + "4"); + testInput.put(testBaseFieldName + clsIdx + "4", ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + TESTBASECLSEND() { + /** + * generate end of the test base class: } + * + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_3, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_3, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + protected String GenTestCode(Class tcg) { + String testCode = ""; + testCode += TestCase.TESTBASECLSSTART.genTestCase(null); + for (String anno : annotationCombinations) { + // append annotation on field + testCode += TestCase.GENERICTYPE.genTestCase(anno); + } + testCode += TestCase.TESTBASECLSEND.genTestCase(null); + + return testCode; + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + Class cls = Helper.loadClass(TestCaseGenerator.testBaseClsName); + for (Object fieldName : testInput.keySet()) { + AnnotatedType[] result = + ((AnnotatedParameterizedType) cls.getDeclaredField( + (String) fieldName).getAnnotatedType()). + getAnnotatedActualTypeArguments(); + for (AnnotatedType at : result) { + for (AnnotatedType as : + ((AnnotatedWildcardType) at).getAnnotatedUpperBounds()) { + + if (!Helper.getAT(as).equals(testInput.get(fieldName))) { + Helper.debugPrint( + fieldName + " failed with faulty annotations."); + return false; + } + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new AnnotatedWildcardTypeGetAnnotatedUpperBoundsTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:54 2013 +++ new/test/type-annotations/java/lang/reflect/AnnotatedWildcardType/AnnotatedWildcardTypeGetAnnotatedUpperBoundsTest.txt Thu Aug 8 00:10:54 2013 @@ -0,0 +1,69 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + public Class< ? extends Object> f11; + public HashMap< ? extends Object, ? extends Object> f12; + public Class< ? super Object> f13; + public HashMap< ? super Object, ? super Object> f14; + public @TypeAnno1("TypeAnno1") Class< ? extends @TypeAnno1("TypeAnno1") Object> f21; + public @TypeAnno1("TypeAnno1") HashMap< ? extends @TypeAnno1("TypeAnno1") Object, ? extends @TypeAnno1("TypeAnno1") Object> f22; + public @TypeAnno1("TypeAnno1") Class< ? super @TypeAnno1("TypeAnno1") Object> f23; + public @TypeAnno1("TypeAnno1") HashMap< ? super @TypeAnno1("TypeAnno1") Object, ? super @TypeAnno1("TypeAnno1") Object> f24; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Class< ? extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f31; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 HashMap< ? extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object, ? extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f32; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Class< ? super @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f33; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 HashMap< ? super @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object, ? super @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> f34; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Class< ? extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f41; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") HashMap< ? extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object, ? extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f42; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Class< ? super @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f43; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") HashMap< ? super @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object, ? super @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> f44; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 Class< ? extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f51; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 HashMap< ? extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object, ? extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f52; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 Class< ? super @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f53; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 HashMap< ? super @TypeAnno3 @TypeAnno3 @TypeAnno3 Object, ? super @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> f54; + public @TypeAnno3 Class< ? extends @TypeAnno3 Object> f61; + public @TypeAnno3 HashMap< ? extends @TypeAnno3 Object, ? extends @TypeAnno3 Object> f62; + public @TypeAnno3 Class< ? super @TypeAnno3 Object> f63; + public @TypeAnno3 HashMap< ? super @TypeAnno3 Object, ? super @TypeAnno3 Object> f64; + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + --- /dev/null Thu Aug 8 00:10:56 2013 +++ new/test/type-annotations/java/lang/reflect/Constructor/ConstructorGetAnnotatedReturnTypeTest.java Thu Aug 8 00:10:55 2013 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Constructor.getAnnotatedReturnType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ConstructorGetAnnotatedReturnTypeTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Constructor; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Single constructor, apply all combinations of annotations on it + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ConstructorGetAnnotatedReturnTypeTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + CONSTRUCTOR() { + /** + * generate test constructor: + * class TypeAnnoCls { + * @anno String TypeAnnoCls(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.CONSTRUCTOR_HEADER, + str + " " + typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, " {}"); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (Object clsName : testInput.keySet()) { + Class cls = Helper.loadClass((String) clsName); + Constructor c = cls.getDeclaredConstructor(); + AnnotatedType at = c.getAnnotatedReturnType(); + + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + " failed with faulty annotations."); + return false; + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new ConstructorGetAnnotatedReturnTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:10:58 2013 +++ new/test/type-annotations/java/lang/reflect/Constructor/ConstructorGetAnnotatedReturnTypeTest.txt Thu Aug 8 00:10:57 2013 @@ -0,0 +1,79 @@ +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + + public TypeAnnoCls1() {} +} + + +class TypeAnnoCls2 { + + public @TypeAnno1("TypeAnno1") TypeAnnoCls2() {} +} + + +class TypeAnnoCls3 { + + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 TypeAnnoCls3() {} +} + + +class TypeAnnoCls4 { + + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") TypeAnnoCls4() {} +} + + +class TypeAnnoCls5 { + + public @TypeAnno3 @TypeAnno3 @TypeAnno3 TypeAnnoCls5() {} +} + + +class TypeAnnoCls6 { + + public @TypeAnno3 TypeAnnoCls6() {} +} + --- /dev/null Thu Aug 8 00:11:00 2013 +++ new/test/type-annotations/java/lang/reflect/Executable/ExecutableGetAnnotatedExceptionTypesTest.java Thu Aug 8 00:10:59 2013 @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Executable.getAnnotatedExceptionTypes() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ExecutableGetAnnotatedExceptionTypesTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. No exception + * 2. Single exception + * 3. Multiple exceptions + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ExecutableGetAnnotatedExceptionTypesTest + extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + NOEXCEPTION() { + /** + * generate test method: + * class TypeAnnoCls { + * String m() { + * return null;} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + + if (null == str) { + throw new RuntimeException("bad test base."); + } + + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, ""); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + SINGLEEXCEPTION() { + /** + * generate test method: + * class TypeAnnoCls { + * String m() throws @anno Exception { + * return null; + * } + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_EXCEPTION, + str + " RuntimeException"); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + MULTIPLEEXCEPTION() { + /** + * generate test method: + * class TypeAnnoCls { + * String m() { + * return null; + * } + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_EXCEPTION, + new String[]{str + " RuntimeException", + str + " ArrayIndexOutOfBoundsException"}); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (Object clsName : testInput.keySet()) { + Class cls = Helper.loadClass((String) clsName); + Method m = cls.getDeclaredMethod( + TestCaseGenerator.testBaseMethodName, (Class[]) null); + AnnotatedType[] aet = m.getAnnotatedExceptionTypes(); + + for (AnnotatedType at : aet) { + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + + " failed with faulty annotations."); + return false; + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new ExecutableGetAnnotatedExceptionTypesTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:01 2013 +++ new/test/type-annotations/java/lang/reflect/Executable/ExecutableGetAnnotatedExceptionTypesTest.txt Thu Aug 8 00:11:01 2013 @@ -0,0 +1,171 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + + public String m() {return null;} + +} + + +class TypeAnnoCls2 { + + public String m() throws RuntimeException {return null;} + +} + + +class TypeAnnoCls3 { + + public String m() throws RuntimeException, ArrayIndexOutOfBoundsException {return null;} + +} + + +class TypeAnnoCls4 { + + public String m() {return null;} + +} + + +class TypeAnnoCls5 { + + public String m() throws @TypeAnno1("TypeAnno1") RuntimeException {return null;} + +} + + +class TypeAnnoCls6 { + + public String m() throws @TypeAnno1("TypeAnno1") RuntimeException, @TypeAnno1("TypeAnno1") ArrayIndexOutOfBoundsException {return null;} + +} + + +class TypeAnnoCls7 { + + public String m() {return null;} + +} + + +class TypeAnnoCls8 { + + public String m() throws @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 RuntimeException {return null;} + +} + + +class TypeAnnoCls9 { + + public String m() throws @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 RuntimeException, @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 ArrayIndexOutOfBoundsException {return null;} + +} + + +class TypeAnnoCls10 { + + public String m() {return null;} + +} + + +class TypeAnnoCls11 { + + public String m() throws @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") RuntimeException {return null;} + +} + + +class TypeAnnoCls12 { + + public String m() throws @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") RuntimeException, @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") ArrayIndexOutOfBoundsException {return null;} + +} + + +class TypeAnnoCls13 { + + public String m() {return null;} + +} + + +class TypeAnnoCls14 { + + public String m() throws @TypeAnno3 @TypeAnno3 @TypeAnno3 RuntimeException {return null;} + +} + + +class TypeAnnoCls15 { + + public String m() throws @TypeAnno3 @TypeAnno3 @TypeAnno3 RuntimeException, @TypeAnno3 @TypeAnno3 @TypeAnno3 ArrayIndexOutOfBoundsException {return null;} + +} + + +class TypeAnnoCls16 { + + public String m() {return null;} + +} + + +class TypeAnnoCls17 { + + public String m() throws @TypeAnno3 RuntimeException {return null;} + +} + + +class TypeAnnoCls18 { + + public String m() throws @TypeAnno3 RuntimeException, @TypeAnno3 ArrayIndexOutOfBoundsException {return null;} + +} + + --- /dev/null Thu Aug 8 00:11:03 2013 +++ new/test/type-annotations/java/lang/reflect/Executable/ExecutableGetAnnotatedParameterTypesTest.java Thu Aug 8 00:11:02 2013 @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Executable.getAnnotatedParameterTypes() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ExecutableGetAnnotatedParameterTypesTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.Map; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. No parameter + * 2. Single parameter + * 3. Multiple parameters + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ExecutableGetAnnotatedParameterTypesTest extends AnnotationTest { + + static Map testInput = new LinkedHashMap<>(); + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + NOPARAM() { + /** + * generate test method: + * class TypeAnnoCls { + * String m() { + * return null; + * } + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + testInput.put("arg " + typeAnnoClsName + clsIdx, (Class[]) null); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + ONEPARAM() { + /** + * generate test method: + * class TypeAnnoCls { + * String m(@anno String s) {return null;} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, + str + " String s"); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + testInput.put("arg " + typeAnnoClsName + clsIdx, + new Class[]{String.class}); + lhm.clear(); + clsIdx ++; + return testCode; + } + }, + MULTIPLEPARAM() { + /** + * generate test method: + * class TypeAnnoCls { + * String m(@anno String s, @anno int i) {return null;} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, + new String[]{str + " String s", str + " int i"}); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + testInput.put("arg " + typeAnnoClsName + clsIdx, + new Class[]{String.class, int.class}); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (String clsName : testInput.keySet()) { + if (clsName.startsWith("arg ")) { + continue; + } + Class cls = Helper.loadClass(clsName); + Method m = cls.getDeclaredMethod( + TestCaseGenerator.testBaseMethodName, + (Class[]) testInput.get("arg " + clsName)); + AnnotatedType[] apt = m.getAnnotatedParameterTypes(); + for (AnnotatedType at : apt) { + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + + " failed with faulty annotations."); + return false; + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new ExecutableGetAnnotatedParameterTypesTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:05 2013 +++ new/test/type-annotations/java/lang/reflect/Executable/ExecutableGetAnnotatedParameterTypesTest.txt Thu Aug 8 00:11:04 2013 @@ -0,0 +1,170 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + + public String m() {return null;} + +} + + +class TypeAnnoCls2 { + + public String m( String s) {return null;} + +} + + +class TypeAnnoCls3 { + + public String m( String s, int i) {return null;} + +} + + +class TypeAnnoCls4 { + + public String m() {return null;} + +} + + +class TypeAnnoCls5 { + + public String m(@TypeAnno1("TypeAnno1") String s) {return null;} + +} + + +class TypeAnnoCls6 { + + public String m(@TypeAnno1("TypeAnno1") String s, @TypeAnno1("TypeAnno1") int i) {return null;} + +} + + +class TypeAnnoCls7 { + + public String m() {return null;} + +} + + +class TypeAnnoCls8 { + + public String m(@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String s) {return null;} + +} + + +class TypeAnnoCls9 { + + public String m(@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String s, @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 int i) {return null;} + +} + + +class TypeAnnoCls10 { + + public String m() {return null;} + +} + + +class TypeAnnoCls11 { + + public String m(@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String s) {return null;} + +} + + +class TypeAnnoCls12 { + + public String m(@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String s, @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") int i) {return null;} + +} + + +class TypeAnnoCls13 { + + public String m() {return null;} + +} + + +class TypeAnnoCls14 { + + public String m(@TypeAnno3 @TypeAnno3 @TypeAnno3 String s) {return null;} + +} + + +class TypeAnnoCls15 { + + public String m(@TypeAnno3 @TypeAnno3 @TypeAnno3 String s, @TypeAnno3 @TypeAnno3 @TypeAnno3 int i) {return null;} + +} + + +class TypeAnnoCls16 { + + public String m() {return null;} + +} + + +class TypeAnnoCls17 { + + public String m(@TypeAnno3 String s) {return null;} + +} + + +class TypeAnnoCls18 { + + public String m(@TypeAnno3 String s, @TypeAnno3 int i) {return null;} + +} + --- /dev/null Thu Aug 8 00:11:06 2013 +++ new/test/type-annotations/java/lang/reflect/Executable/ExecutableGetAnnotatedReceiverTypeTest.java Thu Aug 8 00:11:05 2013 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Executable.getAnnotatedReceiverType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ExecutableGetAnnotatedReceiverTypeTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Apply all combinations of annotations on receiver + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ExecutableGetAnnotatedReceiverTypeTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + RECEIVER() { + /** + * generate test method: + * class TypeAnnoCls { + * String m() {return null;} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, + str + " " + typeAnnoClsName + clsIdx + " this"); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (Object clsName : testInput.keySet()) { + Class cls = Helper.loadClass((String) clsName); + Method m = cls.getDeclaredMethod( + TestCaseGenerator.testBaseMethodName, + (Class[]) null); + AnnotatedType at = m.getAnnotatedReceiverType(); + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + " failed with faulty annotations."); + return false; + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new ExecutableGetAnnotatedReceiverTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:08 2013 +++ new/test/type-annotations/java/lang/reflect/Executable/ExecutableGetAnnotatedReceiverTypeTest.txt Thu Aug 8 00:11:07 2013 @@ -0,0 +1,87 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + + public String m( TypeAnnoCls1 this) {return null;} + +} + + +class TypeAnnoCls2 { + + public String m(@TypeAnno1("TypeAnno1") TypeAnnoCls2 this) {return null;} + +} + + +class TypeAnnoCls3 { + + public String m(@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 TypeAnnoCls3 this) {return null;} + +} + + +class TypeAnnoCls4 { + + public String m(@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") TypeAnnoCls4 this) {return null;} + +} + + +class TypeAnnoCls5 { + + public String m(@TypeAnno3 @TypeAnno3 @TypeAnno3 TypeAnnoCls5 this) {return null;} + +} + + +class TypeAnnoCls6 { + + public String m(@TypeAnno3 TypeAnnoCls6 this) {return null;} + +} + + --- /dev/null Thu Aug 8 00:11:11 2013 +++ new/test/type-annotations/java/lang/reflect/Field/FieldGetAnnotatedTypeTest.java Thu Aug 8 00:11:10 2013 @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Field.getAnnotatedType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main FieldGetAnnotatedTypeTest + */ +import java.lang.reflect.AnnotatedType; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Apply all combinations of annotations on field type + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class FieldGetAnnotatedTypeTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLSSTART() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.IMPORT, null); + lhm.put(Helper.Declaration.CLASS, testBaseClsName); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.CLASS); + lhm.clear(); + return testCode; + } + }, + FIELDTYPE() { + /** + * generate field type: + * public [#ANNO] type f1; + * then append annotations on [#ANNO] + * + * input should be like [@anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test case."); + } + String testCode = ""; + lhm.put(Helper.Declaration.FIELD_TYPE, str + " String"); + lhm.put(Helper.Declaration.FIELD_NAME, + testBaseFieldName + clsIdx); + testInput.put(testBaseFieldName + clsIdx, str); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_TYPE); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + TESTBASECLSEND() { + /** + * generate end of the test base class: } + * + */ + public String genTestCase(String str) { + String testCode = ""; + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.ANNOTATION_TYPE_3, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_1, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_2, ""); + lhm.put(Helper.Declaration.CONTAINING_ANNOTATION_TYPE_3, ""); + testCode += Helper.genDeclaration(lhm, + Helper.Declaration.FIELD_ARRAY); + lhm.clear(); + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // generate source code for test according to TestCase + protected String GenTestCode(Class tcg) { + String testCode = ""; + testCode += TestCase.TESTBASECLSSTART.genTestCase(null); + for (String anno : annotationCombinations) { + // append annotation on field + testCode += TestCase.FIELDTYPE.genTestCase(anno); + } + testCode += TestCase.TESTBASECLSEND.genTestCase(null); + + return testCode; + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + Class cls = Helper.loadClass(TestCaseGenerator.testBaseClsName); + for (Object fieldName : testInput.keySet()) { + AnnotatedType at = + cls.getDeclaredField((String) fieldName).getAnnotatedType(); + if (!Helper.getAT(at).equals(testInput.get(fieldName))) { + Helper.debugPrint(fieldName + " failed with faulty annotations."); + return false; + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new FieldGetAnnotatedTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:13 2013 +++ new/test/type-annotations/java/lang/reflect/Field/FieldGetAnnotatedTypeTest.txt Thu Aug 8 00:11:12 2013 @@ -0,0 +1,51 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + public String f1; + public @TypeAnno1("TypeAnno1") String f2; + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String f3; + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String f4; + public @TypeAnno3 @TypeAnno3 @TypeAnno3 String f5; + public @TypeAnno3 String f6; + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + --- /dev/null Thu Aug 8 00:11:15 2013 +++ new/test/type-annotations/java/lang/reflect/Method/MethodGetAnnotatedReturnTypeTest.java Thu Aug 8 00:11:14 2013 @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Method.getAnnotatedReturnType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main MethodGetAnnotatedReturnTypeTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. Apply all combinations of annotations on method return type + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class MethodGetAnnotatedReturnTypeTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + METHOD() { + /** + * generate test constructor: + * class TypeAnnoCls { + * @anno String TypeAnnoCls(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, str + " String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, ""); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (Object clsName : testInput.keySet()) { + Class cls = Helper.loadClass((String) clsName); + Method m = cls.getDeclaredMethod( + TestCaseGenerator.testBaseMethodName, (Class[]) null); + AnnotatedType at = m.getAnnotatedReturnType(); + + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + " failed with faulty annotations."); + return false; + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new MethodGetAnnotatedReturnTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:17 2013 +++ new/test/type-annotations/java/lang/reflect/Method/MethodGetAnnotatedReturnTypeTest.txt Thu Aug 8 00:11:16 2013 @@ -0,0 +1,87 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + + public String m() {return null;} + +} + + +class TypeAnnoCls2 { + + public @TypeAnno1("TypeAnno1") String m() {return null;} + +} + + +class TypeAnnoCls3 { + + public @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String m() {return null;} + +} + + +class TypeAnnoCls4 { + + public @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String m() {return null;} + +} + + +class TypeAnnoCls5 { + + public @TypeAnno3 @TypeAnno3 @TypeAnno3 String m() {return null;} + +} + + +class TypeAnnoCls6 { + + public @TypeAnno3 String m() {return null;} + +} + + --- /dev/null Thu Aug 8 00:11:18 2013 +++ new/test/type-annotations/java/lang/reflect/Parameter/ParameterGetAnnotatedTypeTest.java Thu Aug 8 00:11:17 2013 @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: Parameter.getAnnotatedType() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main ParameterGetAnnotatedTypeTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Parameter; +import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.Map; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. One parameter + * 2. Multiple parameter + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class ParameterGetAnnotatedTypeTest extends AnnotationTest { + + static Map testInput = new LinkedHashMap<>(); + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + ONEPARAM() { + /** + * generate test method: + * class TypeAnnoCls { + * String m(@anno String s) {return null;} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, str + + " String s"); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + testInput.put("arg " + typeAnnoClsName + clsIdx, + new Class[]{String.class}); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + MULTIPLEPARAM() { + /** + * generate test method: + * class TypeAnnoCls { + * String m(@anno String s, @anno int i) {return null;} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.METHOD_HEADER, "String m"); + lhm.put(Helper.Declaration.METHOD_PARAMETER, + new String[]{str + " String s", str + " int i"}); + lhm.put(Helper.Declaration.METHOD_BODY, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + testInput.put("arg " + typeAnnoClsName + clsIdx, + new Class[]{String.class, int.class}); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (String clsName : testInput.keySet()) { + if (clsName.startsWith("arg ")) { + continue; + } + + Class cls = Helper.loadClass(clsName); + Method m = cls.getDeclaredMethod( + TestCaseGenerator.testBaseMethodName, + (Class[]) testInput.get("arg " + clsName)); + + Parameter[] ps = m.getParameters(); + for (Parameter p : ps) { + AnnotatedType at = p.getAnnotatedType(); + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + + " failed with faulty annotations."); + return false; + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new ParameterGetAnnotatedTypeTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:20 2013 +++ new/test/type-annotations/java/lang/reflect/Parameter/ParameterGetAnnotatedTypeTest.txt Thu Aug 8 00:11:19 2013 @@ -0,0 +1,129 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1 { + + public String m( String s) {return null;} + +} + + +class TypeAnnoCls2 { + + public String m( String s, int i) {return null;} + +} + + +class TypeAnnoCls3 { + + public String m(@TypeAnno1("TypeAnno1") String s) {return null;} + +} + + +class TypeAnnoCls4 { + + public String m(@TypeAnno1("TypeAnno1") String s, @TypeAnno1("TypeAnno1") int i) {return null;} + +} + + +class TypeAnnoCls5 { + + public String m(@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String s) {return null;} + +} + + +class TypeAnnoCls6 { + + public String m(@TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 String s, @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 int i) {return null;} + +} + + +class TypeAnnoCls7 { + + public String m(@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String s) {return null;} + +} + + +class TypeAnnoCls8 { + + public String m(@TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") String s, @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") int i) {return null;} + +} + + +class TypeAnnoCls9 { + + public String m(@TypeAnno3 @TypeAnno3 @TypeAnno3 String s) {return null;} + +} + + +class TypeAnnoCls10 { + + public String m(@TypeAnno3 @TypeAnno3 @TypeAnno3 String s, @TypeAnno3 @TypeAnno3 @TypeAnno3 int i) {return null;} + +} + + +class TypeAnnoCls11 { + + public String m(@TypeAnno3 String s) {return null;} + +} + + +class TypeAnnoCls12 { + + public String m(@TypeAnno3 String s, @TypeAnno3 int i) {return null;} + +} + + --- /dev/null Thu Aug 8 00:11:22 2013 +++ new/test/type-annotations/java/lang/reflect/TypeVariable/TypeVariableGetAnnotatedBoundsTest.java Thu Aug 8 00:11:21 2013 @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +/** + * @test + * @bug 8013497 + * @summary test for API: TypeVariable.getAnnotatedBounds() + * @library ../../../../ + * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper + * @author Charlie Wang + * @run main TypeVariableGetAnnotatedBoundsTest + */ +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.TypeVariable; + +/* + * Construct the test code in a structure specified in TestCase. + * In each of the following cases, different combinations of annotation + * specified in AnnotationTest.annotationCombinations are tested. The output + * annotations must be the same as input both in value and order. + * 1. No bounds + * 2. Single bounds + * 3. Multiple bounds + * The program test all the cases in TestCase by looping over each one of it. + * Test cases are constructed with small code snippet from Helper.SrcType + * using changable annotations, type and name. After these values are specified, + * the method GenTestCode() generates corresponding java code, encapsulate them + * with a class. Then this class is compiled by Helper.compileCode() into + * classes which is later loaded into memory by Helper.loadClass(). + * The test fails if any of the cases fail. + */ +public class TypeVariableGetAnnotatedBoundsTest extends AnnotationTest { + + enum TestCase implements TestCaseGenerator { + + TESTBASECLS() { + /** + * generate test base, which is the class name used to compile the code: + * import java.io.*; + * import java.util.*; + * import java.lang.*; + * import java.lang.reflect.*; + * import java.lang.annotation.*; + * class testBaseClsName { } + */ + public String genTestCase(String str) { + if (0 == clsIdx) { + clsIdx++; + return AnnotationTest.genBaseClass(testBaseClsName); + } else { + return ""; + } + } + }, + NOBOUND() { + /** + * generate test class: + * class TypeAnnoCls { + * T method1(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.GENERICS1, "T"); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, ""); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + SINGLEBOUND() { + /** + * generate test class: + * class TypeAnnoCls { + * T method1(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.GENERICS1, + "T extends " + str + " Object"); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }, + MULTIPLEBOUNDS() { + /** + * generate test class: + * class TypeAnnoCls { + * T method1(){} + * } + * + * input should be like [anno] + */ + public String genTestCase(String str) { + if (null == str) { + throw new RuntimeException("bad test base."); + } + String testCode = ""; + lhm.clear(); + lhm.put(Helper.Declaration.CLASS, typeAnnoClsName + clsIdx); + lhm.put(Helper.Declaration.GENERICS2, + "T " + str + " Object " + str + " Serializable"); + lhm.put(Helper.Declaration.CLASS_BODY_START, ""); + lhm.put(Helper.Declaration.CLASS_BODY_END, ""); + testCode += Helper.genDeclaration(lhm); + testInput.put(typeAnnoClsName + clsIdx, str); + lhm.clear(); + clsIdx++; + return testCode; + } + }; + + // generate test class of a specific case + public String genTestCase(String str) { + return ""; + } + } + + // compare input with result + protected boolean checkResult() throws Exception { + compileCode(TestCase.class); + // Get Class object for the compiled class + for (Object clsName : testInput.keySet()) { + Class cls = Helper.loadClass((String) clsName); + TypeVariable[] typeVars = cls.getTypeParameters(); + for (TypeVariable tv : typeVars) { + AnnotatedType[] abs = ((TypeVariable) tv).getAnnotatedBounds(); + for (AnnotatedType at : abs) { + if (!Helper.getAT(at).equals(testInput.get(clsName))) { + Helper.debugPrint(clsName + + " failed with faulty annotations."); + return false; + } + } + } + } + return true; + } + + public static void main(String[] args) throws Exception { + new TypeVariableGetAnnotatedBoundsTest().test(); + } +} --- /dev/null Thu Aug 8 00:11:23 2013 +++ new/test/type-annotations/java/lang/reflect/TypeVariable/TypeVariableGetAnnotatedBoundsTest.txt Thu Aug 8 00:11:22 2013 @@ -0,0 +1,135 @@ + +import java.io.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import java.lang.annotation.*; + + +class TypeAnnoCls0 { + +} + +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno1Container.class) +@interface TypeAnno1 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno2Container.class) +@interface TypeAnno2 { + String value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(TypeAnno3Container.class) +@interface TypeAnno3 { +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno1Container { + TypeAnno1[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno2Container { + TypeAnno2[] value(); +} +@Target(ElementType.TYPE_USE) +@Retention(RetentionPolicy.RUNTIME) +@interface TypeAnno3Container { + TypeAnno3[] value(); +} + +class TypeAnnoCls1< T > { + +} + + +class TypeAnnoCls2< T extends Object> { + +} + + +class TypeAnnoCls3< T extends Object & Serializable> { + +} + + +class TypeAnnoCls4< T > { + +} + + +class TypeAnnoCls5< T extends @TypeAnno1("TypeAnno1") Object> { + +} + + +class TypeAnnoCls6< T extends @TypeAnno1("TypeAnno1") Object & @TypeAnno1("TypeAnno1") Serializable> { + +} + + +class TypeAnnoCls7< T > { + +} + + +class TypeAnnoCls8< T extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object> { + +} + + +class TypeAnnoCls9< T extends @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Object & @TypeAnno1("TypeAnno1") @TypeAnno2("TypeAnno2") @TypeAnno3 Serializable> { + +} + + +class TypeAnnoCls10< T > { + +} + + +class TypeAnnoCls11< T extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object> { + +} + + +class TypeAnnoCls12< T extends @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Object & @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") @TypeAnno2("TypeAnno2") Serializable> { + +} + + +class TypeAnnoCls13< T > { + +} + + +class TypeAnnoCls14< T extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object> { + +} + + +class TypeAnnoCls15< T extends @TypeAnno3 @TypeAnno3 @TypeAnno3 Object & @TypeAnno3 @TypeAnno3 @TypeAnno3 Serializable> { + +} + + +class TypeAnnoCls16< T > { + +} + + +class TypeAnnoCls17< T extends @TypeAnno3 Object> { + +} + + +class TypeAnnoCls18< T extends @TypeAnno3 Object & @TypeAnno3 Serializable> { + +} + +