MCPcopy Index your code
hub / github.com/github/copilot-sdk / renderNestedType

Function renderNestedType

java/scripts/codegen/java.ts:885–955  ·  view source on GitHub ↗

Render a nested type (enum or record) indented at the given level.

(nested: JavaClassDef, indentLevel: number, nestedTypes: Map<string, JavaClassDef>, allImports: Set<string>)

Source from the content-addressed store, hash-verified

883
884/** Render a nested type (enum or record) indented at the given level. */
885function renderNestedType(nested: JavaClassDef, indentLevel: number, nestedTypes: Map<string, JavaClassDef>, allImports: Set<string>): string[] {
886 const ind = " ".repeat(indentLevel);
887 const lines: string[] = [];
888
889 if (nested.kind === "enum") {
890 lines.push("");
891 if (nested.description) {
892 lines.push(`${ind}/** ${nested.description} */`);
893 }
894 lines.push(`${ind}public enum ${nested.name} {`);
895 for (let i = 0; i < (nested.values || []).length; i++) {
896 const v = nested.values![i];
897 const comma = i < nested.values!.length - 1 ? "," : ";";
898 lines.push(`${ind} /** The {@code ${v}} variant. */`);
899 lines.push(`${ind} ${toEnumConstant(v)}("${v}")${comma}`);
900 }
901 lines.push("");
902 lines.push(`${ind} private final String value;`);
903 lines.push(`${ind} ${nested.name}(String value) { this.value = value; }`);
904 lines.push(`${ind} @com.fasterxml.jackson.annotation.JsonValue`);
905 lines.push(`${ind} public String getValue() { return value; }`);
906 lines.push(`${ind} @com.fasterxml.jackson.annotation.JsonCreator`);
907 lines.push(`${ind} public static ${nested.name} fromValue(String value) {`);
908 lines.push(`${ind} for (${nested.name} v : values()) {`);
909 lines.push(`${ind} if (v.value.equals(value)) return v;`);
910 lines.push(`${ind} }`);
911 lines.push(`${ind} throw new IllegalArgumentException("Unknown ${nested.name} value: " + value);`);
912 lines.push(`${ind} }`);
913 lines.push(`${ind}}`);
914 } else if (nested.kind === "class" && nested.schema?.properties) {
915 const localNestedTypes = new Map<string, JavaClassDef>();
916 const fields: { jsonName: string; javaName: string; javaType: string; description?: string }[] = [];
917
918 for (const [propName, propSchema] of Object.entries(nested.schema.properties)) {
919 if (typeof propSchema !== "object") continue;
920 const prop = propSchema as JSONSchema7;
921 // Record components are always boxed (nullable by design).
922 const result = schemaTypeToJava(prop, false, nested.name, propName, localNestedTypes);
923 for (const imp of result.imports) allImports.add(imp);
924 fields.push({ jsonName: propName, javaName: toCamelCase(propName), javaType: result.javaType, description: prop.description });
925 }
926
927 lines.push("");
928 if (nested.description) {
929 lines.push(`${ind}/** ${nested.description} */`);
930 }
931 lines.push(`${ind}@JsonIgnoreProperties(ignoreUnknown = true)`);
932 lines.push(`${ind}@JsonInclude(JsonInclude.Include.NON_NULL)`);
933 if (fields.length === 0) {
934 lines.push(`${ind}public record ${nested.name}() {`);
935 } else {
936 lines.push(`${ind}public record ${nested.name}(`);
937 for (let i = 0; i < fields.length; i++) {
938 const f = fields[i];
939 const comma = i < fields.length - 1 ? "," : "";
940 if (f.description) lines.push(`${ind} /** ${f.description} */`);
941 lines.push(`${ind} @JsonProperty("${f.jsonName}") ${f.javaType} ${f.javaName}${comma}`);
942 }

Callers 3

generateRpcClassFunction · 0.85

Calls 6

toEnumConstantFunction · 0.85
schemaTypeToJavaFunction · 0.85
toCamelCaseFunction · 0.85
popMethod · 0.80
pushMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…