< prev index next >

src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java

Print this page

166             }
167         }
168     }
169 
170     /**
171      * Generate the MethodAccessor that invokes the given method with
172      * bytecode invocation.
173      */
174     static MethodAccessorImpl generateMethodAccessor(Method method) {
175         return (MethodAccessorImpl)new MethodAccessorGenerator()
176                 .generateMethod(method.getDeclaringClass(),
177                                 method.getName(),
178                                 method.getParameterTypes(),
179                                 method.getReturnType(),
180                                 method.getExceptionTypes(),
181                                 method.getModifiers());
182     }
183 
184     public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
185         Class<?> declaringClass = c.getDeclaringClass();
186         if (Modifier.isAbstract(declaringClass.getModifiers())) {
187             return new InstantiationExceptionConstructorAccessorImpl(null);
188         }
189         if (declaringClass == Class.class) {
190             return new InstantiationExceptionConstructorAccessorImpl
191                 ("Can not instantiate java.lang.Class");
192         }
193 
194         // use the root Constructor that will not cache caller class
195         Constructor<?> root = langReflectAccess.getRoot(c);
196         if (root != null) {
197             c = root;
198         }
199 
200         if (useMethodHandleAccessor()) {
201             return MethodHandleAccessorFactory.newConstructorAccessor(c);
202         } else {
203             // Bootstrapping issue: since we use Class.newInstance() in
204             // the ConstructorAccessor generation process, we have to
205             // break the cycle here.
206             if (Reflection.isSubclassOf(declaringClass, ConstructorAccessorImpl.class)) {

166             }
167         }
168     }
169 
170     /**
171      * Generate the MethodAccessor that invokes the given method with
172      * bytecode invocation.
173      */
174     static MethodAccessorImpl generateMethodAccessor(Method method) {
175         return (MethodAccessorImpl)new MethodAccessorGenerator()
176                 .generateMethod(method.getDeclaringClass(),
177                                 method.getName(),
178                                 method.getParameterTypes(),
179                                 method.getReturnType(),
180                                 method.getExceptionTypes(),
181                                 method.getModifiers());
182     }
183 
184     public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
185         Class<?> declaringClass = c.getDeclaringClass();
186         if (Modifier.isAbstract(declaringClass.getModifiers()) && declaringClass != Object.class) {
187             return new InstantiationExceptionConstructorAccessorImpl(null);
188         }
189         if (declaringClass == Class.class) {
190             return new InstantiationExceptionConstructorAccessorImpl
191                 ("Can not instantiate java.lang.Class");
192         }
193 
194         // use the root Constructor that will not cache caller class
195         Constructor<?> root = langReflectAccess.getRoot(c);
196         if (root != null) {
197             c = root;
198         }
199 
200         if (useMethodHandleAccessor()) {
201             return MethodHandleAccessorFactory.newConstructorAccessor(c);
202         } else {
203             // Bootstrapping issue: since we use Class.newInstance() in
204             // the ConstructorAccessor generation process, we have to
205             // break the cycle here.
206             if (Reflection.isSubclassOf(declaringClass, ConstructorAccessorImpl.class)) {
< prev index next >