@Test public void testApplyDefToBuilderMismatches() throws Exception { FunctionTestConfig.Builder builder = createVariableAccessBuilderManyUnset(); InnerCNode targetDef = getDef(FunctionTestConfig.CONFIG_DEF_SCHEMA); targetDef.children().put("stringwithdef", LeafCNode.newInstance(new DefLine.Type("int"), targetDef, "stringwithdef", "1")); targetDef.children().put("int_val", LeafCNode.newInstance(new DefLine.Type("string"), targetDef, "int_val", "fooOO")); InstanceResolver.applyDef(builder, targetDef); try { FunctionTestConfig c = new FunctionTestConfig(builder); fail("No exception on incomplete builder"); } catch (Exception e) { } }
static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } } }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }  }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }   }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }    }