langtools/test/tools/sjavac/IncCompInheritance.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 36778 e04318f39f92
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     1
/*
35356
e919fd8db52c 8056989: Sjavac --server option should be optional
alundblad
parents: 32799
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     4
 *
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 31115
diff changeset
     7
 * published by the Free Software Foundation.
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     8
 *
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    13
 * accompanied this code).
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    14
 *
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    18
 *
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    21
 * questions.
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    22
 */
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    23
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    24
/*
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    25
 * @test
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    26
 * @bug 8056258
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    27
 * @summary Analysis of public API does not take super classes into account
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    28
 * @library /tools/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 26991
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 26991
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36778
diff changeset
    31
 *          jdk.compiler/com.sun.tools.sjavac
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build Wrapper toolbox.ToolBox
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    33
 * @run main Wrapper IncCompInheritance
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    34
 */
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    35
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    36
import java.nio.file.Path;
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    37
import java.nio.file.Paths;
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    38
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    39
public class IncCompInheritance extends SjavacBase {
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    40
    public static void main(String... args) throws Exception {
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    41
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    42
        Path root = Paths.get(IncCompInheritance.class.getSimpleName() + "Test");
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    43
        Path src = root.resolve("src");
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    44
        Path classes = root.resolve("classes");
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    45
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    46
        // Prep source files: A <- B <- C
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    47
        String a = "package pkga; public class A { public void m() {} }";
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    48
        String b = "package pkgb; public class B extends pkga.A {}";
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    49
        String c = "package pkgc; public class C extends pkgb.B {{ new pkgb.B().m(); }}";
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    50
        toolbox.writeFile(src.resolve("pkga/A.java"), a);
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    51
        toolbox.writeFile(src.resolve("pkgb/B.java"), b);
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    52
        toolbox.writeFile(src.resolve("pkgc/C.java"), c);
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    53
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    54
        // Initial compile (should succeed)
35356
e919fd8db52c 8056989: Sjavac --server option should be optional
alundblad
parents: 32799
diff changeset
    55
        int rc1 = compile("-d", classes, "--state-dir=" + classes, src);
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    56
        if (rc1 != 0)
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    57
            throw new AssertionError("Compilation failed unexpectedly");
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    58
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    59
        // Remove method A.m
31115
8d8e98052d5d 8054717: SJavac should track changes in the public apis of classpath classes!
alundblad
parents: 30730
diff changeset
    60
        Thread.sleep(2500); // Make sure we get a new timestamp
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    61
        String aModified = "package pkga; public class A { }";
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    62
        toolbox.writeFile(src.resolve("pkga/A.java"), aModified);
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    63
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    64
        // Incremental compile (C should now be recompiled even though it
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    65
        // depends on A only through inheritance via B).
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    66
        // Since A.m is removed, this should fail.
35356
e919fd8db52c 8056989: Sjavac --server option should be optional
alundblad
parents: 32799
diff changeset
    67
        int rc2 = compile("-d", classes, "--state-dir=" + classes, src);
26991
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    68
        if (rc2 == 0)
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    69
            throw new AssertionError("Compilation succeeded unexpectedly");
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    70
    }
88d998b3bb4b 8056258: Analysis of public API does not take super classes into account
alundblad
parents:
diff changeset
    71
}