Source:
<code>private void generateCommands() throws IOException, TemplateException { if (ConverterUtil.hasContent(spec.getTypes())) { for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); if (ConverterUtil.hasContent(typeEntry.getEnumConstants())) { generateTypeEnumConstant(typeEntry); generateTypeEnumConstantMatcher(typeEntry); } } final HashSet generatedTypesResponses = new HashSet(); int depth = 0; <START> while (generatedTypesResponses.size() != spec.getTypes().values().size() && depth++ < 10) { <END> for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { if (ConverterUtil.hasContent(ds3TypeEntry.getElements())) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); if (typeEntry.isPrimitiveType() || typeEntry.containsExistingElements(generatedTypesResponses)) { generatedTypesResponses.add(typeEntry.getName()); } } } } for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); generateElementResponseParser(typeEntry); } for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { if (ConverterUtil.hasContent(ds3TypeEntry.getElements())) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); generateTypeElement(typeEntry); generateFreeTypeElementPrototype(typeEntry); generateFreeTypeElement(typeEntry); } } } if (ConverterUtil.hasContent(spec.getRequests())) { for (final Ds3Request request : spec.getRequests()) { generateRequest(request); } } }</code><technical_language>I assume depth < 10 is prevent infinite loop. such, if depth get high, error log message added denote unexpected state</technical_language>

Target:
private void generateCommands() throws IOException, TemplateException { if (ConverterUtil.hasContent(spec.getTypes())) { for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); if (ConverterUtil.hasContent(typeEntry.getEnumConstants())) { generateTypeTemplate(typeEntry, "TypeEnumConstant.ftl"); generateTypeTemplate(typeEntry, "TypeEnumConstantMatcher.ftl"); } } final ImmutableSet.Builder<String> generatedTypesResponses = new ImmutableSet.Builder<>(); LOG.debug(generatedTypesResponses.build().size() + " vs " + spec.getTypes().values().size()); for (int depth = 0; generatedTypesResponses.build().size() < spec.getTypes().values().size(); depth++) { for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { if (ConverterUtil.hasContent(ds3TypeEntry.getElements())) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); if (generatedTypesResponses.build().contains(typeEntry.getName())) { continue; } if (TypeHelper.isPrimitiveType(typeEntry) || TypeHelper.containsExistingElements(typeEntry, generatedTypesResponses.build())) { generateTypeTemplate(typeEntry, "ResponseParser.ftl"); generatedTypesResponses.add(typeEntry.getName()); } } } if (depth > 6) { LOG.warn("generating ResponseParsers up to depth " + depth + ", warning for potential infinite loop."); break; } } for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) { if (ConverterUtil.hasContent(ds3TypeEntry.getElements())) { final Type typeEntry = TypeConverter.toType(ds3TypeEntry); generateTypeTemplate(typeEntry, "TypeElement.ftl"); generateTypeTemplate(typeEntry, "FreeTypeElementPrototype.ftl"); generateTypeTemplate(typeEntry, "FreeTypeElement.ftl"); } } } if (ConverterUtil.hasContent(spec.getRequests())) { for (final Ds3Request request : spec.getRequests()) { generateRequest(request); } } }