public Binding create ( Key < ? > key ) throws BindingCreationException { TypeLiteral < ? > type = key . getTypeLiteral ( ) ; // All steps per: // http://code.google.com/p/google-guice/wiki/BindingResolution // 1. Explicit binding - already finished at this point. // 2. Ask parent injector. // 3. Ask child injector. // These bindings are created in BindingResolver and are not necessary here. // 4. Provider injections. if ( isProviderKey ( key ) ) { return bindingFactory . getImplicitProviderBinding ( key ) ; // TODO(bstoler): Scope the provider binding like the thing being provided? } // 4b. AsyncProvider injections. if ( isAsyncProviderKey ( key ) ) { return bindingFactory . getAsyncProviderBinding ( key ) ; } // 5. Convert constants. // Already covered by resolving explicit bindings. if ( BindConstantBinding . isConstantKey ( key ) ) { throw new BindingCreationException ( "Binding requested for constant key '%s' but no explicit binding was found" , key ) ; } // 6. If the dependency has a binding annotation, give up. if ( key . getAnnotation ( ) != null || key . getAnnotationType ( ) != null ) { throw new BindingCreationException ( "No implementation bound for '%s' and an implicit binding" + " cannot be created because the type is annotated." , key ) ; } // 7. If the dependency is an array or enum, give up. // Covered by step 5 (enum) and 11 (array). // 8. Handle TypeLiteral injections. // TODO(schmitt): Implement TypeLiteral injections. // 9. Use resolution annotations (@ImplementedBy, @ProvidedBy) ImplementedBy implementedBy = type . getRawType ( ) . getAnnotation ( ImplementedBy . class ) ; if ( implementedBy != null ) { return createImplementedByBinding ( key , implementedBy ) ; } ProvidedBy providedBy = type . getRawType ( ) . getAnnotation ( ProvidedBy . class ) ; if ( providedBy != null ) { return createProvidedByBinding ( key , providedBy ) ; } // 10. If the dependency is abstract or a non-static inner class, give up. // Abstract classes are handled by GWT.create. // TODO(schmitt): Introduce check. // 11. Use a single @Inject or public no-arguments constructor. return createImplicitBindingForClass ( type ) ; }
Creates the implicit binding .