jjg@1401: /* jjg@1401: * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. jjg@1401: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1401: * jjg@1401: * This code is free software; you can redistribute it and/or modify it jjg@1401: * under the terms of the GNU General Public License version 2 only, as jjg@1401: * published by the Free Software Foundation. jjg@1401: * jjg@1401: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1401: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1401: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1401: * version 2 for more details (a copy is included in the LICENSE file that jjg@1401: * accompanied this code). jjg@1401: * jjg@1401: * You should have received a copy of the GNU General Public License version jjg@1401: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1401: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1401: * jjg@1401: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1401: * or visit www.oracle.com if you need additional information or have any jjg@1401: * questions. jjg@1401: */ jjg@1401: jjg@1401: /** jjg@1401: * @test jjg@1401: * @bug 8002157 jjg@1401: * @author sogoel jjg@1401: * @summary Positive combo test for use of Inherited on baseAnno/containerAnno jjg@1401: * @build Helper jjg@1401: * @compile InheritedAnnoCombo.java jjg@1401: * @run main InheritedAnnoCombo jjg@1401: */ jjg@1401: jjg@1401: import javax.tools.DiagnosticCollector; jjg@1401: import javax.tools.JavaFileObject; jjg@1401: jjg@1401: /* jjg@1401: * Generate valid test src for the use of @Inherited on container anno jjg@1401: * or on both base anno and container anno. Both test src should compile. jjg@1401: * Repeating annotations used only on class for these generated test src. jjg@1401: */ jjg@1401: jjg@1401: public class InheritedAnnoCombo extends Helper { jjg@1401: static int errors = 0; jjg@1401: enum TestCases { jjg@1401: InheritedonBothAnno(true), jjg@1401: InheritedonBase(true); jjg@1401: jjg@1401: TestCases(boolean compile) { jjg@1401: this.compile = compile; jjg@1401: } jjg@1401: jjg@1401: boolean compile; jjg@1401: boolean shouldCompile() { jjg@1401: return compile; jjg@1401: } jjg@1401: } jjg@1401: jjg@1401: public static void main(String[] args) throws Exception { jjg@1401: new InheritedAnnoCombo().runTest(); jjg@1401: } jjg@1401: jjg@1401: public void runTest() throws Exception { jjg@1401: int testCtr = 0; jjg@1401: boolean ok = false; jjg@1401: jjg@1401: // Create test source content jjg@1401: for (TestCases className : TestCases.values()) { jjg@1401: testCtr++; jjg@1401: String contents = getContent(className.toString()); jjg@1401: jjg@1401: // Compile the generated code jjg@1401: DiagnosticCollector diagnostics = jjg@1401: new DiagnosticCollector(); jjg@1401: ok = compileCode(className.toString(), contents, diagnostics); jjg@1401: jjg@1401: if (!ok) { jjg@1401: error("Class="+ className +" did not compile as expected", contents); jjg@1401: } else { jjg@1401: System.out.println("Test passed for className: " + className); jjg@1401: } jjg@1401: } jjg@1401: jjg@1401: System.out.println("Total number of tests run: " + testCtr); jjg@1401: System.out.println("Total number of errors: " + errors); jjg@1401: jjg@1401: if (errors > 0) jjg@1401: throw new Exception(errors + " errors found"); jjg@1401: } jjg@1401: jjg@1401: private String getContent(String className) { jjg@1401: jjg@1401: StringBuilder annoData = new StringBuilder(); jjg@1401: switch(className) { jjg@1401: case "InheritedonBothAnno": jjg@1401: annoData.append(Helper.ContentVars.INHERITED.getVal()) jjg@1401: .append(Helper.ContentVars.CONTAINERFOR.getVal()) jjg@1401: .append(Helper.ContentVars.CONTAINER.getVal()) jjg@1401: .append(Helper.ContentVars.INHERITED.getVal()) jjg@1401: .append(Helper.ContentVars.CONTAINEDBY.getVal()) jjg@1401: .append(Helper.ContentVars.BASE.getVal()); jjg@1401: break; jjg@1401: case "InheritedonBase": jjg@1401: annoData.append(Helper.ContentVars.INHERITED.getVal()) jjg@1401: .append(Helper.ContentVars.CONTAINERFOR.getVal()) jjg@1401: .append(Helper.ContentVars.CONTAINER.getVal()) jjg@1401: .append(Helper.ContentVars.CONTAINEDBY.getVal()) jjg@1401: .append(Helper.ContentVars.BASE.getVal()); jjg@1401: break; jjg@1401: } jjg@1401: jjg@1401: String contents = Helper.ContentVars.IMPORTCONTAINERSTMTS.getVal() jjg@1401: + Helper.ContentVars.IMPORTINHERITED.getVal() jjg@1401: + annoData jjg@1401: + Helper.ContentVars.REPEATABLEANNO.getVal() jjg@1401: + "\nclass "+ className + "{}"; jjg@1401: return contents; jjg@1401: } jjg@1401: jjg@1401: private void error(String msg, String... contents) { jjg@1401: System.out.println("error: " + msg); jjg@1401: errors++; jjg@1401: if (contents.length == 1) { jjg@1401: System.out.println("Contents = " + contents[0]); jjg@1401: } jjg@1401: } jjg@1401: } jjg@1401: