1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/annotations/repeatingAnnotations/combo/InheritedAnnoCombo.java Wed Nov 07 17:01:19 2012 -0800 1.3 @@ -0,0 +1,128 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * @test 1.29 + * @bug 8002157 1.30 + * @author sogoel 1.31 + * @summary Positive combo test for use of Inherited on baseAnno/containerAnno 1.32 + * @build Helper 1.33 + * @compile InheritedAnnoCombo.java 1.34 + * @run main InheritedAnnoCombo 1.35 + */ 1.36 + 1.37 +import javax.tools.DiagnosticCollector; 1.38 +import javax.tools.JavaFileObject; 1.39 + 1.40 +/* 1.41 + * Generate valid test src for the use of @Inherited on container anno 1.42 + * or on both base anno and container anno. Both test src should compile. 1.43 + * Repeating annotations used only on class for these generated test src. 1.44 + */ 1.45 + 1.46 +public class InheritedAnnoCombo extends Helper { 1.47 + static int errors = 0; 1.48 + enum TestCases { 1.49 + InheritedonBothAnno(true), 1.50 + InheritedonBase(true); 1.51 + 1.52 + TestCases(boolean compile) { 1.53 + this.compile = compile; 1.54 + } 1.55 + 1.56 + boolean compile; 1.57 + boolean shouldCompile() { 1.58 + return compile; 1.59 + } 1.60 + } 1.61 + 1.62 + public static void main(String[] args) throws Exception { 1.63 + new InheritedAnnoCombo().runTest(); 1.64 + } 1.65 + 1.66 + public void runTest() throws Exception { 1.67 + int testCtr = 0; 1.68 + boolean ok = false; 1.69 + 1.70 + // Create test source content 1.71 + for (TestCases className : TestCases.values()) { 1.72 + testCtr++; 1.73 + String contents = getContent(className.toString()); 1.74 + 1.75 + // Compile the generated code 1.76 + DiagnosticCollector<JavaFileObject> diagnostics = 1.77 + new DiagnosticCollector<JavaFileObject>(); 1.78 + ok = compileCode(className.toString(), contents, diagnostics); 1.79 + 1.80 + if (!ok) { 1.81 + error("Class="+ className +" did not compile as expected", contents); 1.82 + } else { 1.83 + System.out.println("Test passed for className: " + className); 1.84 + } 1.85 + } 1.86 + 1.87 + System.out.println("Total number of tests run: " + testCtr); 1.88 + System.out.println("Total number of errors: " + errors); 1.89 + 1.90 + if (errors > 0) 1.91 + throw new Exception(errors + " errors found"); 1.92 + } 1.93 + 1.94 + private String getContent(String className) { 1.95 + 1.96 + StringBuilder annoData = new StringBuilder(); 1.97 + switch(className) { 1.98 + case "InheritedonBothAnno": 1.99 + annoData.append(Helper.ContentVars.INHERITED.getVal()) 1.100 + .append(Helper.ContentVars.CONTAINERFOR.getVal()) 1.101 + .append(Helper.ContentVars.CONTAINER.getVal()) 1.102 + .append(Helper.ContentVars.INHERITED.getVal()) 1.103 + .append(Helper.ContentVars.CONTAINEDBY.getVal()) 1.104 + .append(Helper.ContentVars.BASE.getVal()); 1.105 + break; 1.106 + case "InheritedonBase": 1.107 + annoData.append(Helper.ContentVars.INHERITED.getVal()) 1.108 + .append(Helper.ContentVars.CONTAINERFOR.getVal()) 1.109 + .append(Helper.ContentVars.CONTAINER.getVal()) 1.110 + .append(Helper.ContentVars.CONTAINEDBY.getVal()) 1.111 + .append(Helper.ContentVars.BASE.getVal()); 1.112 + break; 1.113 + } 1.114 + 1.115 + String contents = Helper.ContentVars.IMPORTCONTAINERSTMTS.getVal() 1.116 + + Helper.ContentVars.IMPORTINHERITED.getVal() 1.117 + + annoData 1.118 + + Helper.ContentVars.REPEATABLEANNO.getVal() 1.119 + + "\nclass "+ className + "{}"; 1.120 + return contents; 1.121 + } 1.122 + 1.123 + private void error(String msg, String... contents) { 1.124 + System.out.println("error: " + msg); 1.125 + errors++; 1.126 + if (contents.length == 1) { 1.127 + System.out.println("Contents = " + contents[0]); 1.128 + } 1.129 + } 1.130 +} 1.131 +