Source:
private void generateHeaderVersion(String type) { buffer.printf("public short %sHeaderVersion(short _version) {%n", type); buffer.incrementIndent(); buffer.printf("switch (apiKey) {%n"); buffer.incrementIndent(); for (Map.Entry<Short, ApiData> entry : apis.entrySet()) { short apiKey = entry.getKey(); buffer.printf("case %d:%n", apiKey); buffer.incrementIndent(); if (apiKey == 7) { buffer.printf("if (_version == 0) {%n"); buffer.incrementIndent(); buffer.printf("return (short) 0;%n"); buffer.decrementIndent(); buffer.printf("}%n"); } ApiData data = entry.getValue(); MessageSpec spec = null; if (type.equals("request")) { spec = data.requestSpec; } else if (type.equals("response")) { spec = data.responseSpec; } else { throw new RuntimeException("Invalid type " + type + " for generateHeaderVersion"); } if (spec == null) { throw new RuntimeException("failed to find " + type + " for API key " + apiKey); } VersionConditional.forVersions(spec.flexibleVersions(), spec.validVersions()). ifMember(__ -> { buffer.printf("return (short) 2;%n"); }). ifNotMember(__ -> { buffer.printf("return (short) 1;%n"); }).generate(buffer); buffer.decrementIndent(); } buffer.printf("default:%n"); buffer.incrementIndent(); headerGenerator.addImport(MessageGenerator.UNSUPPORTED_VERSION_EXCEPTION_CLASS); buffer.printf("throw new UnsupportedVersionException(\"Unsupported API key \"" + " + apiKey);%n"); buffer.decrementIndent(); buffer.decrementIndent(); buffer.printf("}%n"); buffer.decrementIndent(); buffer.printf("}%n"); }

Target:
private void generateHeaderVersion(String type) { buffer.printf("public short %sHeaderVersion(short _version) {%n", type); buffer.incrementIndent(); buffer.printf("switch (apiKey) {%n"); buffer.incrementIndent(); for (Map.Entry<Short, ApiData> entry : apis.entrySet()) { short apiKey = entry.getKey(); buffer.printf("case %d:%n", apiKey); buffer.incrementIndent(); if (type.equals("response") && apiKey == 18) { buffer.printf("return (short) 0;%n"); buffer.decrementIndent(); continue; } if (type.equals("request") && apiKey == 7) { buffer.printf("if (_version == 0) {%n"); buffer.incrementIndent(); buffer.printf("return (short) 0;%n"); buffer.decrementIndent(); buffer.printf("}%n"); } ApiData data = entry.getValue(); MessageSpec spec = null; if (type.equals("request")) { spec = data.requestSpec; } else if (type.equals("response")) { spec = data.responseSpec; } else { throw new RuntimeException("Invalid type " + type + " for generateHeaderVersion"); } if (spec == null) { throw new RuntimeException("failed to find " + type + " for API key " + apiKey); } VersionConditional.forVersions(spec.flexibleVersions(), spec.validVersions()). ifMember(__ -> { if (type.equals("request")) { buffer.printf("return (short) 2;%n"); } else { buffer.printf("return (short) 1;%n"); } }). ifNotMember(__ -> { if (type.equals("request")) { buffer.printf("return (short) 1;%n"); } else { buffer.printf("return (short) 0;%n"); } }).generate(buffer); buffer.decrementIndent(); } buffer.printf("default:%n"); buffer.incrementIndent(); headerGenerator.addImport(MessageGenerator.UNSUPPORTED_VERSION_EXCEPTION_CLASS); buffer.printf("throw new UnsupportedVersionException(\"Unsupported API key \"" + " + apiKey);%n"); buffer.decrementIndent(); buffer.decrementIndent(); buffer.printf("}%n"); buffer.decrementIndent(); buffer.printf("}%n"); }