private static < CT , I > Function < CT , I > resolveAndExtend ( Class < CT > contextType , List < MethodResolver < CT > > resolvers , Class < I > typeToExtend ) { // Resolve generics ResolvedTypeWithMembers withMembers = Types . resolveMembers ( typeToExtend ) ; Map < Method , MethodInvocationHandler < CT > > handlers = new HashMap <> ( ) ; try { // Go through methods and create invokers for each of them for ( ResolvedMethod method : withMembers . getMemberMethods ( ) ) { // Only try to implement abstract methods if ( ! method . isAbstract ( ) ) continue ; // Create an encounter and let the first method resolver that matches handle the method boolean foundInvoker = false ; MethodEncounter encounter = new MethodEncounterImpl ( method ) ; for ( MethodResolver < CT > resolver : resolvers ) { Optional < MethodInvocationHandler < CT >> opt = resolver . create ( encounter ) ; if ( opt . isPresent ( ) ) { // This resolver created an invoker to use foundInvoker = true ; handlers . put ( method . getRawMember ( ) , opt . get ( ) ) ; break ; } } if ( ! foundInvoker ) { // No invoker was found, can not handle the method throw new ProxyException ( "The method " + method . getName ( ) + " could not be handled" ) ; } } } catch ( ProxyException e ) { throw new ProxyException ( typeToExtend . getName ( ) + ":\n" + e . getMessage ( ) ) ; } catch ( Exception e ) { throw new ProxyException ( typeToExtend . getName ( ) + ":\n" + e . getMessage ( ) , e ) ; } return createFunction ( contextType , typeToExtend , Collections . unmodifiableMap ( handlers ) ) ; }
Internal helper that resolves all the invokers using the given resolvers .