author | attila |
Mon, 12 Oct 2015 14:52:47 +0200 | |
changeset 33007 | 03119bfefbbf |
parent 25865 | d38d876f1654 |
child 33333 | 0bad500ce4e0 |
permissions | -rw-r--r-- |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
1 |
/* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
4 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
10 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
15 |
* accompanied this code). |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
16 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
20 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
23 |
* questions. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
24 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
25 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
26 |
/* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
27 |
* This file is available under and governed by the GNU General Public |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
28 |
* License version 2 only, as published by the Free Software Foundation. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
29 |
* However, the following notice accompanied the original version of this |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
30 |
* file, and Oracle licenses the original version of this file under the BSD |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
31 |
* license: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
32 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
33 |
/* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
34 |
Copyright 2009-2013 Attila Szegedi |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
35 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
36 |
Licensed under both the Apache License, Version 2.0 (the "Apache License") |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
37 |
and the BSD License (the "BSD License"), with licensee being free to |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
38 |
choose either of the two at their discretion. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
39 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
40 |
You may not use this file except in compliance with either the Apache |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
41 |
License or the BSD License. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
42 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
43 |
If you choose to use this file in compliance with the Apache License, the |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
44 |
following notice applies to you: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
45 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
46 |
You may obtain a copy of the Apache License at |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
47 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
48 |
http://www.apache.org/licenses/LICENSE-2.0 |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
49 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
50 |
Unless required by applicable law or agreed to in writing, software |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
51 |
distributed under the License is distributed on an "AS IS" BASIS, |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
52 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
53 |
implied. See the License for the specific language governing |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
54 |
permissions and limitations under the License. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
55 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
56 |
If you choose to use this file in compliance with the BSD License, the |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
57 |
following notice applies to you: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
58 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
59 |
Redistribution and use in source and binary forms, with or without |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
60 |
modification, are permitted provided that the following conditions are |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
61 |
met: |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
62 |
* Redistributions of source code must retain the above copyright |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
63 |
notice, this list of conditions and the following disclaimer. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
64 |
* Redistributions in binary form must reproduce the above copyright |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
65 |
notice, this list of conditions and the following disclaimer in the |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
66 |
documentation and/or other materials provided with the distribution. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
67 |
* Neither the name of the copyright holder nor the names of |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
68 |
contributors may be used to endorse or promote products derived from |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
69 |
this software without specific prior written permission. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
70 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
71 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
72 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
73 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
74 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
75 |
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
76 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
77 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
78 |
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
79 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
80 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
81 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
82 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
83 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
84 |
package jdk.internal.dynalink.support; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
85 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
86 |
import java.lang.invoke.MethodHandle; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
87 |
import java.lang.invoke.MethodHandles; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
88 |
import java.lang.invoke.MethodType; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
89 |
import java.lang.reflect.Constructor; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
90 |
import java.lang.reflect.Field; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
91 |
import java.lang.reflect.Method; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
92 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
93 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
94 |
* A wrapper around MethodHandles.Lookup that masks checked exceptions in those cases when you're looking up methods |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
95 |
* within your own codebase (therefore it is an error if they are not present). |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
96 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
97 |
public class Lookup { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
98 |
private final MethodHandles.Lookup lookup; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
99 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
100 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
101 |
* Creates a new instance, bound to an instance of {@link java.lang.invoke.MethodHandles.Lookup}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
102 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
103 |
* @param lookup the {@link java.lang.invoke.MethodHandles.Lookup} it delegates to. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
104 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
105 |
public Lookup(final MethodHandles.Lookup lookup) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
106 |
this.lookup = lookup; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
107 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
108 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
109 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
110 |
* A canonical Lookup object that wraps {@link MethodHandles#publicLookup()}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
111 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
112 |
public static final Lookup PUBLIC = new Lookup(MethodHandles.publicLookup()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
113 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
114 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
115 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, converting any encountered |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
116 |
* {@link IllegalAccessException} into an {@link IllegalAccessError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
117 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
118 |
* @param m the method to unreflect |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
119 |
* @return the unreflected method handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
120 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
121 |
public MethodHandle unreflect(final Method m) { |
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
122 |
return unreflect(lookup, m); |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
123 |
} |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
124 |
|
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
125 |
/** |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
126 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, converting any encountered |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
127 |
* {@link IllegalAccessException} into an {@link IllegalAccessError}. |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
128 |
* |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
129 |
* @param lookup the lookup used to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
130 |
* @param m the method to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
131 |
* @return the unreflected method handle. |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
132 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
133 |
public static MethodHandle unreflect(final MethodHandles.Lookup lookup, final Method m) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
134 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
135 |
return lookup.unreflect(m); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
136 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
137 |
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
138 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
139 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
140 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
141 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
142 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
143 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
144 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)}, converting any encountered |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
145 |
* {@link IllegalAccessException} into an {@link IllegalAccessError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
146 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
147 |
* @param f the field for which a getter is unreflected |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
148 |
* @return the unreflected field getter handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
149 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
150 |
public MethodHandle unreflectGetter(final Field f) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
151 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
152 |
return lookup.unreflectGetter(f); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
153 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
154 |
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect getter for field " + f); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
155 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
156 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
157 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
158 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
159 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
160 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
161 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)}, converting any |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
162 |
* encountered {@link IllegalAccessException} into an {@link IllegalAccessError} and {@link NoSuchFieldException} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
163 |
* into a {@link NoSuchFieldError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
164 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
165 |
* @param refc the class declaring the field |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
166 |
* @param name the name of the field |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
167 |
* @param type the type of the field |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
168 |
* @return the unreflected field getter handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
169 |
* @throws IllegalAccessError if the field is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
170 |
* @throws NoSuchFieldError if the field does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
171 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
172 |
public MethodHandle findGetter(final Class<?>refc, final String name, final Class<?> type) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
173 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
174 |
return lookup.findGetter(refc, name, type); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
175 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
176 |
final IllegalAccessError ee = new IllegalAccessError("Failed to access getter for field " + refc.getName() + |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
177 |
"." + name + " of type " + type.getName()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
178 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
179 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
180 |
} catch(final NoSuchFieldException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
181 |
final NoSuchFieldError ee = new NoSuchFieldError("Failed to find getter for field " + refc.getName() + |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
182 |
"." + name + " of type " + type.getName()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
183 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
184 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
185 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
186 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
187 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
188 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
189 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)}, converting any encountered |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
190 |
* {@link IllegalAccessException} into an {@link IllegalAccessError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
191 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
192 |
* @param f the field for which a setter is unreflected |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
193 |
* @return the unreflected field setter handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
194 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
195 |
public MethodHandle unreflectSetter(final Field f) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
196 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
197 |
return lookup.unreflectSetter(f); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
198 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
199 |
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect setter for field " + f); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
200 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
201 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
202 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
203 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
204 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
205 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
206 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, converting any |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
207 |
* encountered {@link IllegalAccessException} into an {@link IllegalAccessError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
208 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
209 |
* @param c the constructor to unreflect |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
210 |
* @return the unreflected constructor handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
211 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
212 |
public MethodHandle unreflectConstructor(final Constructor<?> c) { |
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
213 |
return unreflectConstructor(lookup, c); |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
214 |
} |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
215 |
|
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
216 |
/** |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
217 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, converting any |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
218 |
* encountered {@link IllegalAccessException} into an {@link IllegalAccessError}. |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
219 |
* |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
220 |
* @param lookup the lookup used to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
221 |
* @param c the constructor to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
222 |
* @return the unreflected constructor handle. |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
223 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
224 |
public static MethodHandle unreflectConstructor(final MethodHandles.Lookup lookup, final Constructor<?> c) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
225 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
226 |
return lookup.unreflectConstructor(c); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
227 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
228 |
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
229 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
230 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
231 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
232 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
233 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
234 |
/** |
19455 | 235 |
* Performs a findSpecial on the underlying lookup. Converts any encountered {@link IllegalAccessException} into an |
236 |
* {@link IllegalAccessError} and a {@link NoSuchMethodException} into a {@link NoSuchMethodError}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
237 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
238 |
* @param declaringClass class declaring the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
239 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
240 |
* @param type the type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
241 |
* @return a method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
242 |
* @throws IllegalAccessError if the method is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
243 |
* @throws NoSuchMethodError if the method does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
244 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
245 |
public MethodHandle findSpecial(final Class<?> declaringClass, final String name, final MethodType type) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
246 |
try { |
16245
6a1c6c8bc113
8008371: Fix Dynalink compiler warnings and whitespace
attila
parents:
16234
diff
changeset
|
247 |
return lookup.findSpecial(declaringClass, name, type, declaringClass); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
248 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
249 |
final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
250 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
251 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
252 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
253 |
} catch(final NoSuchMethodException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
254 |
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
255 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
256 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
257 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
258 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
259 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
260 |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
261 |
private static String methodDescription(final Class<?> declaringClass, final String name, final MethodType type) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
262 |
return declaringClass.getName() + "#" + name + type; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
263 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
264 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
265 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
266 |
* Performs a findStatic on the underlying lookup. Converts any encountered {@link IllegalAccessException} into an |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
267 |
* {@link IllegalAccessError} and a {@link NoSuchMethodException} into a {@link NoSuchMethodError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
268 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
269 |
* @param declaringClass class declaring the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
270 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
271 |
* @param type the type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
272 |
* @return a method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
273 |
* @throws IllegalAccessError if the method is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
274 |
* @throws NoSuchMethodError if the method does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
275 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
276 |
public MethodHandle findStatic(final Class<?> declaringClass, final String name, final MethodType type) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
277 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
278 |
return lookup.findStatic(declaringClass, name, type); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
279 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
280 |
final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
281 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
282 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
283 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
284 |
} catch(final NoSuchMethodException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
285 |
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
286 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
287 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
288 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
289 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
290 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
291 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
292 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
293 |
* Performs a findVirtual on the underlying lookup. Converts any encountered {@link IllegalAccessException} into an |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
294 |
* {@link IllegalAccessError} and a {@link NoSuchMethodException} into a {@link NoSuchMethodError}. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
295 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
296 |
* @param declaringClass class declaring the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
297 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
298 |
* @param type the type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
299 |
* @return a method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
300 |
* @throws IllegalAccessError if the method is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
301 |
* @throws NoSuchMethodError if the method does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
302 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
303 |
public MethodHandle findVirtual(final Class<?> declaringClass, final String name, final MethodType type) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
304 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
305 |
return lookup.findVirtual(declaringClass, name, type); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
306 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
307 |
final IllegalAccessError ee = new IllegalAccessError("Failed to access virtual method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
308 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
309 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
310 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
311 |
} catch(final NoSuchMethodException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
312 |
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find virtual method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
313 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
314 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
315 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
316 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
317 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
318 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
319 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
320 |
* Given a lookup, finds using {@link #findSpecial(Class, String, MethodType)} a method on that lookup's class. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
321 |
* Useful in classes' code for convenient linking to their own privates. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
322 |
* @param lookup the lookup for the class |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
323 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
324 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
325 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
326 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
327 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
328 |
public static MethodHandle findOwnSpecial(final MethodHandles.Lookup lookup, final String name, final Class<?> rtype, final Class<?>... ptypes) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
329 |
return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
330 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
331 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
332 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
333 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
334 |
* Finds using {@link #findSpecial(Class, String, MethodType)} a method on that lookup's class. Useful in classes' |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
335 |
* code for convenient linking to their own privates. It's easier to use than {@code findSpecial} in that you can |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
336 |
* just list the parameter types, and don't have to specify lookup class. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
337 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
338 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
339 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
340 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
341 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
342 |
public MethodHandle findOwnSpecial(final String name, final Class<?> rtype, final Class<?>... ptypes) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
343 |
return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
344 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
345 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
346 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
347 |
* Given a lookup, finds using {@link #findStatic(Class, String, MethodType)} a method on that lookup's class. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
348 |
* Useful in classes' code for convenient linking to their own privates. It's easier to use than {@code findStatic} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
349 |
* in that you can just list the parameter types, and don't have to specify lookup class. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
350 |
* @param lookup the lookup for the class |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
351 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
352 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
353 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
354 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
355 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
356 |
public static MethodHandle findOwnStatic(final MethodHandles.Lookup lookup, final String name, final Class<?> rtype, final Class<?>... ptypes) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
357 |
return new Lookup(lookup).findOwnStatic(name, rtype, ptypes); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
358 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
359 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
360 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
361 |
* Finds using {@link #findStatic(Class, String, MethodType)} a method on that lookup's class. Useful in classes' |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
362 |
* code for convenient linking to their own privates. It's easier to use than {@code findStatic} in that you can |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
363 |
* just list the parameter types, and don't have to specify lookup class. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
364 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
365 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
366 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
367 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
368 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
369 |
public MethodHandle findOwnStatic(final String name, final Class<?> rtype, final Class<?>... ptypes) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
370 |
return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
371 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
372 |
} |