src/java.base/share/classes/java/lang/reflect/Proxy.java
changeset 49273 af8ab4f90a32
parent 47722 ce6ff74192fc
child 49529 c0bdb1b1ab4f
equal deleted inserted replaced
49272:e137b71166c4 49273:af8ab4f90a32
   706          * Returns all types referenced by all public non-static method signatures of
   706          * Returns all types referenced by all public non-static method signatures of
   707          * the proxy interfaces
   707          * the proxy interfaces
   708          */
   708          */
   709         private static Set<Class<?>> referencedTypes(ClassLoader loader,
   709         private static Set<Class<?>> referencedTypes(ClassLoader loader,
   710                                                      List<Class<?>> interfaces) {
   710                                                      List<Class<?>> interfaces) {
   711             return interfaces.stream()
   711             var types = new HashSet<Class<?>>();
   712                  .flatMap(intf -> Stream.of(intf.getMethods())
   712             for (var intf : interfaces) {
   713                                         .filter(m -> !Modifier.isStatic(m.getModifiers()))
   713                 for (Method m : intf.getMethods()) {
   714                                         .flatMap(ProxyBuilder::methodRefTypes)
   714                     if (!Modifier.isStatic(m.getModifiers())) {
   715                                         .map(ProxyBuilder::getElementType)
   715                         addElementType(types, m.getReturnType());
   716                                         .filter(t -> !t.isPrimitive()))
   716                         addElementTypes(types, m.getSharedParameterTypes());
   717                  .collect(Collectors.toSet());
   717                         addElementTypes(types, m.getSharedExceptionTypes());
   718         }
   718                     }
   719 
   719                 }
   720         /*
   720             }
   721          * Extracts all types referenced on a method signature including
   721             return types;
   722          * its return type, parameter types, and exception types.
   722         }
   723          */
   723 
   724         private static Stream<Class<?>> methodRefTypes(Method m) {
   724         private static void addElementTypes(HashSet<Class<?>> types,
   725             return Stream.of(new Class<?>[] { m.getReturnType() },
   725                                             Class<?> ... classes) {
   726                              m.getParameterTypes(),
   726             for (var cls : classes) {
   727                              m.getExceptionTypes())
   727                 addElementType(types, cls);
   728                          .flatMap(Stream::of);
   728             }
       
   729         }
       
   730 
       
   731         private static void addElementType(HashSet<Class<?>> types,
       
   732                                            Class<?> cls) {
       
   733             var type = getElementType(cls);
       
   734             if (!type.isPrimitive()) {
       
   735                 types.add(type);
       
   736             }
   729         }
   737         }
   730 
   738 
   731         /**
   739         /**
   732          * Returns the module that the generated proxy class belongs to.
   740          * Returns the module that the generated proxy class belongs to.
   733          *
   741          *