JavaClassBuilder implements ClassBuilder { static String createUniqueSymbol(CNode node, String basis) { Set<String> usedSymbols = Arrays.stream(node.getChildren()).map(CNode::getName).collect(Collectors.toSet()); Random rng = new Random(); for (int i = 1;; i++) { String candidate = (i < basis.length()) ? basis.substring(0, i) : ReservedWords.INTERNAL_PREFIX + basis + rng.nextInt(Integer.MAX_VALUE); if (usedSymbols.contains(candidate) == false) { return candidate; } } } JavaClassBuilder(InnerCNode root, NormalizedDefinition nd, File destDir, String rawPackagePrefix); @Override void createConfigClasses(); String getConfigClass(String className); String className(); String javaPackage();  }
@Test public void testCreateUniqueSymbol() { final String testDefinition = "version=1\n" + "namespace=test\n" + "m int\n" + "n int\n"; InnerCNode root = new DefParser("test", new StringReader(testDefinition)).getTree(); assertThat(createUniqueSymbol(root, "foo"), is("f")); assertThat(createUniqueSymbol(root, "name"), is("na")); assertTrue(createUniqueSymbol(root, "m").startsWith(ReservedWords.INTERNAL_PREFIX + "m")); assertTrue(createUniqueSymbol(root, "my").startsWith(ReservedWords.INTERNAL_PREFIX + "my")); }