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.

    • Constructor Detail

    • Method Detail

      • extract

         final SkeletonExtractor.Skeleton extract(String content, String fileName)

        Extract a skeleton from a Kotlin source file.

        Parameters:
        content - raw file content
        fileName - file name (used to infer the main class name)
        Returns:

        a Skeleton with placeholders {key} and the discovered values

      • 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}), the className convenience alias (renames the executor class and its cross-file references), and STEM-derived sibling renames: renaming className (or passing an explicit stem) 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:

        • basePackage is 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, artifactId from pom.xml, pluginName from plugin.json) become shared placeholders.

        • Each class becomes a VALUE-NAMED placeholder ({SeoToolExecutor}, {SeoAutoConfiguration}): instantiate renames a class via its own key, or via className (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