private static void addImports(AbstractModule module, String packageName) { @SuppressWarnings("unchecked") Set<String> imports = module.get(Set.class, CodegenModule.IMPORTS); if (imports.isEmpty()) { imports = ImmutableSet.of(packageName); } else { Set<String> old = imports; imports = Sets.newHashSet(); imports.addAll(old); imports.add(packageName); } module.bind(CodegenModule.IMPORTS, imports); }
public AbstractModule() { configure(); }
@SuppressWarnings("unchecked") public final <T> T get(Class<T> iface) { if (instances.containsKey(iface)) { return (T) instances.get(iface); } else if (bindings.containsKey(iface)) { Class<?> implementation = bindings.get(iface); T instance = (T) createInstance(implementation); instances.put(iface, instance); return instance; } else { throw new IllegalArgumentException(iface.getName() + " is not registered"); } }
Object[] args = new Object[constructor.getParameterTypes().length]; for (int i = 0; i < constructor.getParameterTypes().length; i++) { Named named = getNamedAnnotation(constructor.getParameterAnnotations()[i]); if (named != null) { args[i] = get(constructor.getParameterTypes()[i], named.value()); } else { args[i] = get(constructor.getParameterTypes()[i]);
/** * Register spatial types to the given codegen module * * @param module module to be customized for spatial support */ public static void addSupport(AbstractModule module) { module.bindInstance(SQLCodegenModule.ENTITYPATH_TYPE, RelationalPathSpatial.class); registerTypes(module.get(Configuration.class)); registerTypes(module.get(TypeMappings.class)); addImports(module); }
public final <T> AbstractModule bind(Class<T> clazz) { if (clazz.isInterface()) { throw new IllegalArgumentException("Interfaces can't be instantiated"); } bind(clazz, clazz); return this; }
@SuppressWarnings("unchecked") private static void addImports(AbstractModule module) { Set<String> imports = module.get(Set.class, CodegenModule.IMPORTS); String packageName = GeometryPath.class.getPackage().getName(); if (imports.isEmpty()) { imports = ImmutableSet.of(packageName); } else { Set<String> old = imports; imports = Sets.newHashSet(); imports.addAll(old); imports.add(packageName); } module.bind(CodegenModule.IMPORTS, imports); }
@SuppressWarnings("unchecked") public final <T> T get(Class<T> iface, String name) { if (namedInstances.containsKey(name)) { return (T) namedInstances.get(name); } else if (namedBindings.containsKey(name)) { Class<?> implementation = namedBindings.get(name); if (implementation != null) { T instance = (T) createInstance(implementation); namedInstances.put(name, instance); return instance; } else { return null; } } else { throw new IllegalArgumentException(iface.getName() + " " + name + " is not registered"); } }