DefaultServiceRegistry之findProviderMethods private void findProviderMethods(Object target) { Set<String> methods = new HashSet<String>(); for (Class<?> type = target.getClass(); type != Object.class; type = type.getSuperclass()) { findDecoratorMethods(target, type, methods, ownServices); findFactoryMethods(target, type, methods, ownServices); } findConfigureMethod(target); } findDecoratorMethods(target, type, methods, ownServices); 从target自己开始,一直到all super class 声明的函数中以create开头,参数一个并且参数类型和返回类型一致的, 以new DecoratorMethodService(target, method) 加入到ownService变量维护的list<Provider>中 type:DecoratorMethodService 例如: org.gradle.api.internal.plugins.PluginRegistry org.gradle.internal.service.scopes.GradleScopeServices.createPluginRegistry( org.gradle.api.internal.plugins.PluginRegistry ) findFactoryMethods(target, type, methods, ownServices); 从target自己开始,一路找到所有super class 声明的函数中名字以create开始的,都加入到自己维护的ownServices成员的list<Provider>中 type:FactoryMethodService findConfigureMethod(target); target和所有基类,方法叫cofigure 返回void的 例如void org.gradle.internal.service.scopes.GlobalScopeServices.configure( org.gradle.internal.service.ServiceRegistration, org.gradle.initialization.ClassLoaderRegistry ) 把改method的参数换个类型, invoke,具体参见 void org.gradle.internal.service.DefaultServiceRegistry.findConfigureMethod(Object target)
时间: 2024-11-07 02:26:19