nashorn/src/jdk.dynalink/share/classes/jdk/dynalink/linker/support/Lookup.java
author attila
Tue, 24 Nov 2015 10:19:34 +0100
changeset 34447 ec4c069f9436
parent 33339 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/internal/dynalink/linker/support/Lookup.java@334cd3ebfa5e
child 36517 41a1c20eb619
permissions -rw-r--r--
8141338: Move jdk.internal.dynalink package to jdk.dynalink Reviewed-by: hannesw, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
34447
ec4c069f9436 8141338: Move jdk.internal.dynalink package to jdk.dynalink
attila
parents: 33339
diff changeset
    84
package jdk.dynalink.linker.support;
16234
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
/**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
    94
 * A wrapper around {@link java.lang.invoke.MethodHandles.Lookup} that masks
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
    95
 * checked exceptions. It is useful in those cases when you're looking up
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
    96
 * methods within your own codebase (therefore it is an error if they are not
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
    97
 * present).
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
    98
 */
33339
334cd3ebfa5e 8139888: Improve Dynalink JavaDoc some more
attila
parents: 33337
diff changeset
    99
public final class Lookup {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   100
    private final MethodHandles.Lookup lookup;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   101
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   102
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   103
     * Creates a new instance, bound to an instance of
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   104
     * {@link java.lang.invoke.MethodHandles.Lookup}.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   105
     *
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   106
     * @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
   107
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   108
    public Lookup(final MethodHandles.Lookup lookup) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   109
        this.lookup = lookup;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   110
    }
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
    /**
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   113
     * A canonical Lookup object that wraps {@link MethodHandles#publicLookup()}.
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
    public static final Lookup PUBLIC = new Lookup(MethodHandles.publicLookup());
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   116
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   117
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   118
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   119
     * converting any encountered {@link IllegalAccessException} into an
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   120
     * {@link IllegalAccessError}.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   121
     *
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   122
     * @param m the method to unreflect
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   123
     * @return the unreflected method handle.
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   124
     * @throws IllegalAccessError if the method is inaccessible.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   125
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   126
    public MethodHandle unreflect(final Method m) {
18841
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   127
        return unreflect(lookup, m);
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
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   130
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   131
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   132
     * converting any encountered {@link IllegalAccessException} into an
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   133
     * {@link IllegalAccessError}.
18841
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   134
     *
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   135
     * @param lookup the lookup used to unreflect
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   136
     * @param m the method to unreflect
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   137
     * @return the unreflected method handle.
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   138
     * @throws IllegalAccessError if the method is inaccessible.
18841
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   139
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   140
    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
   141
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   142
            return lookup.unreflect(m);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   143
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   144
            final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   145
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   146
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   147
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   148
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   149
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   150
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   151
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   152
     * converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   153
     *
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   154
     * @param f the field for which a getter is unreflected
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   155
     * @return the unreflected field getter handle.
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   156
     * @throws IllegalAccessError if the getter is inaccessible.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   157
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   158
    public MethodHandle unreflectGetter(final Field f) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   159
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   160
            return lookup.unreflectGetter(f);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   161
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   162
            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
   163
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   164
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   165
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   166
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   167
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   168
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   169
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   170
     * converting any encountered {@link IllegalAccessException} into an
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   171
     * {@link IllegalAccessError} and {@link NoSuchFieldException} into a
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   172
     * {@link NoSuchFieldError}.
16234
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
     * @param refc the class declaring the field
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   175
     * @param name the name of the field
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   176
     * @param type the type of the field
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   177
     * @return the unreflected field getter handle.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   178
     * @throws IllegalAccessError if the field is inaccessible.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   179
     * @throws NoSuchFieldError if the field does not exist.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   180
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   181
    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
   182
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   183
            return lookup.findGetter(refc, name, type);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   184
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   185
            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
   186
                    "." + name + " of type " + type.getName());
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   187
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   188
            throw ee;
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   189
        } catch(final NoSuchFieldException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   190
            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
   191
                    "." + name + " of type " + type.getName());
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   192
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   193
            throw ee;
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
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   196
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   197
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   198
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   199
     * converting any encountered {@link IllegalAccessException} into an
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   200
     * {@link IllegalAccessError}.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   201
     *
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   202
     * @param f the field for which a setter is unreflected
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   203
     * @return the unreflected field setter handle.
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   204
     * @throws IllegalAccessError if the field is inaccessible.
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   205
     * @throws NoSuchFieldError if the field does not exist.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   206
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   207
    public MethodHandle unreflectSetter(final Field f) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   208
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   209
            return lookup.unreflectSetter(f);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   210
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   211
            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
   212
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   213
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   214
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   215
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   216
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   217
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   218
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   219
     * converting any encountered {@link IllegalAccessException} into an
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   220
     * {@link IllegalAccessError}.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   221
     *
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   222
     * @param c the constructor to unreflect
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   223
     * @return the unreflected constructor handle.
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   224
     * @throws IllegalAccessError if the constructor is inaccessible.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   225
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   226
    public MethodHandle unreflectConstructor(final Constructor<?> c) {
18841
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   227
        return unreflectConstructor(lookup, c);
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   228
    }
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   229
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   230
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   231
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)},
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   232
     * converting any encountered {@link IllegalAccessException} into an
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   233
     * {@link IllegalAccessError}.
18841
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   234
     *
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   235
     * @param lookup the lookup used to unreflect
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   236
     * @param c the constructor to unreflect
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   237
     * @return the unreflected constructor handle.
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   238
     * @throws IllegalAccessError if the constructor is inaccessible.
18841
9bbc4b8832b2 8010946: AccessControl.doPrivileged is broken when called from js script
attila
parents: 16245
diff changeset
   239
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   240
    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
   241
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   242
            return lookup.unreflectConstructor(c);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   243
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   244
            final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   245
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   246
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   247
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   248
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   249
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   250
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   251
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findSpecial(Class, String, MethodType, Class)}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   252
     * on the underlying lookup. Converts any encountered
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   253
     * {@link IllegalAccessException} into an {@link IllegalAccessError} and
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   254
     * {@link NoSuchMethodException} into a {@link NoSuchMethodError}.
16234
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
     * @param declaringClass class declaring the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   257
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   258
     * @param type the type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   259
     * @return a method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   260
     * @throws IllegalAccessError if the method is inaccessible.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   261
     * @throws NoSuchMethodError if the method does not exist.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   262
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   263
    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
   264
        try {
16245
6a1c6c8bc113 8008371: Fix Dynalink compiler warnings and whitespace
attila
parents: 16234
diff changeset
   265
            return lookup.findSpecial(declaringClass, name, type, declaringClass);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   266
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   267
            final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription(
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   268
                    declaringClass, name, type));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   269
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   270
            throw ee;
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   271
        } catch(final NoSuchMethodException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   272
            final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription(
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   273
                    declaringClass, name, type));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   274
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   275
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   276
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   277
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   278
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   279
    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
   280
        return declaringClass.getName() + "#" + name + type;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   281
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   282
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   283
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   284
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType)}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   285
     * on the underlying lookup. Converts any encountered
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   286
     * {@link IllegalAccessException} into an {@link IllegalAccessError} and
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   287
     * {@link NoSuchMethodException} into a {@link NoSuchMethodError}.
16234
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
     * @param declaringClass class declaring the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   290
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   291
     * @param type the type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   292
     * @return a method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   293
     * @throws IllegalAccessError if the method is inaccessible.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   294
     * @throws NoSuchMethodError if the method does not exist.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   295
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   296
    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
   297
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   298
            return lookup.findStatic(declaringClass, name, type);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   299
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   300
            final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription(
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   301
                    declaringClass, name, type));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   302
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   303
            throw ee;
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   304
        } catch(final NoSuchMethodException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   305
            final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription(
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   306
                    declaringClass, name, type));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   307
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   308
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   309
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   310
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   311
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   312
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   313
     * Performs a {@link java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType)}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   314
     * on the underlying lookup. Converts any encountered
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   315
     * {@link IllegalAccessException} into an {@link IllegalAccessError} and
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   316
     * {@link NoSuchMethodException} into a {@link NoSuchMethodError}.
16234
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
     * @param declaringClass class declaring the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   319
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   320
     * @param type the type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   321
     * @return a method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   322
     * @throws IllegalAccessError if the method is inaccessible.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   323
     * @throws NoSuchMethodError if the method does not exist.
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   324
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   325
    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
   326
        try {
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   327
            return lookup.findVirtual(declaringClass, name, type);
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   328
        } catch(final IllegalAccessException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   329
            final IllegalAccessError ee = new IllegalAccessError("Failed to access virtual method " + methodDescription(
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   330
                    declaringClass, name, type));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   331
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   332
            throw ee;
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   333
        } catch(final NoSuchMethodException e) {
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   334
            final NoSuchMethodError ee = new NoSuchMethodError("Failed to find virtual method " + methodDescription(
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   335
                    declaringClass, name, type));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   336
            ee.initCause(e);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   337
            throw ee;
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   338
        }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   339
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   340
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   341
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   342
     * Given a lookup, finds using {@link #findSpecial(Class, String, MethodType)}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   343
     * a method on that lookup's class. Useful in classes' code for convenient
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   344
     * linking to their own privates.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   345
     * @param lookup the lookup for the class
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   346
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   347
     * @param rtype the return type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   348
     * @param ptypes the parameter types of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   349
     * @return the method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   350
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   351
    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
   352
        return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   353
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   354
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   355
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   356
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   357
     * Finds using {@link #findSpecial(Class, String, MethodType)} a method on
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   358
     * that lookup's class. Useful in classes' code for convenient linking to
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   359
     * their own privates. It's also more convenient than {@code findSpecial}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   360
     * in that you can just list the parameter types, and don't have to specify
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   361
     * lookup class.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   362
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   363
     * @param rtype the return type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   364
     * @param ptypes the parameter types of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   365
     * @return the method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   366
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   367
    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
   368
        return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   369
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   370
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   371
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   372
     * Given a lookup, finds using {@link #findStatic(Class, String, MethodType)}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   373
     * a method on that lookup's class. Useful in classes' code for convenient
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   374
     * linking to their own privates. It's easier to use than {@code findStatic}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   375
     * in that you can just list the parameter types, and don't have to specify
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   376
     * lookup class.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   377
     * @param lookup the lookup for the class
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   378
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   379
     * @param rtype the return type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   380
     * @param ptypes the parameter types of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   381
     * @return the method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   382
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   383
    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
   384
        return new Lookup(lookup).findOwnStatic(name, rtype, ptypes);
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   385
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   386
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   387
    /**
33333
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   388
     * Finds using {@link #findStatic(Class, String, MethodType)} a method on
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   389
     * that lookup's class. Useful in classes' code for convenient linking to
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   390
     * their own privates. It's easier to use than {@code findStatic}
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   391
     * in that you can just list the parameter types, and don't have to specify
0bad500ce4e0 8139590: Improve Dynalink JavaDoc
attila
parents: 33007
diff changeset
   392
     * lookup class.
16234
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   393
     * @param name the name of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   394
     * @param rtype the return type of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   395
     * @param ptypes the parameter types of the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   396
     * @return the method handle for the method
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   397
     */
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 19455
diff changeset
   398
    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
   399
        return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes));
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   400
    }
86cb162cec6c 8008085: Integrate Dynalink source code into Nashorn codebase
attila
parents:
diff changeset
   401
}