JavaClassBuilder implements ClassBuilder { public String getConfigClass(String className) { return getHeader() + "\n\n" + getRootClassDeclaration(root, className) + "\n\n" + indentCode(INDENTATION, getFrameworkCode()) + "\n\n" + ConfigGenerator.generateContent(INDENTATION, root, true) + "\n" + "}\n"; } JavaClassBuilder(InnerCNode root, NormalizedDefinition nd, File destDir, String rawPackagePrefix); @Override void createConfigClasses(); String getConfigClass(String className); String className(); String javaPackage();  }
@Ignore @Test public void visual_inspection_of_generated_class() { final String testDefinition = "version=1\n" + "namespace=test\n" + "p path\n" + "pathArr[] path\n" + "u url\n" + "urlArr[] url\n" + "f file\n" + "fileArr[] file\n" + "i int default=0\n" + "# A long value\n" + "l long default=0\n" + "s string default=\"\"\n" + "b bool\n" + "# An enum value\n" + "e enum {A, B, C}\n" + "intArr[] int\n" + "boolArr[] bool\n" + "enumArr[] enum {FOO, BAR}\n" + "intMap{} int\n" + "# A struct\n" + "# with multi-line\n" + "# comment and \"quotes\".\n" + "myStruct.i int\n" + "myStruct.s string\n" + "# An inner array\n" + "myArr[].i int\n" + "myArr[].newStruct.s string\n" + "myArr[].newStruct.b bool\n" + "myArr[].intArr[] int\n" + "# An inner map\n" + "myMap{}.i int\n" + "myMap{}.newStruct.s string\n" + "myMap{}.newStruct.b bool\n" + "myMap{}.intArr[] int\n" + "intMap{} int\n"; DefParser parser = new DefParser("test", new StringReader(testDefinition)); InnerCNode root = parser.getTree(); JavaClassBuilder builder = new JavaClassBuilder(root, parser.getNormalizedDefinition(), null, null); String configClass = builder.getConfigClass("TestConfig"); System.out.print(configClass); }
@Test public void verify_generated_class_against_reference() throws IOException { String testDefinition = String.join("\n", Files.readAllLines(FileSystems.getDefault().getPath(DEF_NAME))); List<String> referenceClassLines = Files.readAllLines(FileSystems.getDefault().getPath(REFERENCE_NAME)); DefParser parser = new DefParser("allfeatures", new StringReader(testDefinition)); InnerCNode root = parser.getTree(); JavaClassBuilder builder = new JavaClassBuilder(root, parser.getNormalizedDefinition(), null, null); String[] configClassLines = builder.getConfigClass("AllfeaturesConfig").split("\n"); for (int i = 0; i < referenceClassLines.size(); i++) { if (configClassLines.length <= i) fail("Missing lines i generated config class. First missing line:\n" + referenceClassLines.get(i)); assertEquals("Line " + i, referenceClassLines.get(i), configClassLines[i]); } }