1 /*
2 * Copyright (c) 2012, 2013, 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
191 if (!samBase.isInterface()) {
192 throw new LambdaConversionException(String.format(
193 "Functional interface %s is not an interface",
194 samBase.getName()));
195 }
196
197 for (Class<?> c : markerInterfaces) {
198 if (!c.isInterface()) {
199 throw new LambdaConversionException(String.format(
200 "Marker interface %s is not an interface",
201 c.getName()));
202 }
203 }
204 }
205
206 /**
207 * Build the CallSite.
208 *
209 * @return a CallSite, which, when invoked, will return an instance of the
210 * functional interface
211 * @throws ReflectiveOperationException
212 */
213 abstract CallSite buildCallSite()
214 throws LambdaConversionException;
215
216 /**
217 * Check the meta-factory arguments for errors
218 * @throws LambdaConversionException if there are improper conversions
219 */
220 void validateMetafactoryArgs() throws LambdaConversionException {
221 // Check arity: captured + SAM == impl
222 final int implArity = implMethodType.parameterCount();
223 final int capturedArity = invokedType.parameterCount();
224 final int samArity = samMethodType.parameterCount();
225 final int instantiatedArity = instantiatedMethodType.parameterCount();
226 if (implArity != capturedArity + samArity) {
227 throw new LambdaConversionException(
228 String.format("Incorrect number of parameters for %s method %s; %d captured parameters, %d functional interface method parameters, %d implementation parameters",
229 implIsInstanceMethod ? "instance" : "static", implInfo,
230 capturedArity, samArity, implArity));
231 }
|
1 /*
2 * Copyright (c) 2012, 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. 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
191 if (!samBase.isInterface()) {
192 throw new LambdaConversionException(String.format(
193 "Functional interface %s is not an interface",
194 samBase.getName()));
195 }
196
197 for (Class<?> c : markerInterfaces) {
198 if (!c.isInterface()) {
199 throw new LambdaConversionException(String.format(
200 "Marker interface %s is not an interface",
201 c.getName()));
202 }
203 }
204 }
205
206 /**
207 * Build the CallSite.
208 *
209 * @return a CallSite, which, when invoked, will return an instance of the
210 * functional interface
211 * @throws LambdaConversionException
212 */
213 abstract CallSite buildCallSite()
214 throws LambdaConversionException;
215
216 /**
217 * Check the meta-factory arguments for errors
218 * @throws LambdaConversionException if there are improper conversions
219 */
220 void validateMetafactoryArgs() throws LambdaConversionException {
221 // Check arity: captured + SAM == impl
222 final int implArity = implMethodType.parameterCount();
223 final int capturedArity = invokedType.parameterCount();
224 final int samArity = samMethodType.parameterCount();
225 final int instantiatedArity = instantiatedMethodType.parameterCount();
226 if (implArity != capturedArity + samArity) {
227 throw new LambdaConversionException(
228 String.format("Incorrect number of parameters for %s method %s; %d captured parameters, %d functional interface method parameters, %d implementation parameters",
229 implIsInstanceMethod ? "instance" : "static", implInfo,
230 capturedArity, samArity, implArity));
231 }
|