T8068517.java revision 2794:a510d7536fa1
1/* 2 * Copyright (c) 2015, 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 */ 23 24/** @test 25 * @bug 8034854 26 * @summary Verify that nested enums have correct abstract flag in the InnerClasses attribute. 27 * @library /tools/lib 28 * @build ToolBox T8068517 29 * @run main T8068517 30 */ 31 32import com.sun.tools.javac.util.Assert; 33import java.util.Arrays; 34import javax.tools.JavaFileManager; 35import javax.tools.StandardLocation; 36import javax.tools.ToolProvider; 37 38public class T8068517 { 39 40 public static void main(String[] args) throws Exception { 41 new T8068517().run(); 42 } 43 44 void run() throws Exception { 45 runTest("class A {\n" + 46 " enum AInner implements Runnable {\n" + 47 " A {\n" + 48 " public void run() {}\n" + 49 " };\n" + 50 " }\n" + 51 "}\n", 52 "class B {\n" + 53 " A.AInner a;\n" + 54 "}"); 55 runTest("class A {\n" + 56 " enum AInner implements Runnable {\n" + 57 " A {\n" + 58 " public void run() {}\n" + 59 " };\n" + 60 " }\n" + 61 " AInner aInner;\n" + 62 "}\n", 63 "class B {\n" + 64 " void test(A a) {;\n" + 65 " switch (a.aInner) {\n" + 66 " case A: break;\n" + 67 " }\n" + 68 " };\n" + 69 "}"); 70 runTest("class A {\n" + 71 " enum AInner implements Runnable {\n" + 72 " A {\n" + 73 " public void run() {}\n" + 74 " };\n" + 75 " }\n" + 76 " AInner aInner;\n" + 77 "}\n", 78 "class B {\n" + 79 " void test(A a) {;\n" + 80 " System.err.println(a.aInner.toString());\n" + 81 " };\n" + 82 "}"); 83 runTest("class A {\n" + 84 " enum AInner implements Runnable {\n" + 85 " A {\n" + 86 " public void run() {}\n" + 87 " };\n" + 88 " }\n" + 89 " AInner aInner() {\n" + 90 " return null;\n" + 91 " }\n" + 92 "}\n", 93 "class B {\n" + 94 " void test(A a) {;\n" + 95 " System.err.println(a.aInner().toString());\n" + 96 " };\n" + 97 "}"); 98 } 99 100 void runTest(String aJava, String bJava) throws Exception { 101 try (JavaFileManager fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) { 102 ToolBox tb = new ToolBox(); 103 ToolBox.MemoryFileManager memoryFM1 = new ToolBox.MemoryFileManager(fm); 104 tb.new JavacTask().fileManager(memoryFM1) 105 .sources(aJava, bJava) 106 .run(); 107 ToolBox.MemoryFileManager memoryFM2 = new ToolBox.MemoryFileManager(fm); 108 tb.new JavacTask().fileManager(memoryFM2) 109 .sources(bJava, aJava) 110 .run(); 111 112 Assert.check(Arrays.equals(memoryFM1.getFileBytes(StandardLocation.CLASS_OUTPUT, "B"), 113 memoryFM2.getFileBytes(StandardLocation.CLASS_OUTPUT, "B"))); 114 } 115 } 116} 117