author | jlaskey |
Thu, 21 Jun 2018 08:58:59 -0300 | |
changeset 50695 | 36ca515343e0 |
parent 47216 | 71c04702a3d5 |
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 |
|
50695 | 36 |
Redistribution and use in source and binary forms, with or without |
37 |
modification, are permitted provided that the following conditions are |
|
38 |
met: |
|
39 |
* Redistributions of source code must retain the above copyright |
|
40 |
notice, this list of conditions and the following disclaimer. |
|
41 |
* Redistributions in binary form must reproduce the above copyright |
|
42 |
notice, this list of conditions and the following disclaimer in the |
|
43 |
documentation and/or other materials provided with the distribution. |
|
44 |
* Neither the name of the copyright holder nor the names of |
|
45 |
contributors may be used to endorse or promote products derived from |
|
46 |
this software without specific prior written permission. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
47 |
|
50695 | 48 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
49 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
50 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
51 |
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER |
|
52 |
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
53 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
54 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
55 |
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
56 |
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
57 |
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
58 |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
59 |
*/ |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
60 |
|
34447
ec4c069f9436
8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents:
33339
diff
changeset
|
61 |
package jdk.dynalink.linker.support; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
62 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
63 |
import java.lang.invoke.MethodHandle; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
64 |
import java.lang.invoke.MethodHandles; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
65 |
import java.lang.invoke.MethodType; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
66 |
import java.lang.reflect.Constructor; |
36517 | 67 |
import java.lang.reflect.Executable; |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
68 |
import java.lang.reflect.Field; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
69 |
import java.lang.reflect.Method; |
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 |
/** |
33333 | 72 |
* A wrapper around {@link java.lang.invoke.MethodHandles.Lookup} that masks |
73 |
* checked exceptions. It is useful in those cases when you're looking up |
|
74 |
* methods within your own codebase (therefore it is an error if they are not |
|
75 |
* present). |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
76 |
*/ |
33339 | 77 |
public final class Lookup { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
78 |
private final MethodHandles.Lookup lookup; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
79 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
80 |
/** |
33333 | 81 |
* Creates a new instance, bound to an instance of |
82 |
* {@link java.lang.invoke.MethodHandles.Lookup}. |
|
16234
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 |
* @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
|
85 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
86 |
public Lookup(final MethodHandles.Lookup lookup) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
87 |
this.lookup = lookup; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
88 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
89 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
90 |
/** |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
91 |
* A canonical Lookup object that wraps {@link MethodHandles#publicLookup()}. |
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 |
public static final Lookup PUBLIC = new Lookup(MethodHandles.publicLookup()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
94 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
95 |
/** |
33333 | 96 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, |
97 |
* converting any encountered {@link IllegalAccessException} into an |
|
98 |
* {@link IllegalAccessError}. |
|
16234
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 |
* @param m the method to unreflect |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
101 |
* @return the unreflected method handle. |
33333 | 102 |
* @throws IllegalAccessError if the method is inaccessible. |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
103 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
104 |
public MethodHandle unreflect(final Method m) { |
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
105 |
return unreflect(lookup, m); |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
106 |
} |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
107 |
|
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
108 |
/** |
33333 | 109 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, |
110 |
* converting any encountered {@link IllegalAccessException} into an |
|
111 |
* {@link IllegalAccessError}. |
|
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
112 |
* |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
113 |
* @param lookup the lookup used to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
114 |
* @param m the method to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
115 |
* @return the unreflected method handle. |
33333 | 116 |
* @throws IllegalAccessError if the method is inaccessible. |
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
117 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
118 |
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
|
119 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
120 |
return lookup.unreflect(m); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
121 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
122 |
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
123 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
124 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
125 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
126 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
127 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
128 |
/** |
33333 | 129 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)}, |
130 |
* converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
131 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
132 |
* @param f the field for which a getter is unreflected |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
133 |
* @return the unreflected field getter handle. |
33333 | 134 |
* @throws IllegalAccessError if the getter is inaccessible. |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
135 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
136 |
public MethodHandle unreflectGetter(final Field f) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
137 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
138 |
return lookup.unreflectGetter(f); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
139 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
140 |
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
|
141 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
142 |
throw ee; |
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 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
145 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
146 |
/** |
33333 | 147 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)}, |
148 |
* converting any encountered {@link IllegalAccessException} into an |
|
149 |
* {@link IllegalAccessError} and {@link NoSuchFieldException} into a |
|
150 |
* {@link NoSuchFieldError}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
151 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
152 |
* @param refc the class declaring the field |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
153 |
* @param name the name of the field |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
154 |
* @param type the type of the field |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
155 |
* @return the unreflected field getter handle. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
156 |
* @throws IllegalAccessError if the field is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
157 |
* @throws NoSuchFieldError if the field does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
158 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
159 |
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
|
160 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
161 |
return lookup.findGetter(refc, name, type); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
162 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
163 |
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
|
164 |
"." + name + " of type " + type.getName()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
165 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
166 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
167 |
} catch(final NoSuchFieldException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
168 |
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
|
169 |
"." + name + " of type " + type.getName()); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
170 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
171 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
172 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
173 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
174 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
175 |
/** |
33333 | 176 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)}, |
177 |
* converting any encountered {@link IllegalAccessException} into an |
|
178 |
* {@link IllegalAccessError}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
179 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
180 |
* @param f the field for which a setter is unreflected |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
181 |
* @return the unreflected field setter handle. |
33333 | 182 |
* @throws IllegalAccessError if the field is inaccessible. |
183 |
* @throws NoSuchFieldError if the field does not exist. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
184 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
185 |
public MethodHandle unreflectSetter(final Field f) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
186 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
187 |
return lookup.unreflectSetter(f); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
188 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
189 |
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
|
190 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
191 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
192 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
193 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
194 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
195 |
/** |
33333 | 196 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, |
197 |
* converting any encountered {@link IllegalAccessException} into an |
|
198 |
* {@link IllegalAccessError}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
199 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
200 |
* @param c the constructor to unreflect |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
201 |
* @return the unreflected constructor handle. |
33333 | 202 |
* @throws IllegalAccessError if the constructor is inaccessible. |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
203 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
204 |
public MethodHandle unreflectConstructor(final Constructor<?> c) { |
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
205 |
return unreflectConstructor(lookup, c); |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
206 |
} |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
207 |
|
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
208 |
/** |
33333 | 209 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)}, |
210 |
* converting any encountered {@link IllegalAccessException} into an |
|
211 |
* {@link IllegalAccessError}. |
|
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
212 |
* |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
213 |
* @param lookup the lookup used to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
214 |
* @param c the constructor to unreflect |
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
215 |
* @return the unreflected constructor handle. |
33333 | 216 |
* @throws IllegalAccessError if the constructor is inaccessible. |
18841
9bbc4b8832b2
8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents:
16245
diff
changeset
|
217 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
218 |
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
|
219 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
220 |
return lookup.unreflectConstructor(c); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
221 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
222 |
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
223 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
224 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
225 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
226 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
227 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
228 |
/** |
33333 | 229 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#findSpecial(Class, String, MethodType, Class)} |
230 |
* on the underlying lookup. Converts any encountered |
|
231 |
* {@link IllegalAccessException} into an {@link IllegalAccessError} and |
|
232 |
* {@link NoSuchMethodException} into a {@link NoSuchMethodError}. |
|
16234
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 |
* @param declaringClass class declaring the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
235 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
236 |
* @param type the type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
237 |
* @return a method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
238 |
* @throws IllegalAccessError if the method is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
239 |
* @throws NoSuchMethodError if the method does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
240 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
241 |
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
|
242 |
try { |
16245
6a1c6c8bc113
8008371: Fix Dynalink compiler warnings and whitespace
attila
parents:
16234
diff
changeset
|
243 |
return lookup.findSpecial(declaringClass, name, type, declaringClass); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
244 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
245 |
final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
246 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
247 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
248 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
249 |
} catch(final NoSuchMethodException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
250 |
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
251 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
252 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
253 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
254 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
255 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
256 |
|
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
257 |
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
|
258 |
return declaringClass.getName() + "#" + name + type; |
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 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
261 |
/** |
33333 | 262 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType)} |
263 |
* on the underlying lookup. Converts any encountered |
|
264 |
* {@link IllegalAccessException} into an {@link IllegalAccessError} and |
|
265 |
* {@link NoSuchMethodException} into a {@link NoSuchMethodError}. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
266 |
* |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
267 |
* @param declaringClass class declaring the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
268 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
269 |
* @param type the type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
270 |
* @return a method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
271 |
* @throws IllegalAccessError if the method is inaccessible. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
272 |
* @throws NoSuchMethodError if the method does not exist. |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
273 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
274 |
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
|
275 |
try { |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
276 |
return lookup.findStatic(declaringClass, name, type); |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
277 |
} catch(final IllegalAccessException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
278 |
final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
279 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
280 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
281 |
throw ee; |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
282 |
} catch(final NoSuchMethodException e) { |
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
283 |
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription( |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
284 |
declaringClass, name, type)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
285 |
ee.initCause(e); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
286 |
throw ee; |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
287 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
288 |
} |
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 |
/** |
33333 | 291 |
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType)} |
292 |
* on the underlying lookup. Converts any encountered |
|
293 |
* {@link IllegalAccessException} into an {@link IllegalAccessError} and |
|
294 |
* {@link NoSuchMethodException} into a {@link NoSuchMethodError}. |
|
16234
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 |
/** |
33333 | 320 |
* Given a lookup, finds using {@link #findSpecial(Class, String, MethodType)} |
321 |
* a method on that lookup's class. Useful in classes' code for convenient |
|
322 |
* linking to their own privates. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
323 |
* @param lookup the lookup for the class |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
324 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
325 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
326 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
327 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
328 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
329 |
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
|
330 |
return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes); |
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 |
/** |
33333 | 335 |
* Finds using {@link #findSpecial(Class, String, MethodType)} a method on |
336 |
* that lookup's class. Useful in classes' code for convenient linking to |
|
337 |
* their own privates. It's also more convenient than {@code findSpecial} |
|
338 |
* in that you can just list the parameter types, and don't have to specify |
|
339 |
* lookup class. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
340 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
341 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
342 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
343 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
344 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
345 |
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
|
346 |
return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
347 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
348 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
349 |
/** |
33333 | 350 |
* Given a lookup, finds using {@link #findStatic(Class, String, MethodType)} |
351 |
* a method on that lookup's class. Useful in classes' code for convenient |
|
352 |
* linking to their own privates. It's easier to use than {@code findStatic} |
|
353 |
* in that you can just list the parameter types, and don't have to specify |
|
354 |
* lookup class. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
355 |
* @param lookup the lookup for the class |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
356 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
357 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
358 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
359 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
360 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
361 |
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
|
362 |
return new Lookup(lookup).findOwnStatic(name, rtype, ptypes); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
363 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
364 |
|
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
365 |
/** |
33333 | 366 |
* Finds using {@link #findStatic(Class, String, MethodType)} a method on |
367 |
* that lookup's class. Useful in classes' code for convenient linking to |
|
368 |
* their own privates. It's easier to use than {@code findStatic} |
|
369 |
* in that you can just list the parameter types, and don't have to specify |
|
370 |
* lookup class. |
|
16234
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
371 |
* @param name the name of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
372 |
* @param rtype the return type of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
373 |
* @param ptypes the parameter types of the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
374 |
* @return the method handle for the method |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
375 |
*/ |
24778
2ff5d7041566
8044638: Tidy up Nashorn codebase for code standards
attila
parents:
19455
diff
changeset
|
376 |
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
|
377 |
return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes)); |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
378 |
} |
86cb162cec6c
8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff
changeset
|
379 |
} |