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