langtools/test/tools/javac/classfiles/attributes/deprecated/DeprecatedPackageTest.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
child 35359 f04501964016
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     4
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     8
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    13
 * accompanied this code).
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    14
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    18
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    21
 * questions.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    22
 */
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    23
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    24
/*
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    25
 * @test
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    26
 * @bug 8042261
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    27
 * @summary Checking that deprecated attribute does not apply to classes of deprecated package.
26100
bb7dd001d190 8050429: Update/cleanup ToolBox
jjg
parents: 25434
diff changeset
    28
 * @library /tools/lib /tools/javac/lib ../lib
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    29
 * @modules jdk.jdeps/com.sun.tools.classfile
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.file
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27552
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.main
26100
bb7dd001d190 8050429: Update/cleanup ToolBox
jjg
parents: 25434
diff changeset
    33
 * @build  ToolBox TestBase TestResult InMemoryFileManager
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    34
 * @run main DeprecatedPackageTest
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    35
 */
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    36
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    37
import com.sun.tools.classfile.Attribute;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    38
import com.sun.tools.classfile.ClassFile;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    39
import com.sun.tools.classfile.Deprecated_attribute;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    40
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    41
public class DeprecatedPackageTest extends TestResult {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    42
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    43
    private static final String[] sourceTest = new String[]{
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    44
        "package deprecated;\n"
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    45
        + "public class notDeprecated{}",
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    46
        "package deprecated;\n"
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    47
        + "public interface notDeprecated{}",
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    48
        "package deprecated;\n"
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    49
        + "public @interface notDeprecated{}",
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    50
        "package deprecated;\n"
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    51
        + "public enum notDeprecated{}"
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    52
    };
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    53
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    54
    private static final String CLASS_NAME = "deprecated.notDeprecated";
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    55
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    56
    private static final String PACKAGE_INFO =
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    57
            "@Deprecated\n" +
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    58
            "package deprecated;";
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    59
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    60
    public static void main(String[] args) throws TestFailedException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    61
        new DeprecatedPackageTest().test();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    62
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    63
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    64
    private void test() throws TestFailedException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    65
        try {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    66
            for (String src : sourceTest) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    67
                test(PACKAGE_INFO, src);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    68
                test(PACKAGE_INFO.replaceAll("@Deprecated", "/** @deprecated */"), src);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    69
            }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    70
        } catch (Exception e) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    71
            addFailure(e);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    72
        } finally {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    73
            checkStatus();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    74
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    75
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    76
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    77
    private void test(String package_info, String src) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    78
        addTestCase(src);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    79
        printf("Testing test case: \n%s\n", src);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    80
        try {
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents: 26100
diff changeset
    81
            ClassFile cf = readClassFile(compile(
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    82
                        new String[]{"package-info.java", package_info},
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    83
                        new String[]{"notDeprecated.java", src})
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents: 26100
diff changeset
    84
                    .getClasses().get(CLASS_NAME));
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    85
            Deprecated_attribute attr =
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    86
                    (Deprecated_attribute) cf.getAttribute(Attribute.Deprecated);
27552
8a4b2d3639c1 8042931: Implement classfile tests for EnclosingMethod attribute.
aeremeev
parents: 26100
diff changeset
    87
            checkNull(attr, "Class can not have deprecated attribute : " + CLASS_NAME);
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    88
        } catch (Exception e) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    89
            addFailure(e);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    90
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    91
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    92
}