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