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

Function generateRpcRootFile

java/scripts/codegen/java.ts:1875–2006  ·  view source on GitHub ↗

* Generate ServerRpc.java or SessionRpc.java — the top-level wrapper class.

(
    sectionName: string, // "server" | "session"
    tree: NamespaceTree,
    isSession: boolean,
    packageName: string,
    packageDir: string
)

Source from the content-addressed store, hash-verified

1873 * Generate ServerRpc.java or SessionRpc.java — the top-level wrapper class.
1874 */
1875async function generateRpcRootFile(
1876 sectionName: string, // "server" | "session"
1877 tree: NamespaceTree,
1878 isSession: boolean,
1879 packageName: string,
1880 packageDir: string
1881): Promise<void> {
1882 const prefix = sectionName === "server" ? "Server" : "Session";
1883 const rootClassName = prefix + "Rpc";
1884 const sessionIdExpr = "this.sessionId";
1885
1886 const classLines: string[] = [];
1887 const allImports = new Set<string>([
1888 "java.util.concurrent.CompletableFuture",
1889 "javax.annotation.processing.Generated",
1890 ]);
1891 let needsMapper = false;
1892
1893 // Sub-namespace fields and init lines
1894 const subFields: string[] = [];
1895 const subInits: string[] = [];
1896 for (const [nsKey, nsTree] of tree.subspaces) {
1897 const nsClass = apiClassName(prefix, [nsKey]);
1898 subFields.push(` /** API methods for the {@code ${nsKey}} namespace. */`);
1899 subFields.push(` public final ${nsClass} ${nsKey};`);
1900 if (isSession) {
1901 subInits.push(` this.${nsKey} = new ${nsClass}(caller, sessionId);`);
1902 } else {
1903 subInits.push(` this.${nsKey} = new ${nsClass}(caller);`);
1904 }
1905 // Generate the namespace API class file (recursively)
1906 await generateNamespaceApiFile(prefix, [nsKey], nsTree, isSession, packageName, packageDir);
1907 }
1908
1909 // Collect result/param imports and generate top-level method bodies
1910 const methodLines: string[] = [];
1911 for (const [key, method] of tree.methods) {
1912 const resultClass = wrapperResultClassName(method);
1913 const paramsClass = wrapperParamsClassName(method);
1914 addWrapperResultImports(resultClass, allImports, packageName);
1915 if (paramsClass) allImports.add(`${packageName}.${paramsClass}`);
1916
1917 const { lines, needsMapper: nm, needsExperimentalImport } = generateApiMethod(key, method, isSession, sessionIdExpr);
1918 methodLines.push(...lines);
1919 if (nm) needsMapper = true;
1920 if (needsExperimentalImport) allImports.add("com.github.copilot.CopilotExperimental");
1921 }
1922
1923 // Build file content
1924 classLines.push(COPYRIGHT);
1925 classLines.push(``);
1926 classLines.push(AUTO_GENERATED_HEADER);
1927 classLines.push(GENERATED_FROM_API);
1928 classLines.push(``);
1929 classLines.push(`package ${packageName};`);
1930 classLines.push(``);
1931
1932 const sortedImports = [...allImports].filter(imp => !imp.startsWith(packageName + ".")).sort();

Callers 1

generateRpcWrappersFunction · 0.85

Calls 10

apiClassNameFunction · 0.85
generateNamespaceApiFileFunction · 0.85
wrapperResultClassNameFunction · 0.85
wrapperParamsClassNameFunction · 0.85
addWrapperResultImportsFunction · 0.85
generateApiMethodFunction · 0.85
joinMethod · 0.80
writeGeneratedFileFunction · 0.70
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…