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

Function generateEventVariantClass

java/scripts/codegen/java.ts:957–1085  ·  view source on GitHub ↗
(
    variant: EventVariant,
    packageName: string,
    packageDir: string
)

Source from the content-addressed store, hash-verified

955}
956
957async function generateEventVariantClass(
958 variant: EventVariant,
959 packageName: string,
960 packageDir: string
961): Promise<void> {
962 const lines: string[] = [];
963 const allImports = new Set<string>([
964 "com.fasterxml.jackson.annotation.JsonIgnoreProperties",
965 "com.fasterxml.jackson.annotation.JsonProperty",
966 "com.fasterxml.jackson.annotation.JsonInclude",
967 "javax.annotation.processing.Generated",
968 ]);
969 const nestedTypes = new Map<string, JavaClassDef>();
970
971 // Collect data record fields
972 interface FieldInfo {
973 jsonName: string;
974 javaName: string;
975 javaType: string;
976 description?: string;
977 }
978
979 const dataFields: FieldInfo[] = [];
980
981 if (variant.dataSchema?.properties) {
982 for (const [propName, propSchema] of Object.entries(variant.dataSchema.properties)) {
983 if (typeof propSchema !== "object") continue;
984 const prop = propSchema as JSONSchema7;
985 // Record components are always boxed (nullable by design).
986 const result = schemaTypeToJava(prop, false, `${variant.className}Data`, propName, nestedTypes);
987 for (const imp of result.imports) allImports.add(imp);
988 dataFields.push({
989 jsonName: propName,
990 javaName: toCamelCase(propName),
991 javaType: result.javaType,
992 description: prop.description,
993 });
994 }
995 }
996
997 // Whether a data record should be emitted (always when dataSchema is present)
998 const hasDataSchema = variant.dataSchema !== null;
999
1000 // Build the file
1001 lines.push(COPYRIGHT);
1002 lines.push("");
1003 lines.push(AUTO_GENERATED_HEADER);
1004 lines.push(GENERATED_FROM_SESSION_EVENTS);
1005 lines.push("");
1006 lines.push(`package ${packageName};`);
1007 lines.push("");
1008
1009 // Placeholder for imports
1010 const importPlaceholderIdx = lines.length;
1011 lines.push("__IMPORTS__");
1012 lines.push("");
1013
1014 if (variant.description) {

Callers 1

generateSessionEventsFunction · 0.85

Calls 8

schemaTypeToJavaFunction · 0.85
toCamelCaseFunction · 0.85
renderNestedTypeFunction · 0.85
popMethod · 0.80
joinMethod · 0.80
writeGeneratedFileFunction · 0.70
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…