use of com.google.inject.internal.ErrorsException in project roboguice by roboguice.
the class FactoryProvider method newFactory.
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);
}
}
use of com.google.inject.internal.ErrorsException in project guice by google.
the class FactoryProvider method newFactory.
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);
}
}
use of com.google.inject.internal.ErrorsException in project guice by google.
the class InjectionPoint method forMember.
private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
Errors errors = new Errors(member);
List<Dependency<?>> dependencies = Lists.newArrayList();
int index = 0;
for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
try {
Annotation[] parameterAnnotations = paramterAnnotations[index];
Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
index++;
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
return ImmutableList.copyOf(dependencies);
}
use of com.google.inject.internal.ErrorsException in project roboguice by roboguice.
the class InjectionPoint method forMember.
private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
Errors errors = new Errors(member);
Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator();
List<Dependency<?>> dependencies = Lists.newArrayList();
int index = 0;
for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
try {
Annotation[] parameterAnnotations = annotationsIterator.next();
Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
index++;
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
return ImmutableList.copyOf(dependencies);
}
Aggregations