add generator for futur-lazy

This commit is contained in:
WhatCats
2025-01-06 23:08:59 +01:00
parent 4236adbd9e
commit 6174193145
11 changed files with 595 additions and 188 deletions

View File

@@ -0,0 +1,33 @@
const PACKAGE = "src/main/java/dev/tommyjs/futur"
const SIGNAL = "// Generated delegates to static factory"
const regex = /( {4}\/\*\*.+?)?((?:\S| )+? )(\S+)(\(.*?\))(?: {.+?}|;)/gs
const content = await Bun.file(`../../futur-api/${PACKAGE}/promise/PromiseFactory.java`).text()
const methods = [""]
for (const match of content.matchAll(regex)) {
let [_, docs, head, name, params] = match
head = head.trimStart()
if (head.startsWith("static")) continue
if (head.startsWith("default")) head = head.slice(8);
const args = Array.from(params.matchAll(/ ([a-zA-Z1-9]+)[,)]/gs))
.map(v => v[1]).join(", ")
methods.push(
[
`${docs} public static ${head}${name}${params} {`,
` return factory.${name}(${args});`,
" }"
].join("\n")
)
}
const output = Bun.file(`../${PACKAGE}/lazy/Promises.java`)
const existing = await output.text()
const cutIndex = existing.indexOf(SIGNAL) + SIGNAL.length;
const newContent = existing.slice(0, cutIndex) + methods.join("\n\n") + "\n\n}"
await Bun.write(output, newContent)