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