jaroslav@1646
|
1 |
/*
|
jaroslav@1646
|
2 |
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@1646
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@1646
|
4 |
*
|
jaroslav@1646
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@1646
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@1646
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@1646
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@1646
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@1646
|
10 |
*
|
jaroslav@1646
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@1646
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@1646
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@1646
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@1646
|
15 |
* accompanied this code).
|
jaroslav@1646
|
16 |
*
|
jaroslav@1646
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@1646
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@1646
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@1646
|
20 |
*
|
jaroslav@1646
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@1646
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@1646
|
23 |
* questions.
|
jaroslav@1646
|
24 |
*/
|
jaroslav@1646
|
25 |
|
jaroslav@1646
|
26 |
package java.lang.invoke;
|
jaroslav@1646
|
27 |
|
jaroslav@1646
|
28 |
import static java.lang.invoke.LambdaForm.*;
|
jaroslav@1646
|
29 |
import static java.lang.invoke.MethodHandleNatives.Constants.*;
|
jaroslav@1646
|
30 |
import java.util.logging.Level;
|
jaroslav@1646
|
31 |
import java.util.logging.Logger;
|
jaroslav@1646
|
32 |
|
jaroslav@1646
|
33 |
/**
|
jaroslav@1646
|
34 |
* A method handle whose behavior is determined only by its LambdaForm.
|
jaroslav@1646
|
35 |
* @author jrose
|
jaroslav@1646
|
36 |
*/
|
jaroslav@1646
|
37 |
final class SimpleMethodHandle extends MethodHandle {
|
jaroslav@1646
|
38 |
private SimpleMethodHandle(MethodType type, LambdaForm form) {
|
jaroslav@1646
|
39 |
super(type, form);
|
jaroslav@1646
|
40 |
}
|
jaroslav@1646
|
41 |
|
jaroslav@1646
|
42 |
/*non-public*/ static SimpleMethodHandle make(MethodType type, LambdaForm form) {
|
jaroslav@1646
|
43 |
return new SimpleMethodHandle(type, form);
|
jaroslav@1646
|
44 |
}
|
jaroslav@1646
|
45 |
|
jaroslav@1646
|
46 |
@Override
|
jaroslav@1646
|
47 |
MethodHandle bindArgument(int pos, char basicType, Object value) {
|
jaroslav@1646
|
48 |
MethodType type2 = type().dropParameterTypes(pos, pos+1);
|
jaroslav@1646
|
49 |
LambdaForm form2 = internalForm().bind(1+pos, BoundMethodHandle.SpeciesData.EMPTY);
|
jaroslav@1646
|
50 |
return BoundMethodHandle.bindSingle(type2, form2, basicType, value);
|
jaroslav@1646
|
51 |
}
|
jaroslav@1646
|
52 |
|
jaroslav@1646
|
53 |
@Override
|
jaroslav@1646
|
54 |
MethodHandle dropArguments(MethodType srcType, int pos, int drops) {
|
jaroslav@1646
|
55 |
LambdaForm newForm = internalForm().addArguments(pos, srcType.parameterList().subList(pos, pos+drops));
|
jaroslav@1646
|
56 |
return new SimpleMethodHandle(srcType, newForm);
|
jaroslav@1646
|
57 |
}
|
jaroslav@1646
|
58 |
|
jaroslav@1646
|
59 |
@Override
|
jaroslav@1646
|
60 |
MethodHandle permuteArguments(MethodType newType, int[] reorder) {
|
jaroslav@1646
|
61 |
LambdaForm form2 = internalForm().permuteArguments(1, reorder, basicTypes(newType.parameterList()));
|
jaroslav@1646
|
62 |
return new SimpleMethodHandle(newType, form2);
|
jaroslav@1646
|
63 |
}
|
jaroslav@1646
|
64 |
|
jaroslav@1646
|
65 |
@Override
|
jaroslav@1646
|
66 |
MethodHandle copyWith(MethodType mt, LambdaForm lf) {
|
jaroslav@1646
|
67 |
return new SimpleMethodHandle(mt, lf);
|
jaroslav@1646
|
68 |
}
|
jaroslav@1646
|
69 |
|
jaroslav@1646
|
70 |
}
|