AccessToPrivateInnerClassMembersTest.java revision 3294:9adfb22ff08f
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/*
25 * @test
26 * @bug 8044537
27 * @summary Checking ACC_SYNTHETIC flag is generated for access method
28 *          generated to access to private methods and fields.
29 * @modules jdk.compiler/com.sun.tools.javac.api
30 *          jdk.compiler/com.sun.tools.javac.file
31 *          jdk.compiler/com.sun.tools.javac.main
32 *          jdk.jdeps/com.sun.tools.classfile
33 *          jdk.jdeps/com.sun.tools.javap
34 * @library /tools/lib /tools/javac/lib ../lib
35 * @build TestBase TestResult InMemoryFileManager ToolBox
36 * @build AccessToPrivateInnerClassMembersTest SyntheticTestDriver ExpectedClass ExpectedClasses
37 * @run main SyntheticTestDriver AccessToPrivateInnerClassMembersTest 1
38 */
39
40/**
41 * Access from top level class to inner classes.
42 * Synthetic members:
43 * 1. inner classes for Inner*.
44 * 2. getter/setter for private field var.
45 * 3. access method for private method function().
46 * 4. getter/setter for private field staticVar.
47 * 5. access method for private method staticFunction().
48 * 6. field this in Inner1.
49 * 7. constructor for Inner*.
50 */
51@ExpectedClass(className = "AccessToPrivateInnerClassMembersTest",
52        expectedMethods = {"<init>()", "<clinit>()"})
53@ExpectedClass(className = "AccessToPrivateInnerClassMembersTest$Inner1",
54        expectedMethods = {"<init>(AccessToPrivateInnerClassMembersTest)", "function()"},
55        expectedFields = "var",
56        expectedNumberOfSyntheticMethods = 4,
57        expectedNumberOfSyntheticFields = 1)
58@ExpectedClass(className = "AccessToPrivateInnerClassMembersTest$Inner2",
59        expectedMethods = {"function()", "staticFunction()", "<init>()"},
60        expectedFields = {"staticVar", "var"},
61        expectedNumberOfSyntheticMethods = 7)
62public class AccessToPrivateInnerClassMembersTest {
63
64    private class Inner1 {
65        private Inner1() {}
66        private int var;
67        private void function() {}
68    }
69
70    {
71        Inner1 inner = new Inner1();
72        inner.var = 0;
73        int i = inner.var;
74        inner.function();
75    }
76
77    private static class Inner2 {
78        private Inner2() {}
79        private int var;
80        private static int staticVar;
81        private void function() {}
82        private static void staticFunction() {}
83    }
84
85    {
86        Inner2 inner = new Inner2();
87        inner.var = 0;
88        int i = inner.var;
89        inner.function();
90    }
91
92    static {
93        Inner2.staticFunction();
94        Inner2.staticVar = 0;
95        int i = Inner2.staticVar;
96    }
97}
98