@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
private <T> ProviderMethod<T> createProviderMethod( Binder binder, Method method, Annotation annotation) { binder = binder.withSource(method); Errors errors = new Errors(method); // prepare the parameter providers InjectionPoint point = InjectionPoint.forMethod(method, typeLiteral); @SuppressWarnings("unchecked") // Define T as the method's return type. TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method); Key<T> key = getKey(errors, returnType, method, method.getAnnotations()); try { key = scanner.prepareMethod(binder, annotation, key, point); } catch (Throwable t) { binder.addError(t); } Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations()); for (Message message : errors.getMessages()) { binder.addError(message); } return ProviderMethod.create( key, method, delegate, ImmutableSet.copyOf(point.getDependencies()), scopeAnnotation, skipFastClassGeneration, annotation); }
@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
@Override public TypeLiteral<?> getReturnType() { return getDeclaringType().getReturnType(getMember()); }
@VisibleForTesting void mergeProviderSourceVertices(final ServiceDAG serviceDAG) { // 1. Find all vertices within the service graph which are providers. final Set<IServiceDAGVertex<?>> providerSourceVertices = serviceDAG.findAllVertices(rawTypeThat(subclassesOf(Provider.class))); // 2. Search the service graph for the vertices which are provided by the provider vertices final Map<IServiceDAGVertex<?>, Optional<IServiceDAGVertex<?>>> providerSourceMap = providerSourceVertices.stream().collect(Collectors.toMap(Function.identity(), providerSourceVertex -> { final TypeLiteral<?> providerSourceLiteral = providerSourceVertex.getGuiceKey().getTypeLiteral(); try { final Method getMethod = providerSourceLiteral.getRawType().getDeclaredMethod("get"); final TypeLiteral<?> providedLiteral = providerSourceLiteral.getReturnType(getMethod); return serviceDAG.findVertex(Key.get(providedLiteral)); } catch (Throwable t) { return Optional.empty(); } })); // 3. For each provider, provided pair, merge them together within the service graph providerSourceMap.entrySet().stream() .filter(entry -> entry.getValue().isPresent()) .forEach(entry -> { final IServiceDAGVertex<?> providerSourceVertex = entry.getKey(); final IServiceDAGVertex<?> providedVertex = entry.getValue().get(); final IServiceDAGVertex<?> mergedVertex = createDAGVertexWithProvider(providedVertex, providerSourceVertex); mergeVertices(serviceDAG, providerSourceVertex, providedVertex, mergedVertex); }); }
public static <F> Provider<F> newFactory( TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) { Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType); if (!factoryMethodToConstructor.isEmpty()) { return new FactoryProvider<F>(factoryType, implementationType, factoryMethodToConstructor); } else { BindingCollector collector = new BindingCollector(); // Preserving backwards-compatibility: Map all return types in a factory // interface to the passed implementation type. Errors errors = new Errors(); Key<?> implementationKey = Key.get(implementationType); try { for (Method method : factoryType.getRawType().getMethods()) { Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors); if (!implementationKey.equals(returnType)) { collector.addBinding(returnType, implementationType); } } } catch (ErrorsException e) { throw new ConfigurationException(e.getErrors().getMessages()); } return new FactoryProvider2<F>(Key.get(factoryType), collector); } }
public static <F> Provider<F> newFactory( TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) { Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType); if (!factoryMethodToConstructor.isEmpty()) { return new FactoryProvider<F>(factoryType, implementationType, factoryMethodToConstructor); } else { BindingCollector collector = new BindingCollector(); // Preserving backwards-compatibility: Map all return types in a factory // interface to the passed implementation type. Errors errors = new Errors(); Key<?> implementationKey = Key.get(implementationType); try { for (Method method : factoryType.getRawType().getMethods()) { Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors); if (!implementationKey.equals(returnType)) { collector.addBinding(returnType, implementationType); } } } catch (ErrorsException e) { throw new ConfigurationException(e.getErrors().getMessages()); } return new FactoryProvider2<F>(Key.get(factoryType), collector); } }
public static <F> Provider<F> newFactory( TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) { Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType); if (!factoryMethodToConstructor.isEmpty()) { return new FactoryProvider<F>(factoryType, implementationType, factoryMethodToConstructor); } else { BindingCollector collector = new BindingCollector(); // Preserving backwards-compatibility: Map all return types in a factory // interface to the passed implementation type. Errors errors = new Errors(); Key<?> implementationKey = Key.get(implementationType); try { for (Method method : factoryType.getRawType().getMethods()) { Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors); if (!implementationKey.equals(returnType)) { collector.addBinding(returnType, implementationType); } } } catch (ErrorsException e) { throw new ConfigurationException(e.getErrors().getMessages()); } return new FactoryProvider2<F>(Key.get(factoryType), collector); } }
public static <F> Provider<F> newFactory( TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) { Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType); if (!factoryMethodToConstructor.isEmpty()) { return new FactoryProvider<F>(factoryType, implementationType, factoryMethodToConstructor); } else { BindingCollector collector = new BindingCollector(); // Preserving backwards-compatibility: Map all return types in a factory // interface to the passed implementation type. Errors errors = new Errors(); Key<?> implementationKey = Key.get(implementationType); try { for (Method method : factoryType.getRawType().getMethods()) { Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors); if (!implementationKey.equals(returnType)) { collector.addBinding(returnType, implementationType); } } } catch (ErrorsException e) { throw new ConfigurationException(e.getErrors().getMessages()); } return new FactoryProvider2<F>(Key.get(factoryType), collector); } }
public static <F> Provider<F> newFactory( TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) { Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType); if (!factoryMethodToConstructor.isEmpty()) { return new FactoryProvider<F>(factoryType, factoryMethodToConstructor); } else { BindingCollector collector = new BindingCollector(); // Preserving backwards-compatibility: Map all return types in a factory // interface to the passed implementation type. Errors errors = new Errors(); Key<?> implementationKey = Key.get(implementationType); if (implementationType != null) { try { for (Method method : factoryType.getRawType().getMethods()) { Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors); if (!implementationKey.equals(returnType)) { collector.addBinding(returnType, implementationType); } } } catch (ErrorsException e) { throw new ConfigurationException(e.getErrors().getMessages()); } } return new FactoryProvider2<F>(Key.get(factoryType), collector); } }
Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors);
TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method);
public static <F> Provider<F> newFactory( TypeLiteral<F> factoryType, TypeLiteral<?> implementationType) { Map<Method, AssistedConstructor<?>> factoryMethodToConstructor = createMethodMapping(factoryType, implementationType); if (!factoryMethodToConstructor.isEmpty()) { return new FactoryProvider<F>(factoryType, factoryMethodToConstructor); } else { BindingCollector collector = new BindingCollector(); // Preserving backwards-compatibility: Map all return types in a factory // interface to the passed implementation type. Errors errors = new Errors(); Key<?> implementationKey = Key.get(implementationType); if (implementationType != null) { try { for (Method method : factoryType.getRawType().getMethods()) { Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors); if (!implementationKey.equals(returnType)) { collector.addBinding(returnType, implementationType); } } } catch (ErrorsException e) { throw new ConfigurationException(e.getErrors().getMessages()); } } return new FactoryProvider2<F>(factoryType, collector); } }
private <T> ProviderMethod<T> createProviderMethod(Binder binder, Method method, Annotation annotation) { binder = binder.withSource(method); Errors errors = new Errors(method); // prepare the parameter providers InjectionPoint point = InjectionPoint.forMethod(method, typeLiteral); List<Dependency<?>> dependencies = point.getDependencies(); List<Provider<?>> parameterProviders = Lists.newArrayList(); for (Dependency<?> dependency : point.getDependencies()) { parameterProviders.add(binder.getProvider(dependency)); } @SuppressWarnings("unchecked") // Define T as the method's return type. TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method); Key<T> key = getKey(errors, returnType, method, method.getAnnotations()); try { key = scanner.prepareMethod(binder, annotation, key, point); } catch (Throwable t) { binder.addError(t); } Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations()); for (Message message : errors.getMessages()) { binder.addError(message); } return ProviderMethod.create(key, method, delegate, ImmutableSet.copyOf(dependencies), parameterProviders, scopeAnnotation, skipFastClassGeneration, annotation); }
private <T> ProviderMethod<T> createProviderMethod( Binder binder, Method method, Annotation annotation) { binder = binder.withSource(method); Errors errors = new Errors(method); // prepare the parameter providers InjectionPoint point = InjectionPoint.forMethod(method, typeLiteral); @SuppressWarnings("unchecked") // Define T as the method's return type. TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method); Key<T> key = getKey(errors, returnType, method, method.getAnnotations()); try { key = scanner.prepareMethod(binder, annotation, key, point); } catch (Throwable t) { binder.addError(t); } Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations()); for (Message message : errors.getMessages()) { binder.addError(message); } return ProviderMethod.create( key, method, delegate, ImmutableSet.copyOf(point.getDependencies()), scopeAnnotation, skipFastClassGeneration, annotation); }
private <T> ProviderMethod<T> createProviderMethod( Binder binder, Method method, Annotation annotation) { binder = binder.withSource(method); Errors errors = new Errors(method); // prepare the parameter providers InjectionPoint point = InjectionPoint.forMethod(method, typeLiteral); @SuppressWarnings("unchecked") // Define T as the method's return type. TypeLiteral<T> returnType = (TypeLiteral<T>) typeLiteral.getReturnType(method); Key<T> key = getKey(errors, returnType, method, method.getAnnotations()); try { key = scanner.prepareMethod(binder, annotation, key, point); } catch (Throwable t) { binder.addError(t); } Class<? extends Annotation> scopeAnnotation = Annotations.findScopeAnnotation(errors, method.getAnnotations()); for (Message message : errors.getMessages()) { binder.addError(message); } return ProviderMethod.create( key, method, delegate, ImmutableSet.copyOf(point.getDependencies()), scopeAnnotation, skipFastClassGeneration, annotation); }