@Test public void testTraverseTree() throws IOException { File defFile = new File(DEF_NAME); CNode root = new DefParser("test", new FileReader(defFile)).getTree(); assertNotNull(root); CNode[] children = root.getChildren(); assertThat(children.length, is(34)); int numGrandChildren = 0; int numGreatGrandChildren = 0; for (CNode child : children) { CNode[] childsChildren = child.getChildren(); numGrandChildren += childsChildren.length; for (CNode grandChild : childsChildren) { numGreatGrandChildren += grandChild.getChildren().length; } } assertThat(numGrandChildren, is(14)); assertThat(numGreatGrandChildren, is(6)); CNode myArray = root.getChild("myArray"); assertThat(myArray.getChildren().length, is(5)); LeafCNode myArrayInt = (LeafCNode) myArray.getChild("intVal"); assertThat(myArrayInt.getDefaultValue().getValue(), is("14")); LeafCNode myArrayEnum = (LeafCNode) myArray.getChild("enumVal"); assertThat(myArrayEnum.getDefaultValue().getValue(), is("TYPE")); CNode anotherArray = myArray.getChild("anotherArray"); assertThat(anotherArray.getChildren().length, is(1)); LeafCNode foo = (LeafCNode) anotherArray.getChild("foo"); assertThat(foo.getDefaultValue().getValue(), is("-4")); }
public InnerCNode getTree() throws CodegenRuntimeException { try { if (root == null) parse(); } catch (DefParserException | IOException e) { throw new CodegenRuntimeException("Error parsing or reading config definition." + e.getMessage(), e); } return root; }
DefParser { public InnerCNode getTree() throws CodegenRuntimeException { try { if (root == null) parse(); } catch (DefParserException | IOException e) { throw new CodegenRuntimeException("Error parsing or reading config definition." + e.getMessage(), e); } return root; } }
DefParser { public InnerCNode getTree() throws CodegenRuntimeException { try { if (root == null) parse(); } catch (DefParserException | IOException e) { throw new CodegenRuntimeException("Error parsing or reading config definition." + e.getMessage(), e); } return root; } DefParser(String name, Reader defReader); }
DefParser { public InnerCNode getTree() throws CodegenRuntimeException { try { if (root == null) parse(); } catch (DefParserException | IOException e) { throw new CodegenRuntimeException("Error parsing or reading config definition." + e.getMessage(), e); } return root; } DefParser(String name, Reader defReader); InnerCNode getTree(); NormalizedDefinition getNormalizedDefinition(); static void dumpTree(CNode root, String indent); }
DefParser { public InnerCNode getTree() throws CodegenRuntimeException { try { if (root == null) parse(); } catch (DefParserException | IOException e) { throw new CodegenRuntimeException("Error parsing or reading config definition." + e.getMessage(), e); } return root; } DefParser(String name, Reader defReader); InnerCNode getTree(); NormalizedDefinition getNormalizedDefinition(); static void dumpTree(CNode root, String indent); static final String DEFAULT_PACKAGE_PREFIX; static final Pattern versionPattern; static final Pattern namespacePattern; static final Pattern packagePattern; }