1 /*
  2  * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package jdk.internal.access;
 27 
 28 import java.lang.reflect.*;
 29 import jdk.internal.reflect.*;
 30 
 31 /** An interface which gives privileged packages Java-level access to
 32     internals of java.lang.reflect. */
 33 
 34 public interface JavaLangReflectAccess {
 35     /** Creates a new java.lang.reflect.Constructor. Access checks as
 36       per java.lang.reflect.AccessibleObject are not overridden. */
 37     public <T> Constructor<T> newConstructor(Class<T> declaringClass,
 38                                              Class<?>[] parameterTypes,
 39                                              Class<?>[] checkedExceptions,
 40                                              int modifiers,
 41                                              int slot,
 42                                              String signature,
 43                                              byte[] annotations,
 44                                              byte[] parameterAnnotations);
 45 
 46     /** Gets the MethodAccessor object for a java.lang.reflect.Method */
 47     public MethodAccessor getMethodAccessor(Method m);
 48 
 49     /** Sets the MethodAccessor object for a java.lang.reflect.Method */
 50     public void setMethodAccessor(Method m, MethodAccessor accessor);
 51 
 52     /** Gets the ConstructorAccessor object for a
 53         java.lang.reflect.Constructor */
 54     public ConstructorAccessor getConstructorAccessor(Constructor<?> c);
 55 
 56     /** Sets the ConstructorAccessor object for a
 57         java.lang.reflect.Constructor */
 58     public void setConstructorAccessor(Constructor<?> c,
 59                                        ConstructorAccessor accessor);
 60 
 61     /** Gets the byte[] that encodes TypeAnnotations on an Executable. */
 62     public byte[] getExecutableTypeAnnotationBytes(Executable ex);
 63 
 64     /** Gets the "slot" field from a Constructor (used for serialization) */
 65     public int getConstructorSlot(Constructor<?> c);
 66 
 67     /** Gets the "signature" field from a Constructor (used for serialization) */
 68     public String getConstructorSignature(Constructor<?> c);
 69 
 70     /** Gets the "annotations" field from a Constructor (used for serialization) */
 71     public byte[] getConstructorAnnotations(Constructor<?> c);
 72 
 73     /** Gets the "parameterAnnotations" field from a Constructor (used for serialization) */
 74     public byte[] getConstructorParameterAnnotations(Constructor<?> c);
 75 
 76     /** Gets the shared array of parameter types of an Executable. */
 77     public Class<?>[] getExecutableSharedParameterTypes(Executable ex);
 78 
 79     /** Gets the shared array of exception types of an Executable. */
 80     public Class<?>[] getExecutableSharedExceptionTypes(Executable ex);
 81 
 82     //
 83     // Copying routines, needed to quickly fabricate new Field,
 84     // Method, and Constructor objects from templates
 85     //
 86 
 87     /** Makes a "child" copy of a Method */
 88     public Method      copyMethod(Method arg);
 89 
 90     /** Makes a copy of this non-root a Method */
 91     public Method      leafCopyMethod(Method arg);
 92 
 93     /** Makes a "child" copy of a Field */
 94     public Field       copyField(Field arg);
 95 
 96     /** Makes a "child" copy of a Constructor */
 97     public <T> Constructor<T> copyConstructor(Constructor<T> arg);
 98 
 99     /** Gets the root of the given AccessibleObject object; null if arg is the root */
100     public <T extends AccessibleObject> T getRoot(T obj);
101 
102     /** Tests if this is a trusted final field */
103     public boolean isTrustedFinalField(Field f);
104 
105 
106     /** Tests if this is a null-restricted field */
107     public boolean isNullRestrictedField(Field f);
108 
109     /** Returns a new instance created by the given constructor with access check */
110     public <T> T newInstance(Constructor<T> ctor, Object[] args, Class<?> caller)
111         throws IllegalAccessException, InstantiationException, InvocationTargetException;
112 }