use of com.google.inject.TypeLiteral in project infrautils by opendaylight.
the class DiagStatusTestModule method configureBindings.
@Override
protected void configureBindings() throws UnknownHostException {
bind(DiagStatusService.class).to(DiagStatusServiceImpl.class);
bind(new TypeLiteral<List<ServiceStatusProvider>>() {
}).toInstance(Collections.emptyList());
bind(SystemReadyMonitor.class).annotatedWith(OsgiService.class).toInstance(new SystemReadyMonitor() {
@Override
public void registerListener(SystemReadyListener listener) {
// NOOP
}
@Override
public SystemState getSystemState() {
return SystemState.ACTIVE;
}
});
bind(DiagStatusServiceMBean.class).to(DiagStatusServiceMBeanImpl.class);
}
use of com.google.inject.TypeLiteral in project ovirt-engine by oVirt.
the class UiCommonModule method bindModels.
void bindModels() {
// all model providers should be bound as singletons
install(new DataCenterModule());
install(new StorageModule());
install(new ClusterModule());
install(new VirtualMachineModule());
install(new HostModule());
install(new PoolModule());
install(new TemplateModule());
install(new UserModule());
install(new EventModule());
install(new QuotaModule());
install(new VolumeModule());
install(new DiskModule());
install(new NetworkModule());
install(new ProviderModule());
install(new VnicProfileModule());
install(new MacPoolModule());
install(new ErrataModule());
install(new SessionModule());
bindCommonModels();
// BookmarkListModel
bind(BookmarkModelProvider.class).in(Singleton.class);
// TagListModel
bind(TagModelProvider.class).in(Singleton.class);
// AlertListModel
bind(AlertModelProvider.class).in(Singleton.class);
// TaskListModel
bind(TaskModelProvider.class).in(Singleton.class);
// RoleListModel
bind(RoleModelProvider.class).in(Singleton.class);
// RolePermissionListModel
bind(RolePermissionModelProvider.class).in(Singleton.class);
// SystemPermissionListModel
bind(SystemPermissionModelProvider.class).in(Singleton.class);
// ClusterPolicyListModel
bind(ClusterPolicyModelProvider.class).in(Singleton.class);
// ClusterPolicyClusterListModel
bind(ClusterPolicyClusterModelProvider.class).in(Singleton.class);
bind(InstanceTypeModelProvider.class).in(Singleton.class);
bind(new TypeLiteral<DetailTabModelProvider<InstanceTypeListModel, InstanceTypeGeneralModel>>() {
}).in(Singleton.class);
// disk profiles permissions
bind(DiskProfilePermissionModelProvider.class).in(Singleton.class);
// cpu profiles permissions
bind(CpuProfilePermissionModelProvider.class).in(Singleton.class);
}
use of com.google.inject.TypeLiteral in project vespa by vespa-engine.
the class TypeCheckers method createChecker.
// this is festooned with instance checkes before all the casting
@SuppressWarnings("unchecked")
private static OperatorTypeChecker createChecker(Operator parent, int idx, Object value) {
if (value instanceof TypeLiteral) {
TypeLiteral<?> lit = (TypeLiteral<?>) value;
Class<?> raw = lit.getRawType();
if (List.class.isAssignableFrom(raw)) {
Preconditions.checkArgument(lit.getType() instanceof ParameterizedType, "TypeLiteral without a ParameterizedType for List");
ParameterizedType type = (ParameterizedType) lit.getType();
TypeLiteral<?> arg = TypeLiteral.get(type.getActualTypeArguments()[0]);
if (OperatorNode.class.isAssignableFrom(arg.getRawType())) {
Preconditions.checkArgument(arg.getType() instanceof ParameterizedType, "Type spec must be List<OperatorNode<?>>");
Class<? extends Operator> optype = (Class<? extends Operator>) TypeLiteral.get(((ParameterizedType) arg.getType()).getActualTypeArguments()[0]).getRawType();
return new OperatorNodeListTypeChecker(parent, idx, optype, ImmutableSet.<Operator>of());
} else {
return new JavaListTypeChecker(parent, idx, arg.getRawType());
}
}
throw new IllegalArgumentException("don't know how to handle TypeLiteral " + value);
}
if (value instanceof Class) {
Class<?> clazz = (Class<?>) value;
if (Operator.class.isAssignableFrom(clazz)) {
return new NodeTypeChecker(parent, idx, (Class<? extends Operator>) clazz, ImmutableSet.<Operator>of());
} else {
return new JavaTypeChecker(parent, idx, clazz);
}
} else if (value instanceof Operator) {
Operator operator = (Operator) value;
Class<? extends Operator> clazz = operator.getClass();
Set<? extends Operator> allowed;
if (Enum.class.isInstance(value)) {
Class<? extends Enum> enumClazz = (Class<? extends Enum>) clazz;
allowed = (Set<? extends Operator>) EnumSet.of(enumClazz.cast(value));
} else {
allowed = ImmutableSet.of(operator);
}
return new NodeTypeChecker(parent, idx, clazz, allowed);
} else if (value instanceof EnumSet) {
EnumSet<?> v = (EnumSet<?>) value;
Enum elt = Iterables.get(v, 0);
if (elt instanceof Operator) {
Class<? extends Operator> opclass = (Class<? extends Operator>) elt.getClass();
Set<? extends Operator> allowed = (Set<? extends Operator>) v;
return new NodeTypeChecker(parent, idx, opclass, allowed);
}
} else if (value instanceof Set) {
// Set<Class<?>>
return new JavaUnionTypeChecker(parent, idx, (Set<Class<?>>) value);
}
throw new IllegalArgumentException("I don't know how to create a checker from " + value);
}
use of com.google.inject.TypeLiteral in project google-gin by gwtplus.
the class FactoryBinding method constructorHasMatchingParams.
/**
* Matching logic for {@literal @}{@link AssistedInject} constructor and
* method parameters.
*
* This returns true if and only if all @Assisted parameters in the
* constructor exactly match (in any order) all @Assisted parameters the
* method's parameter.
*/
private boolean constructorHasMatchingParams(TypeLiteral<?> type, Constructor<?> constructor, List<Key<?>> paramList, Errors errors) throws ErrorsException {
List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
int p = 0;
List<Key<?>> constructorKeys = new ArrayList<Key<?>>();
for (TypeLiteral<?> param : params) {
constructorKeys.add(getKey(param, constructor, paramAnnotations[p++], errors));
}
// Require that every key exist in the constructor to match up exactly.
for (Key<?> key : paramList) {
// If it didn't exist in the constructor set, we can't use it.
if (!constructorKeys.remove(key)) {
return false;
}
}
// If any keys remain and their annotation is Assisted, we can't use it.
for (Key<?> key : constructorKeys) {
if (key.getAnnotationType() == Assisted.class) {
return false;
}
}
// All @Assisted params match up to the method's parameters.
return true;
}
use of com.google.inject.TypeLiteral in project google-gin by gwtplus.
the class FactoryBinding method injectConstructorHasMatchingParams.
/**
* Matching logic for {@literal @}{@link Inject} constructor and method
* parameters.
*
* This returns true if all assisted parameters required by the constructor
* are provided by the factory method.
*/
private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type, Constructor<?> constructor, List<Key<?>> paramList, Errors errors) throws ErrorsException {
List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
int p = 0;
for (TypeLiteral<?> param : params) {
Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors);
if (paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) {
return false;
}
}
return true;
}
Aggregations