AccessToPrivateSiblingsTest.java revision 3294:9adfb22ff08f
1202097Smarcel/* 2202097Smarcel * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3202097Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4202097Smarcel * 5202097Smarcel * This code is free software; you can redistribute it and/or modify it 6202097Smarcel * under the terms of the GNU General Public License version 2 only, as 7202097Smarcel * published by the Free Software Foundation. 8202097Smarcel * 9202097Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT 10202097Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11202097Smarcel * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12202097Smarcel * version 2 for more details (a copy is included in the LICENSE file that 13202097Smarcel * accompanied this code). 14202097Smarcel * 15202097Smarcel * You should have received a copy of the GNU General Public License version 16202097Smarcel * 2 along with this work; if not, write to the Free Software Foundation, 17202097Smarcel * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18202097Smarcel * 19202097Smarcel * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20202097Smarcel * or visit www.oracle.com if you need additional information or have any 21202097Smarcel * questions. 22202097Smarcel */ 23202097Smarcel 24202097Smarcel/* 25202097Smarcel * @test 26202097Smarcel * @bug 8044537 27202097Smarcel * @summary Checking ACC_SYNTHETIC flag is generated for access method 28202097Smarcel * generated to access to private methods and fields. 29202097Smarcel * @modules jdk.compiler/com.sun.tools.javac.api 30202097Smarcel * jdk.compiler/com.sun.tools.javac.main 31202097Smarcel * jdk.jdeps/com.sun.tools.classfile 32202273Smarcel * jdk.jdeps/com.sun.tools.javap 33202273Smarcel * @library /tools/lib /tools/javac/lib ../lib 34207329Sattilio * @build TestBase TestResult InMemoryFileManager ToolBox 35207329Sattilio * @build AccessToPrivateSiblingsTest SyntheticTestDriver ExpectedClass ExpectedClasses 36207329Sattilio * @run main SyntheticTestDriver AccessToPrivateSiblingsTest 1 37202097Smarcel */ 38207329Sattilio 39207329Sattilio/** 40207329Sattilio * Access from sibling classes to sibling classes. 41202097Smarcel * Synthetic members: 42202273Smarcel * 1. inner classes for Inner*. 43202273Smarcel * 2. getter/setter for private field var. 44202273Smarcel * 3. access method for private method function(). 45202273Smarcel * 4. getter/setter for private field staticVar. 46202273Smarcel * 5. access method for private method staticFunction(). 47202273Smarcel * 6. field this in Inner1. 48202273Smarcel * 7. constructor for Inner*. 49202273Smarcel */ 50202273Smarcel@ExpectedClass(className = "AccessToPrivateSiblingsTest", expectedMethods = "<init>()") 51202273Smarcel@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner1", 52202273Smarcel expectedMethods = {"function()", "<init>(AccessToPrivateSiblingsTest)"}, 53202273Smarcel expectedFields = "var", 54202273Smarcel expectedNumberOfSyntheticMethods = 4, 55202097Smarcel expectedNumberOfSyntheticFields = 1) 56207329Sattilio@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner2", 57207329Sattilio expectedMethods = "<init>(AccessToPrivateSiblingsTest)", 58207329Sattilio expectedNumberOfSyntheticFields = 1) 59207329Sattilio@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner3", 60207329Sattilio expectedMethods = {"<init>()", "function()", "staticFunction()", "<clinit>()"}, 61207329Sattilio expectedFields = {"var", "staticVar"}, 62202097Smarcel expectedNumberOfSyntheticMethods = 4) 63207329Sattilio@ExpectedClass(className = "AccessToPrivateSiblingsTest$Inner4", 64207329Sattilio expectedMethods = {"<init>()", "function()", "staticFunction()"}, 65207329Sattilio expectedFields = {"var", "staticVar"}, 66202097Smarcel expectedNumberOfSyntheticMethods = 4) 67207329Sattiliopublic class AccessToPrivateSiblingsTest { 68202097Smarcel 69 private class Inner1 { 70 private Inner1() {} 71 private int var; 72 private void function() {} 73 74 { 75 Inner3 inner = new Inner3(); 76 inner.var = 0; 77 int i = inner.var; 78 inner.function(); 79 } 80 } 81 82 private class Inner2 { 83 { 84 Inner1 inner = new Inner1(); 85 inner.var = 0; 86 int i = inner.var; 87 inner.function(); 88 } 89 } 90 91 private static class Inner3 { 92 private Inner3() {} 93 private int var; 94 private static int staticVar; 95 private void function() {} 96 private static void staticFunction() {} 97 98 static { 99 Inner4 inner = new Inner4(); 100 inner.var = 0; 101 int i = inner.var; 102 inner.function(); 103 } 104 } 105 106 private static class Inner4 { 107 private Inner4() {} 108 private int var; 109 private static int staticVar; 110 private void function() {} 111 private static void staticFunction() {} 112 } 113} 114