< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java

Print this page

   1 /*
   2  * Copyright (c) 2010, 2025, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

 961                 staticArgs = staticArgs.append(LoadableConstant.Int(bridges.length() - 1));
 962                 for (Symbol s : bridges) {
 963                     Type s_erasure = s.erasure(types);
 964                     if (!types.isSameType(s_erasure, samSym.erasure(types))) {
 965                         staticArgs = staticArgs.append(((MethodType)s.erasure(types)));
 966                     }
 967                 }
 968             }
 969             if (isSerializable) {
 970                 int prevPos = make.pos;
 971                 try {
 972                     make.at(kInfo.clazz);
 973                     addDeserializationCase(refSym, tree.type, samSym, samType,
 974                             tree, staticArgs, indyType);
 975                 } finally {
 976                     make.at(prevPos);
 977                 }
 978             }
 979         }
 980 
 981         return makeIndyCall(tree, syms.lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, samSym.name);






 982     }
 983 
 984     /**
 985      * Generate an indy method call with given name, type and static bootstrap
 986      * arguments types
 987      */
 988     private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
 989                                       List<LoadableConstant> staticArgs, MethodType indyType, List<JCExpression> indyArgs,
 990                                       Name methName) {
 991         int prevPos = make.pos;
 992         try {
 993             make.at(pos);
 994             List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
 995                     syms.stringType,
 996                     syms.methodTypeType).appendList(staticArgs.map(types::constantType));
 997 
 998             MethodSymbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
 999                     bsmName, bsm_staticArgs, List.nil());
1000 
1001             DynamicMethodSymbol dynSym =

   1 /*
   2  * Copyright (c) 2010, 2026, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

 961                 staticArgs = staticArgs.append(LoadableConstant.Int(bridges.length() - 1));
 962                 for (Symbol s : bridges) {
 963                     Type s_erasure = s.erasure(types);
 964                     if (!types.isSameType(s_erasure, samSym.erasure(types))) {
 965                         staticArgs = staticArgs.append(((MethodType)s.erasure(types)));
 966                     }
 967                 }
 968             }
 969             if (isSerializable) {
 970                 int prevPos = make.pos;
 971                 try {
 972                     make.at(kInfo.clazz);
 973                     addDeserializationCase(refSym, tree.type, samSym, samType,
 974                             tree, staticArgs, indyType);
 975                 } finally {
 976                     make.at(prevPos);
 977                 }
 978             }
 979         }
 980 
 981         Name lambdaName = samSym.name;
 982         if (tree.codeReflectionInfo != null) {
 983             tree.codeReflectionInfo.registerImplementation().accept(refSym.name);
 984         }
 985         Type lambdaMetafactory = tree.codeReflectionInfo != null ?
 986                 tree.codeReflectionInfo.reflectableLambdaMetafactory() : syms.lambdaMetafactory;
 987         return makeIndyCall(tree, lambdaMetafactory, metafactoryName, staticArgs, indyType, indy_args, lambdaName);
 988     }
 989 
 990     /**
 991      * Generate an indy method call with given name, type and static bootstrap
 992      * arguments types
 993      */
 994     private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
 995                                       List<LoadableConstant> staticArgs, MethodType indyType, List<JCExpression> indyArgs,
 996                                       Name methName) {
 997         int prevPos = make.pos;
 998         try {
 999             make.at(pos);
1000             List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
1001                     syms.stringType,
1002                     syms.methodTypeType).appendList(staticArgs.map(types::constantType));
1003 
1004             MethodSymbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
1005                     bsmName, bsm_staticArgs, List.nil());
1006 
1007             DynamicMethodSymbol dynSym =
< prev index next >