Object SkeletonExtractor
-
- All Implemented Interfaces:
public class SkeletonExtractor"Extract skeleton from real code" — the anti-staleness scaffold mechanism.
Instead of hand-written templates (which go stale when the codebase evolves — e.g. the
ai.platon.browser4.*→ai.platon.pulsar.*package migration touched 334 files), this extracts a parameterized skeleton from an existing, real source file. The repository's own best code IS the template, so it never drifts from reality.package X.Y.Z→{basePackage}the class named after the file (
class Foo/open class Foo) →{className}override val domain = "x"→{domain}toolSpec["method"]→{toolMethod}imports of the form
import <basePackage>.*→ rewritten to the new package
Everything else (annotations, bodies, comments) is preserved verbatim, so the extracted skeleton is a faithful copy of the reference implementation with only the volatile identifiers replaced.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classSkeletonExtractor.SkeletonA parameterized skeleton: the template text plus the parameters found.
public final classSkeletonExtractor.SkeletonSetA multi-file skeleton set extracted from a real directory (a plugin or module). Each file carries its own per-file skeleton; parameters is the UNION across all files, so re-instantiation with one value set renames consistently everywhere.
-
Field Summary
Fields Modifier and Type Field Description public final static SkeletonExtractorINSTANCE
-
Method Summary
Modifier and Type Method Description final SkeletonExtractor.Skeletonextract(String content, String fileName)Extract a skeleton from a Kotlin source file. final Stringinstantiate(SkeletonExtractor.Skeleton skeleton, Map<String, String> params)Instantiate a Skeleton with new parameter values. final Map<String, String>instantiate(SkeletonExtractor.SkeletonSet set, Map<String, String> params)Instantiate a SkeletonSet with new parameter values, consistently across all files. final SkeletonExtractor.SkeletonSetextractDir(Map<String, String> files)Extract a multi-file skeleton set from a real directory (a plugin/module). -
-
Method Detail
-
extract
final SkeletonExtractor.Skeleton extract(String content, String fileName)
Extract a skeleton from a Kotlin source file.
- Parameters:
content- raw file contentfileName- file name (used to infer the main class name)- Returns:
a Skeleton with placeholders
{key}and the discovered values
-
instantiate
final String instantiate(SkeletonExtractor.Skeleton skeleton, Map<String, String> params)
Instantiate a Skeleton with new parameter values.
- Parameters:
params- the desired values for each placeholder key- Returns:
the generated source, with any unresolved placeholders left as-is (caller can inspect them)
-
instantiate
final Map<String, String> instantiate(SkeletonExtractor.SkeletonSet set, Map<String, String> params)
Instantiate a SkeletonSet with new parameter values, consistently across all files. Resolves shared placeholders (
{basePackage},{domain}), class placeholders via their own key ({SeoAutoConfiguration}), theclassNameconvenience alias (renames the executor class and its cross-file references), and STEM-derived sibling renames: renamingclassName(or passing an explicitstem) renames every class sharing the recorded stem ({SeoService}→ WeatherService when SeoToolExecutor → WeatherToolExecutor). Explicit per-class keys always win over stem derivation.- Returns:
relative path → generated content; unresolved placeholders are left as-is for caller inspection
-
extractDir
final SkeletonExtractor.SkeletonSet extractDir(Map<String, String> files)
Extract a multi-file skeleton set from a real directory (a plugin/module).
Semantics:
basePackageis the COMMON package prefix across all files (e.g. "ai.platon.pulsar.seo" for packages "…seo.tools" and "…seo.config"). Per-file suffixes (".tools", ".config") are preserved, so renaming the base renames every package line and import consistently.Shared identifiers (
domain,toolMethod,artifactIdfrom pom.xml,pluginNamefrom plugin.json) become shared placeholders.Each class becomes a VALUE-NAMED placeholder (
{SeoToolExecutor},{SeoAutoConfiguration}): instantiate renames a class via its own key, or viaclassName(the first class discovered, kept as a convenience alias). Cross-file references (an import of the executor class inside the AutoConfiguration) are parameterized the same way.
- Parameters:
files- relative path → file content (text files only, keys use '/')- Returns:
the multi-file skeleton set
-
-
-
-