/** Creates a binding for a type annotated with @ImplementedBy. */ private <T> BindingImpl<T> createImplementedByBinding( Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors) throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value(); // Make sure it's not the same type. TODO: Can we check for deeper cycles? if (implementationType == rawType) { throw errors.recursiveImplementationType().toException(); } // Make sure implementationType extends type. if (!rawType.isAssignableFrom(implementationType)) { throw errors.notASubtype(implementationType, rawType).toException(); } @SuppressWarnings("unchecked") // After the preceding check, this cast is safe. Class<? extends T> subclass = (Class<? extends T>) implementationType; // Look up the target binding. final Key<? extends T> targetKey = Key.get(subclass); Object source = rawType; FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source); factory.notify(errors); // causes the factory to initialize itself internally return new LinkedBindingImpl<T>( this, key, source, Scoping.<T>scope(key, this, factory, source, scoping), scoping, targetKey); }
/** Create a default Java batch compiler, without injection. * * @return the Java batch compiler. * @since 0.8 */ public static IJavaBatchCompiler newDefaultJavaBatchCompiler() { try { synchronized (SarlBatchCompiler.class) { if (defaultJavaBatchCompiler == null) { final ImplementedBy annotation = IJavaBatchCompiler.class.getAnnotation(ImplementedBy.class); assert annotation != null; final Class<?> type = annotation.value(); assert type != null; defaultJavaBatchCompiler = type.asSubclass(IJavaBatchCompiler.class); } return defaultJavaBatchCompiler.newInstance(); } } catch (Exception exception) { throw new RuntimeException(exception); } }
private void analyzeImplicitBindings( final TypeLiteral<?> type ) { if ( !analyzedTypes.containsKey( type ) ) { final Class<?> clazz = type.getRawType(); if ( TypeParameters.isConcrete( clazz ) ) { analyzeImplementation( type, false ); } else { analyzedTypes.put( type, Boolean.TRUE ); final ImplementedBy implementedBy = clazz.getAnnotation( ImplementedBy.class ); if ( null != implementedBy ) { requireKey( Key.get( implementedBy.value() ) ); } else { final ProvidedBy providedBy = clazz.getAnnotation( ProvidedBy.class ); if ( null != providedBy ) { requireKey( Key.get( providedBy.value() ) ); } } } } } }
private BindClassBinding createImplementedByBinding(Key<?> key, ImplementedBy implementedBy) throws BindingCreationException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value(); if (implementationType == rawType) { throw new BindingCreationException( "@ImplementedBy points to the same class it annotates: %s", rawType); } if (!rawType.isAssignableFrom(implementationType)) { throw new BindingCreationException("%s doesn't extend %s (while resolving @ImplementedBy)", implementationType, rawType); } return bindingFactory.getBindClassBinding(Key.get(implementationType), key, Context.forText("@ImplementedBy annotation")); }
if ( null != implementedBy ) binder.bind( Key.get( clazz, Implicit.class ) ).to( (Class) implementedBy.value() );
/** Creates a binding for a type annotated with @ImplementedBy. */ private <T> BindingImpl<T> createImplementedByBinding( Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors) throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value(); // Make sure it's not the same type. TODO: Can we check for deeper cycles? if (implementationType == rawType) { throw errors.recursiveImplementationType().toException(); } // Make sure implementationType extends type. if (!rawType.isAssignableFrom(implementationType)) { throw errors.notASubtype(implementationType, rawType).toException(); } @SuppressWarnings("unchecked") // After the preceding check, this cast is safe. Class<? extends T> subclass = (Class<? extends T>) implementationType; // Look up the target binding. final Key<? extends T> targetKey = Key.get(subclass); Object source = rawType; FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source); factory.notify(errors); // causes the factory to initialize itself internally return new LinkedBindingImpl<T>( this, key, source, Scoping.<T>scope(key, this, factory, source, scoping), scoping, targetKey); }
throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value();
throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value();
throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value();
/** Creates a binding for a type annotated with @ImplementedBy. */ private <T> BindingImpl<T> createImplementedByBinding( Key<T> key, Scoping scoping, ImplementedBy implementedBy, Errors errors) throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value(); // Make sure it's not the same type. TODO: Can we check for deeper cycles? if (implementationType == rawType) { throw errors.recursiveImplementationType().toException(); } // Make sure implementationType extends type. if (!rawType.isAssignableFrom(implementationType)) { throw errors.notASubtype(implementationType, rawType).toException(); } @SuppressWarnings("unchecked") // After the preceding check, this cast is safe. Class<? extends T> subclass = (Class<? extends T>) implementationType; // Look up the target binding. final Key<? extends T> targetKey = Key.get(subclass); Object source = rawType; FactoryProxy<T> factory = new FactoryProxy<>(this, key, targetKey, source); factory.notify(errors); // causes the factory to initialize itself internally return new LinkedBindingImpl<T>( this, key, source, Scoping.<T>scope(key, this, factory, source, scoping), scoping, targetKey); }
throws ErrorsException { Class<?> rawType = key.getTypeLiteral().getRawType(); Class<?> implementationType = implementedBy.value();
type.getAnnotation(ImplementedBy.class); if (implementedBy != null) { Class<?> implementationType = implementedBy.value();