Path: blob/master/test/langtools/tools/sjavac/IncCompInheritance.java
41144 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 805625826* @summary Analysis of public API does not take super classes into account27* @library /tools/lib28* @modules jdk.compiler/com.sun.tools.javac.api29* jdk.compiler/com.sun.tools.javac.main30* jdk.compiler/com.sun.tools.sjavac31* @build Wrapper toolbox.ToolBox32* @run main Wrapper IncCompInheritance33*/3435import java.nio.file.Path;36import java.nio.file.Paths;3738public class IncCompInheritance extends SjavacBase {39public static void main(String... args) throws Exception {4041Path root = Paths.get(IncCompInheritance.class.getSimpleName() + "Test");42Path src = root.resolve("src");43Path classes = root.resolve("classes");4445// Prep source files: A <- B <- C46String a = "package pkga; public class A { public void m() {} }";47String b = "package pkgb; public class B extends pkga.A {}";48String c = "package pkgc; public class C extends pkgb.B {{ new pkgb.B().m(); }}";49toolbox.writeFile(src.resolve("pkga/A.java"), a);50toolbox.writeFile(src.resolve("pkgb/B.java"), b);51toolbox.writeFile(src.resolve("pkgc/C.java"), c);5253// Initial compile (should succeed)54int rc1 = compile("-d", classes, "--state-dir=" + classes, src);55if (rc1 != 0)56throw new AssertionError("Compilation failed unexpectedly");5758// Remove method A.m59Thread.sleep(2500); // Make sure we get a new timestamp60String aModified = "package pkga; public class A { }";61toolbox.writeFile(src.resolve("pkga/A.java"), aModified);6263// Incremental compile (C should now be recompiled even though it64// depends on A only through inheritance via B).65// Since A.m is removed, this should fail.66int rc2 = compile("-d", classes, "--state-dir=" + classes, src);67if (rc2 == 0)68throw new AssertionError("Compilation succeeded unexpectedly");69}70}717273