jdk/src/share/classes/java/lang/reflect/ReflectAccess.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7803 56bc97d69d93
child 15510 898d924a7efd
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7803
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3959
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.reflect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.reflect.MethodAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.reflect.ConstructorAccessor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/** Package-private class implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    sun.reflect.LangReflectAccess interface, allowing the java.lang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    package to instantiate objects in this package. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
class ReflectAccess implements sun.reflect.LangReflectAccess {
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    36
    public Field newField(Class<?> declaringClass,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
                          String name,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    38
                          Class<?> type,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                          int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                          int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                          String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                          byte[] annotations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        return new Field(declaringClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                         name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                         type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                         modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                         slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                         signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                         annotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    53
    public Method newMethod(Class<?> declaringClass,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                            String name,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    55
                            Class<?>[] parameterTypes,
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    56
                            Class<?> returnType,
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    57
                            Class<?>[] checkedExceptions,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                            int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                            int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                            String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                            byte[] annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                            byte[] parameterAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                            byte[] annotationDefault)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        return new Method(declaringClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                          name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                          parameterTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                          returnType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                          checkedExceptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                          modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                          slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                          signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                          annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                          parameterAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                          annotationDefault);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public <T> Constructor<T> newConstructor(Class<T> declaringClass,
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    79
                                             Class<?>[] parameterTypes,
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
    80
                                             Class<?>[] checkedExceptions,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                             int modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                             int slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                             String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                             byte[] annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                             byte[] parameterAnnotations)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    {
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
    87
        return new Constructor<>(declaringClass,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                  parameterTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                  checkedExceptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                  modifiers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                  slot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                  signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                  annotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                  parameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public MethodAccessor getMethodAccessor(Method m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return m.getMethodAccessor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void setMethodAccessor(Method m, MethodAccessor accessor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        m.setMethodAccessor(accessor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
   105
    public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return c.getConstructorAccessor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
   109
    public void setConstructorAccessor(Constructor<?> c,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                       ConstructorAccessor accessor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        c.setConstructorAccessor(accessor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
   115
    public int getConstructorSlot(Constructor<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return c.getSlot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
   119
    public String getConstructorSignature(Constructor<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return c.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
   123
    public byte[] getConstructorAnnotations(Constructor<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return c.getRawAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
3959
05a07c0a273b 5062288: (reflect) Core reflection uses raw types when it could be using wildcards
darcy
parents: 2
diff changeset
   127
    public byte[] getConstructorParameterAnnotations(Constructor<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return c.getRawParameterAnnotations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // Copying routines, needed to quickly fabricate new Field,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // Method, and Constructor objects from templates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Method      copyMethod(Method arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return arg.copy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public Field       copyField(Field arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return arg.copy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public <T> Constructor<T> copyConstructor(Constructor<T> arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return arg.copy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
}