test/tools/javac/annotations/repeatingAnnotations/combo/DocumentedAnnoCombo.java

Mon, 18 Feb 2013 14:29:40 -0800

author
jjg
date
Mon, 18 Feb 2013 14:29:40 -0800
changeset 1589
87884cd0fea3
parent 1492
df694c775e8a
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8008339: Test TargetAnnoCombo.java is broken
Reviewed-by: jjh

     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /**
    25  * @test
    26  * @bug      8002157
    27  * @author   sogoel
    28  * @summary  Positive combo test for use of Documented on baseAnno/containerAnno
    29  * @build    Helper
    30  * @compile  DocumentedAnnoCombo.java
    31  * @run main DocumentedAnnoCombo
    32  */
    34 import javax.tools.DiagnosticCollector;
    35 import javax.tools.JavaFileObject;
    37 /*
    38  * Generate valid test src for the use of @Documented on container anno
    39  * or on both base anno and container anno. Both test src should compile.
    40  * Repeating annotations used only on class for these generated test src.
    41  */
    42 public class DocumentedAnnoCombo extends Helper {
    43     static int errors = 0;
    45     enum TestCases {
    46         DocumentedonBothAnno(true),
    47         DocumentedonContainer(true);
    49         TestCases(boolean compile) {
    50             this.compile = compile;
    51         }
    53         boolean compile;
    54         boolean shouldCompile() {
    55             return compile;
    56         }
    57     }
    59     public static void main(String[] args) throws Exception {
    60         new DocumentedAnnoCombo().runTest();
    61     }
    63     public void runTest() throws Exception {
    64         boolean ok = false;
    65         int testCtr = 0;
    67         // Create test source content
    68         for (TestCases className : TestCases.values()) {
    69             testCtr++;
    70             String contents = getContent(className.toString());
    72             // Compile the generated source file
    73             DiagnosticCollector<JavaFileObject> diagnostics =
    74                     new DiagnosticCollector<JavaFileObject>();
    75             ok = compileCode(className.toString(), contents, diagnostics);
    76             if (!ok) {
    77                 error("Class="+ className +" did not compile as expected", contents);
    78             } else {
    79                 System.out.println("Test passed for className: " + className);
    80             }
    81         }
    83         System.out.println("Total number of tests run: " + testCtr);
    84         System.out.println("Total number of errors: " + errors);
    86         if (errors > 0)
    87             throw new Exception(errors + " errors found");
    88     }
    90     private String getContent(String className) {
    92         StringBuilder annoData = new StringBuilder();
    93         switch(className) {
    94             case "DocumentedonBothAnno":
    95                 annoData.append(Helper.ContentVars.DOCUMENTED.getVal())
    96                 .append(Helper.ContentVars.CONTAINER.getVal())
    97                 .append(Helper.ContentVars.DOCUMENTED.getVal())
    98                 .append(Helper.ContentVars.REPEATABLE.getVal())
    99                 .append(Helper.ContentVars.BASE.getVal());
   100             break;
   101             case "DocumentedonContainer":
   102                 annoData.append(Helper.ContentVars.DOCUMENTED.getVal())
   103                 .append(Helper.ContentVars.CONTAINER.getVal())
   104                 .append(Helper.ContentVars.REPEATABLE.getVal())
   105                 .append(Helper.ContentVars.BASE.getVal());
   106             break;
   107         }
   109         String contents = Helper.ContentVars.IMPORTCONTAINERSTMTS.getVal()
   110                           + Helper.ContentVars.IMPORTDOCUMENTED.getVal()
   111                           + annoData
   112                           + Helper.ContentVars.REPEATABLEANNO.getVal()
   113                           + "\nclass "+ className + "{}";
   114         return contents;
   115     }
   117     private void error(String msg, String... contents) {
   118         System.out.println("error: " + msg);
   119         errors++;
   120         if (contents.length == 1) {
   121             System.out.println("Contents = " + contents[0]);
   122         }
   123     }
   124 }

mercurial