use of com.google.inject.ConfigurationException in project roboguice by roboguice.
the class InjectorImpl method getBinding.
/**
* Returns the binding for {@code key}
*/
public <T> BindingImpl<T> getBinding(Key<T> key) {
Errors errors = new Errors(key);
try {
BindingImpl<T> result = getBindingOrThrow(key, errors, JitLimitation.EXISTING_JIT);
errors.throwConfigurationExceptionIfErrorsExist();
return result;
} catch (ErrorsException e) {
throw new ConfigurationException(errors.merge(e.getErrors()).getMessages());
}
}
use of com.google.inject.ConfigurationException in project roboguice by roboguice.
the class BindingBuilder method toConstructor.
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> constructor, TypeLiteral<? extends S> type) {
checkNotNull(constructor, "constructor");
checkNotNull(type, "type");
checkNotTargetted();
BindingImpl<T> base = getBinding();
Set<InjectionPoint> injectionPoints;
try {
injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type);
} catch (ConfigurationException e) {
copyErrorsToBinder(e);
injectionPoints = e.getPartialValue();
}
try {
InjectionPoint constructorPoint = InjectionPoint.forConstructor(constructor, type);
setBinding(new ConstructorBindingImpl<T>(base.getKey(), base.getSource(), base.getScoping(), constructorPoint, injectionPoints));
} catch (ConfigurationException e) {
copyErrorsToBinder(e);
}
return this;
}
use of com.google.inject.ConfigurationException in project roboguice by roboguice.
the class MembersInjectorStore method createWithListeners.
/**
* Creates a new members injector and attaches both injection listeners and method aspects.
*/
private <T> MembersInjectorImpl<T> createWithListeners(TypeLiteral<T> type, Errors errors) throws ErrorsException {
int numErrorsBefore = errors.size();
Set<InjectionPoint> injectionPoints;
try {
injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type);
} catch (ConfigurationException e) {
errors.merge(e.getErrorMessages());
injectionPoints = e.getPartialValue();
}
ImmutableList<SingleMemberInjector> injectors = getInjectors(injectionPoints, errors);
errors.throwIfNewErrors(numErrorsBefore);
EncounterImpl<T> encounter = new EncounterImpl<T>(errors, injector.lookups);
Set<TypeListener> alreadySeenListeners = Sets.newHashSet();
for (TypeListenerBinding binding : typeListenerBindings) {
TypeListener typeListener = binding.getListener();
if (!alreadySeenListeners.contains(typeListener) && binding.getTypeMatcher().matches(type)) {
alreadySeenListeners.add(typeListener);
try {
typeListener.hear(type, encounter);
} catch (RuntimeException e) {
errors.errorNotifyingTypeListener(binding, type, e);
}
}
}
encounter.invalidate();
errors.throwIfNewErrors(numErrorsBefore);
return new MembersInjectorImpl<T>(injector, type, encounter, injectors);
}
use of com.google.inject.ConfigurationException in project opt4j by felixreimann.
the class Opt4JModule method configure.
/*
* (non-Javadoc)
*
* @see com.google.inject.AbstractModule#configure()
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
/**
* Configure injected constants.
*/
PropertyModule module = new PropertyModule(this);
for (Property property : module.getProperties()) {
for (Annotation annotation : property.getAnnotations()) {
if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null) {
Class<?> type = property.getType();
Object value = property.getValue();
ConstantBindingBuilder builder = bindConstant(annotation);
if (type.equals(Integer.TYPE)) {
builder.to((Integer) value);
} else if (type.equals(Long.TYPE)) {
builder.to((Long) value);
} else if (type.equals(Double.TYPE)) {
builder.to((Double) value);
} else if (type.equals(Float.TYPE)) {
builder.to((Float) value);
} else if (type.equals(Byte.TYPE)) {
builder.to((Byte) value);
} else if (type.equals(Short.TYPE)) {
builder.to((Short) value);
} else if (type.equals(Boolean.TYPE)) {
builder.to((Boolean) value);
} else if (type.equals(Character.TYPE)) {
builder.to((Character) value);
} else if (type.equals(String.class)) {
builder.to((String) value);
} else if (type.equals(Class.class)) {
builder.to((Class<?>) value);
} else if (value instanceof Enum<?>) {
builder.to((Enum) value);
} else {
String message = "Constant type not bindable: " + type + " of field " + property.getName() + " in module " + this.getClass().getName();
throw new ConfigurationException(Arrays.asList(new Message(message)));
}
}
}
}
multi(OptimizerStateListener.class);
multi(OptimizerIterationListener.class);
multi(IndividualStateListener.class);
config();
}
use of com.google.inject.ConfigurationException in project guice by google.
the class BindingBuilder method toConstructor.
@Override
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> constructor, TypeLiteral<? extends S> type) {
checkNotNull(constructor, "constructor");
checkNotNull(type, "type");
checkNotTargetted();
BindingImpl<T> base = getBinding();
Set<InjectionPoint> injectionPoints;
try {
injectionPoints = InjectionPoint.forInstanceMethodsAndFields(type);
} catch (ConfigurationException e) {
copyErrorsToBinder(e);
injectionPoints = e.getPartialValue();
}
try {
InjectionPoint constructorPoint = InjectionPoint.forConstructor(constructor, type);
setBinding(new ConstructorBindingImpl<T>(base.getKey(), base.getSource(), base.getScoping(), constructorPoint, injectionPoints));
} catch (ConfigurationException e) {
copyErrorsToBinder(e);
}
return this;
}
Aggregations