|
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 bridge method |
|
28 * generated for lambda expressions and method references. |
|
29 * @library /tools/lib /tools/javac/lib ../lib |
|
30 * @build TestBase TestResult InMemoryFileManager ToolBox |
|
31 * @build BridgeMethodsForLambdaTest SyntheticTestDriver ExpectedClass ExpectedClasses |
|
32 * @run main SyntheticTestDriver BridgeMethodsForLambdaTest 1 |
|
33 */ |
|
34 |
|
35 import java.util.Comparator; |
|
36 import java.util.stream.IntStream; |
|
37 |
|
38 /** |
|
39 * Synthetic members: |
|
40 * 1. inner class for Inner1. |
|
41 * 2. method for () -> {} in Inner1 |
|
42 * 3. method for () -> {} in Inner2 |
|
43 * 4. method references to private methods. |
|
44 * 5. method for super::function() |
|
45 * 6. method references to private static methods. |
|
46 * 7. access method for private method function(). |
|
47 * 8. access method for private static method staticFunction(). |
|
48 * 9. method reference to vararg method. |
|
49 * 10. method reference to array's method. |
|
50 * 11. constructors for Inner1 and Inner2. |
|
51 */ |
|
52 @ExpectedClass(className = "BridgeMethodsForLambdaTest", |
|
53 expectedMethods = {"<init>()", "<clinit>()", "function(java.lang.Integer[])"}, |
|
54 expectedNumberOfSyntheticMethods = 6) |
|
55 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner1", |
|
56 expectedMethods = {"<init>(BridgeMethodsForLambdaTest)", "function()", "run()"}, |
|
57 expectedFields = "lambda1", |
|
58 expectedNumberOfSyntheticMethods = 4, |
|
59 expectedNumberOfSyntheticFields = 1) |
|
60 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner2", |
|
61 expectedMethods = {"<init>()", "staticFunction()"}, |
|
62 expectedFields = "lambda1", |
|
63 expectedNumberOfSyntheticMethods = 3) |
|
64 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner3", |
|
65 expectedMethods = {"<init>(BridgeMethodsForLambdaTest)", "function()"}, |
|
66 expectedNumberOfSyntheticMethods = 1, |
|
67 expectedNumberOfSyntheticFields = 1) |
|
68 @ExpectedClass(className = "BridgeMethodsForLambdaTest$Inner4", |
|
69 expectedMethods = {"<init>(BridgeMethodsForLambdaTest)", "function()"}, |
|
70 expectedNumberOfSyntheticMethods = 1, |
|
71 expectedNumberOfSyntheticFields = 1) |
|
72 public class BridgeMethodsForLambdaTest { |
|
73 |
|
74 private class Inner1 implements Runnable { |
|
75 private Inner1() { |
|
76 } |
|
77 private Runnable lambda1 = () -> { |
|
78 }; |
|
79 private void function() { |
|
80 } |
|
81 @Override |
|
82 public void run() { |
|
83 } |
|
84 } |
|
85 |
|
86 private static class Inner2 { |
|
87 private Runnable lambda1 = () -> { |
|
88 }; |
|
89 private static void staticFunction() { |
|
90 } |
|
91 } |
|
92 |
|
93 private class Inner3 { |
|
94 public void function() { |
|
95 } |
|
96 } |
|
97 |
|
98 private class Inner4 extends Inner3 { |
|
99 @Override |
|
100 public void function() { |
|
101 Runnable r = super::function; |
|
102 } |
|
103 } |
|
104 |
|
105 private static int function(Integer...vararg) { |
|
106 return 0; |
|
107 } |
|
108 |
|
109 { |
|
110 Inner1 inner = new Inner1(); |
|
111 Runnable l1 = inner::function; |
|
112 Runnable l2 = Inner1::new; |
|
113 inner.lambda1 = inner::function; |
|
114 Comparator<Integer> c = BridgeMethodsForLambdaTest::function; |
|
115 IntStream.of(2).mapToObj(int[]::new); |
|
116 } |
|
117 |
|
118 static { |
|
119 Inner2 inner = new Inner2(); |
|
120 Runnable l1 = Inner2::staticFunction; |
|
121 } |
|
122 } |