@Test public void nonExistentStringBindNotOK() throws BindException, InjectionException { thrown.expect(ClassHierarchyException.class); thrown.expectMessage("ConfigurationModule refers to unknown class: i.do.not.exist"); new MyBadConfigurationModule().bindImplementation(Foo.class, "i.do.not.exist").build(); }
@SuppressWarnings({"unchecked", "rawtypes"}) public Configuration build() throws BindException { final ConfigurationModule c = deepCopy(); if (!c.reqSet.containsAll(c.builder.reqDecl)) { final Set<Field> missingSet = new MonotonicHashSet<>(); for (final Field f : c.builder.reqDecl) { if (!c.reqSet.contains(f)) { missingSet.add(f); } } throw new BindException( "Attempt to build configuration before setting required option(s): " + builder.toString(missingSet)); } for (final Class<?> clazz : c.builder.freeImpls.keySet()) { final Impl<?> i = c.builder.freeImpls.get(clazz); boolean foundOne = false; if (c.setImpls.containsKey(i)) { if (c.setImpls.get(i) != null) { c.builder.b.bind(clazz, c.setImpls.get(i)); foundOne = true; } } else if (c.setLateImpls.containsKey(i)) { if (c.setLateImpls.get(i) != null) { c.builder.b.bind(ReflectionUtilities.getFullName(clazz), c.setLateImpls.get(i)); foundOne = true; } } else if (c.setImplSets.containsKey(i) || c.setLateImplSets.containsKey(i)) { if (c.setImplSets.getValuesForKey(i) != null) { for (final Class<?> clz : c.setImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, (Class) clz); } foundOne = true; } if (c.setLateImplSets.getValuesForKey(i) != null) { for (final String s : c.setLateImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, s); } foundOne = true; } } else if (c.setImplLists.containsKey(i)) { if (c.setImplLists.get(i) != null) { c.builder.b.bindList((Class) clazz, c.setImplLists.get(i)); foundOne = true; } } if(!foundOne && !(i instanceof OptionalImpl)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredImplementation of the " + clazz + ". Check that you don't pass null as an implementation value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } for (final Class<? extends Name<?>> clazz : c.builder.freeParams.keySet()) { final Param<?> p = c.builder.freeParams.get(clazz); final String s = c.setParams.get(p); boolean foundOne = false; if (s != null) { c.builder.b.bindNamedParameter(clazz, s); foundOne = true; } final List list = c.setParamLists.get(p); if (list != null) { c.builder.b.bindList((Class) clazz, list); foundOne = true; } for (final String paramStr : c.setParamSets.getValuesForKey(p)) { c.builder.b.bindSetEntry((Class) clazz, paramStr); foundOne = true; } if (!foundOne && !(p instanceof OptionalParameter)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredParameter of the " + clazz + ". Check that you don't pass null as the parameter value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } return c.builder.b.build(); }
ConfigurationModule { @SuppressWarnings({"unchecked", "rawtypes"}) public Configuration build() throws BindException { final ConfigurationModule c = deepCopy(); if (!c.reqSet.containsAll(c.builder.reqDecl)) { final Set<Field> missingSet = new MonotonicHashSet<>(); for (final Field f : c.builder.reqDecl) { if (!c.reqSet.contains(f)) { missingSet.add(f); } } throw new BindException( "Attempt to build configuration before setting required option(s): " + builder.toString(missingSet)); } for (final Class<?> clazz : c.builder.freeImpls.keySet()) { final Impl<?> i = c.builder.freeImpls.get(clazz); boolean foundOne = false; if (c.setImpls.containsKey(i)) { if (c.setImpls.get(i) != null) { c.builder.b.bind(clazz, c.setImpls.get(i)); foundOne = true; } } else if (c.setLateImpls.containsKey(i)) { if (c.setLateImpls.get(i) != null) { c.builder.b.bind(ReflectionUtilities.getFullName(clazz), c.setLateImpls.get(i)); foundOne = true; } } else if (c.setImplSets.containsKey(i) || c.setLateImplSets.containsKey(i)) { if (c.setImplSets.getValuesForKey(i) != null) { for (final Class<?> clz : c.setImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, (Class) clz); } foundOne = true; } if (c.setLateImplSets.getValuesForKey(i) != null) { for (final String s : c.setLateImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, s); } foundOne = true; } } else if (c.setImplLists.containsKey(i)) { if (c.setImplLists.get(i) != null) { c.builder.b.bindList((Class) clazz, c.setImplLists.get(i)); foundOne = true; } } if(!foundOne && !(i instanceof OptionalImpl)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredImplementation of the " + clazz + ". Check that you don't pass null as an implementation value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } for (final Class<? extends Name<?>> clazz : c.builder.freeParams.keySet()) { final Param<?> p = c.builder.freeParams.get(clazz); final String s = c.setParams.get(p); boolean foundOne = false; if (s != null) { c.builder.b.bindNamedParameter(clazz, s); foundOne = true; } final List list = c.setParamLists.get(p); if (list != null) { c.builder.b.bindList((Class) clazz, list); foundOne = true; } for (final String paramStr : c.setParamSets.getValuesForKey(p)) { c.builder.b.bindSetEntry((Class) clazz, paramStr); foundOne = true; } if (!foundOne && !(p instanceof OptionalParameter)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredParameter of the " + clazz + ". Check that you don't pass null as the parameter value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } return c.builder.b.build(); } }
ConfigurationModule { @SuppressWarnings({"unchecked", "rawtypes"}) public Configuration build() throws BindException { final ConfigurationModule c = deepCopy(); if (!c.reqSet.containsAll(c.builder.reqDecl)) { final Set<Field> missingSet = new MonotonicHashSet<>(); for (final Field f : c.builder.reqDecl) { if (!c.reqSet.contains(f)) { missingSet.add(f); } } throw new BindException( "Attempt to build configuration before setting required option(s): " + builder.toString(missingSet)); } for (final Class<?> clazz : c.builder.freeImpls.keySet()) { final Impl<?> i = c.builder.freeImpls.get(clazz); boolean foundOne = false; if (c.setImpls.containsKey(i)) { if (c.setImpls.get(i) != null) { c.builder.b.bind(clazz, c.setImpls.get(i)); foundOne = true; } } else if (c.setLateImpls.containsKey(i)) { if (c.setLateImpls.get(i) != null) { c.builder.b.bind(ReflectionUtilities.getFullName(clazz), c.setLateImpls.get(i)); foundOne = true; } } else if (c.setImplSets.containsKey(i) || c.setLateImplSets.containsKey(i)) { if (c.setImplSets.getValuesForKey(i) != null) { for (final Class<?> clz : c.setImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, (Class) clz); } foundOne = true; } if (c.setLateImplSets.getValuesForKey(i) != null) { for (final String s : c.setLateImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, s); } foundOne = true; } } else if (c.setImplLists.containsKey(i)) { if (c.setImplLists.get(i) != null) { c.builder.b.bindList((Class) clazz, c.setImplLists.get(i)); foundOne = true; } } if(!foundOne && !(i instanceof OptionalImpl)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredImplementation of the " + clazz + ". Check that you don't pass null as an implementation value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } for (final Class<? extends Name<?>> clazz : c.builder.freeParams.keySet()) { final Param<?> p = c.builder.freeParams.get(clazz); final String s = c.setParams.get(p); boolean foundOne = false; if (s != null) { c.builder.b.bindNamedParameter(clazz, s); foundOne = true; } final List list = c.setParamLists.get(p); if (list != null) { c.builder.b.bindList((Class) clazz, list); foundOne = true; } for (final String paramStr : c.setParamSets.getValuesForKey(p)) { c.builder.b.bindSetEntry((Class) clazz, paramStr); foundOne = true; } if (!foundOne && !(p instanceof OptionalParameter)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredParameter of the " + clazz + ". Check that you don't pass null as the parameter value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } return c.builder.b.build(); } protected  ConfigurationModule(final ConfigurationModuleBuilder builder); }
ConfigurationModule { @SuppressWarnings({"unchecked", "rawtypes"}) public Configuration build() throws BindException { final ConfigurationModule c = deepCopy(); if (!c.reqSet.containsAll(c.builder.reqDecl)) { final Set<Field> missingSet = new MonotonicHashSet<>(); for (final Field f : c.builder.reqDecl) { if (!c.reqSet.contains(f)) { missingSet.add(f); } } throw new BindException( "Attempt to build configuration before setting required option(s): " + builder.toString(missingSet)); } for (final Class<?> clazz : c.builder.freeImpls.keySet()) { final Impl<?> i = c.builder.freeImpls.get(clazz); boolean foundOne = false; if (c.setImpls.containsKey(i)) { if (c.setImpls.get(i) != null) { c.builder.b.bind(clazz, c.setImpls.get(i)); foundOne = true; } } else if (c.setLateImpls.containsKey(i)) { if (c.setLateImpls.get(i) != null) { c.builder.b.bind(ReflectionUtilities.getFullName(clazz), c.setLateImpls.get(i)); foundOne = true; } } else if (c.setImplSets.containsKey(i) || c.setLateImplSets.containsKey(i)) { if (c.setImplSets.getValuesForKey(i) != null) { for (final Class<?> clz : c.setImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, (Class) clz); } foundOne = true; } if (c.setLateImplSets.getValuesForKey(i) != null) { for (final String s : c.setLateImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, s); } foundOne = true; } } else if (c.setImplLists.containsKey(i)) { if (c.setImplLists.get(i) != null) { c.builder.b.bindList((Class) clazz, c.setImplLists.get(i)); foundOne = true; } } if(!foundOne && !(i instanceof OptionalImpl)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredImplementation of the " + clazz + ". Check that you don't pass null as an implementation value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } for (final Class<? extends Name<?>> clazz : c.builder.freeParams.keySet()) { final Param<?> p = c.builder.freeParams.get(clazz); final String s = c.setParams.get(p); boolean foundOne = false; if (s != null) { c.builder.b.bindNamedParameter(clazz, s); foundOne = true; } final List list = c.setParamLists.get(p); if (list != null) { c.builder.b.bindList((Class) clazz, list); foundOne = true; } for (final String paramStr : c.setParamSets.getValuesForKey(p)) { c.builder.b.bindSetEntry((Class) clazz, paramStr); foundOne = true; } if (!foundOne && !(p instanceof OptionalParameter)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredParameter of the " + clazz + ". Check that you don't pass null as the parameter value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } return c.builder.b.build(); } protected  ConfigurationModule(final ConfigurationModuleBuilder builder); final ConfigurationModule set(final Impl<T> opt, final Class<? extends T> impl); final ConfigurationModule set(final Impl<T> opt, final String impl); final ConfigurationModule set(final Impl<List> opt, final List implList); final ConfigurationModule set(final Param<T> opt, final Class<? extends T> val); final ConfigurationModule set(final Param<Boolean> opt, final boolean val); final ConfigurationModule set(final Param<? extends Number> opt, final Number val); final ConfigurationModule set(final Param<T> opt, final String val); final ConfigurationModule setMultiple(final Param<T> opt, final Iterable<String> values); final ConfigurationModule setMultiple(final Param<T> opt, final String... values); final ConfigurationModule set(final Param<List> opt, final List implList); @SuppressWarnings({"unchecked", "rawtypes"}) Configuration build(); Set<NamedParameterNode<?>> getBoundNamedParameters(); List<Entry<String, String>> toStringPairs(); String toPrettyString(); void assertStaticClean(); ConfigurationModuleBuilder getBuilder(); }
ConfigurationModule { @SuppressWarnings({"unchecked", "rawtypes"}) public Configuration build() throws BindException { final ConfigurationModule c = deepCopy(); if (!c.reqSet.containsAll(c.builder.reqDecl)) { final Set<Field> missingSet = new MonotonicHashSet<>(); for (final Field f : c.builder.reqDecl) { if (!c.reqSet.contains(f)) { missingSet.add(f); } } throw new BindException( "Attempt to build configuration before setting required option(s): " + builder.toString(missingSet)); } for (final Class<?> clazz : c.builder.freeImpls.keySet()) { final Impl<?> i = c.builder.freeImpls.get(clazz); boolean foundOne = false; if (c.setImpls.containsKey(i)) { if (c.setImpls.get(i) != null) { c.builder.b.bind(clazz, c.setImpls.get(i)); foundOne = true; } } else if (c.setLateImpls.containsKey(i)) { if (c.setLateImpls.get(i) != null) { c.builder.b.bind(ReflectionUtilities.getFullName(clazz), c.setLateImpls.get(i)); foundOne = true; } } else if (c.setImplSets.containsKey(i) || c.setLateImplSets.containsKey(i)) { if (c.setImplSets.getValuesForKey(i) != null) { for (final Class<?> clz : c.setImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, (Class) clz); } foundOne = true; } if (c.setLateImplSets.getValuesForKey(i) != null) { for (final String s : c.setLateImplSets.getValuesForKey(i)) { c.builder.b.bindSetEntry((Class) clazz, s); } foundOne = true; } } else if (c.setImplLists.containsKey(i)) { if (c.setImplLists.get(i) != null) { c.builder.b.bindList((Class) clazz, c.setImplLists.get(i)); foundOne = true; } } if(!foundOne && !(i instanceof OptionalImpl)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredImplementation of the " + clazz + ". Check that you don't pass null as an implementation value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } for (final Class<? extends Name<?>> clazz : c.builder.freeParams.keySet()) { final Param<?> p = c.builder.freeParams.get(clazz); final String s = c.setParams.get(p); boolean foundOne = false; if (s != null) { c.builder.b.bindNamedParameter(clazz, s); foundOne = true; } final List list = c.setParamLists.get(p); if (list != null) { c.builder.b.bindList((Class) clazz, list); foundOne = true; } for (final String paramStr : c.setParamSets.getValuesForKey(p)) { c.builder.b.bindSetEntry((Class) clazz, paramStr); foundOne = true; } if (!foundOne && !(p instanceof OptionalParameter)) { final IllegalStateException e = new IllegalStateException("Cannot find the value for the RequiredParameter of the " + clazz + ". Check that you don't pass null as the parameter value."); LOG.log(Level.SEVERE, "Failed to build configuration", e); throw e; } } return c.builder.b.build(); } protected  ConfigurationModule(final ConfigurationModuleBuilder builder); final ConfigurationModule set(final Impl<T> opt, final Class<? extends T> impl); final ConfigurationModule set(final Impl<T> opt, final String impl); final ConfigurationModule set(final Impl<List> opt, final List implList); final ConfigurationModule set(final Param<T> opt, final Class<? extends T> val); final ConfigurationModule set(final Param<Boolean> opt, final boolean val); final ConfigurationModule set(final Param<? extends Number> opt, final Number val); final ConfigurationModule set(final Param<T> opt, final String val); final ConfigurationModule setMultiple(final Param<T> opt, final Iterable<String> values); final ConfigurationModule setMultiple(final Param<T> opt, final String... values); final ConfigurationModule set(final Param<List> opt, final List implList); @SuppressWarnings({"unchecked", "rawtypes"}) Configuration build(); Set<NamedParameterNode<?>> getBoundNamedParameters(); List<Entry<String, String>> toStringPairs(); String toPrettyString(); void assertStaticClean(); ConfigurationModuleBuilder getBuilder();  }