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