/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
public AbstractInjectionProvider(Key<T> key) { this.key = key; constructorInjectionPoint = InjectionPoint.forConstructorOf(key.getTypeLiteral()); Set<Dependency<?>> dependencyBuilder = new HashSet<Dependency<?>>(); dependencyBuilder.addAll(constructorInjectionPoint.getDependencies()); for (InjectionPoint injectionPoint : InjectionPoint.forInstanceMethodsAndFields(key.getTypeLiteral())) { dependencyBuilder.addAll(injectionPoint.getDependencies()); } this.dependencies = Collections.unmodifiableSet(dependencyBuilder); }
@Test public void ensureInjectable() { try { InjectionPoint ip = InjectionPoint.forConstructorOf(GuiceShiroFilter.class); } catch (Exception e) { fail("Could not create constructor injection point."); } }
@Test public void ensureInjectable() { try { InjectionPoint ip = InjectionPoint.forConstructorOf(WebGuiceEnvironment.class); } catch (Exception e) { fail("Could not create constructor injection point."); } }
@Test public void ensureInjectable() { try { InjectionPoint ip = InjectionPoint.forConstructorOf(GuiceEnvironment.class); } catch (Exception e) { fail("Could not create constructor injection point."); } } }
constructorInjector = InjectionPoint.forConstructorOf(key.getTypeLiteral()); if (failIfNotExplicit && !hasAtInject((Constructor) constructorInjector.getMember())) { errors.atInjectRequired(rawType);
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
/** * Returns a new injection point for the injectable constructor of {@code type}. * * @param type a concrete type with exactly one constructor annotated {@literal @}{@link Inject}, * or a no-arguments constructor that is not private. * @throws ConfigurationException if there is no injectable constructor, more than one injectable * constructor, or if parameters of the injectable constructor are malformed, such as * a * parameter with multiple binding annotations. */ public static InjectionPoint forConstructorOf(Class<?> type) { return forConstructorOf(TypeLiteral.get(type)); }
private Iterator<Dependency<?>> initInjectionPoint() { try { InjectionPoint injectionPoint; if (creationTypeLiteral != null) { injectionPoint = InjectionPoint.forConstructorOf(creationTypeLiteral); } else { injectionPoint = InjectionPoint.forConstructorOf(creationClass); } return injectionPoint.getDependencies().iterator(); } catch (ConfigurationException dummy) { // ignore } return null; } }
static Set<Key<?>> getUnboundDirectDependencies(TypeLiteral<?> type, Set<Key<?>> boundKeys) { if (type.getRawType().isInterface()) { return Collections.emptySet(); } Set<Key<?>> keys = new HashSet<>(); keys.addAll(getUnboundDirectDependencies(InjectionPoint.forConstructorOf(type), boundKeys)); keys.addAll(getUnboundDirectDependencies(InjectionPoint.forInstanceMethodsAndFields(type), boundKeys)); return keys; }
private boolean canBeInjected(TypeLiteral<?> type) { Class<?> rawType = type.getRawType(); if (isPrimitive(rawType) || isCoreGuiceType(rawType) || !isInstantiable(rawType)) { return false; } try { InjectionPoint.forConstructorOf(type); return true; } catch (ConfigurationException e) { return false; } }
private boolean canBeInjected(TypeLiteral<?> type) { Class<?> rawType = type.getRawType(); if (isPrimitive(rawType) || isCoreGuiceType(rawType) || !isInstantiable(rawType)) { return false; } try { InjectionPoint.forConstructorOf(type); return true; } catch (ConfigurationException e) { return false; } }
public AbstractInjectionProvider(Key<T> key) { this.key = key; constructorInjectionPoint = InjectionPoint.forConstructorOf(key.getTypeLiteral()); Set<Dependency<?>> dependencyBuilder = new HashSet<Dependency<?>>(); dependencyBuilder.addAll(constructorInjectionPoint.getDependencies()); for (InjectionPoint injectionPoint : InjectionPoint.forInstanceMethodsAndFields(key.getTypeLiteral())) { dependencyBuilder.addAll(injectionPoint.getDependencies()); } this.dependencies = Collections.unmodifiableSet(dependencyBuilder); }
@SuppressWarnings("unchecked") private <T> ScopedBindingBuilder bindNewSpyProvider(Key<T> key) { TypeLiteral<T> type = key.getTypeLiteral(); InjectionPoint constructorInjectionPoint = InjectionPoint.forConstructorOf(type); Key<T> relayingKey = Key.get(type, JukitoInternal.class); bind(relayingKey).toConstructor((Constructor<T>) constructorInjectionPoint.getMember()); return bind(key).toProvider(new SpyProvider<T>(getProvider(relayingKey), relayingKey)); }
@SuppressWarnings("unchecked") private <T> ScopedBindingBuilder bindNewSpyProvider(Key<T> key) { TypeLiteral<T> type = key.getTypeLiteral(); InjectionPoint constructorInjectionPoint = InjectionPoint.forConstructorOf(type); Key<T> relayingKey = Key.get(type, JukitoInternal.class); bind(relayingKey).toConstructor((Constructor<T>) constructorInjectionPoint.getMember()); return bind(key).toProvider(new SpyProvider<T>(getProvider(relayingKey), relayingKey)); }
private <T> void addDependencies(Key<T> key, Set<Key<?>> keysObserved, Set<Key<?>> keysNeeded) { TypeLiteral<T> type = key.getTypeLiteral(); if (!canBeInjected(type)) { return; } addInjectionPointDependencies(InjectionPoint.forConstructorOf(type), keysObserved, keysNeeded); Set<InjectionPoint> methodsAndFieldsInjectionPoints = InjectionPoint.forInstanceMethodsAndFields(type); for (InjectionPoint injectionPoint : methodsAndFieldsInjectionPoints) { addInjectionPointDependencies(injectionPoint, keysObserved, keysNeeded); } }