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

Function generateNamespaceApiFile

java/scripts/codegen/java.ts:1755–1870  ·  view source on GitHub ↗

* Generate a Java source file for a single namespace API class. * Returns the generated class name and whether a mapper static field is needed.

(
    prefix: string,
    namespacePath: string[],
    tree: NamespaceTree,
    isSession: boolean,
    packageName: string,
    packageDir: string
)

Source from the content-addressed store, hash-verified

1753 * Returns the generated class name and whether a mapper static field is needed.
1754 */
1755async function generateNamespaceApiFile(
1756 prefix: string,
1757 namespacePath: string[],
1758 tree: NamespaceTree,
1759 isSession: boolean,
1760 packageName: string,
1761 packageDir: string
1762): Promise<string> {
1763 const className = apiClassName(prefix, namespacePath);
1764 const sessionIdExpr = "this.sessionId";
1765
1766 const classLines: string[] = [];
1767 const allImports = new Set<string>([
1768 "java.util.concurrent.CompletableFuture",
1769 "javax.annotation.processing.Generated",
1770 ]);
1771 let needsMapper = false;
1772
1773 // Generate sub-namespace fields
1774 const subFields: string[] = [];
1775 const subInits: string[] = [];
1776 for (const [subKey, subTree] of tree.subspaces) {
1777 const subClass = apiClassName(prefix, [...namespacePath, subKey]);
1778 subFields.push(` /** API methods for the {@code ${[...namespacePath, subKey].join(".")}} sub-namespace. */`);
1779 subFields.push(` public final ${subClass} ${subKey};`);
1780 if (isSession) {
1781 subInits.push(` this.${subKey} = new ${subClass}(caller, sessionId);`);
1782 } else {
1783 subInits.push(` this.${subKey} = new ${subClass}(caller);`);
1784 }
1785 // Recursively generate sub-namespace files
1786 await generateNamespaceApiFile(prefix, [...namespacePath, subKey], subTree, isSession, packageName, packageDir);
1787 }
1788
1789 // Collect result/param imports and generate methods
1790 const methodLines: string[] = [];
1791 for (const [key, method] of tree.methods) {
1792 const resultClass = wrapperResultClassName(method);
1793 const paramsClass = wrapperParamsClassName(method);
1794 addWrapperResultImports(resultClass, allImports, packageName);
1795 if (paramsClass) allImports.add(`${packageName}.${paramsClass}`);
1796
1797 const { lines, needsMapper: nm, needsExperimentalImport } = generateApiMethod(key, method, isSession, sessionIdExpr);
1798 methodLines.push(...lines);
1799 if (nm) needsMapper = true;
1800 if (needsExperimentalImport) allImports.add("com.github.copilot.CopilotExperimental");
1801 }
1802
1803 // Build class body
1804 const qualifiedNs = namespacePath.length > 0 ? namespacePath.join(".") : prefix.toLowerCase();
1805 classLines.push(COPYRIGHT);
1806 classLines.push(``);
1807 classLines.push(AUTO_GENERATED_HEADER);
1808 classLines.push(GENERATED_FROM_API);
1809 classLines.push(``);
1810 classLines.push(`package ${packageName};`);
1811 classLines.push(``);
1812

Callers 1

generateRpcRootFileFunction · 0.85

Calls 9

apiClassNameFunction · 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…