Class GuidanceProcessor


public class GuidanceProcessor extends AIFileProcessor
Scans a project tree, extracts per-file @guidance directives through Reviewers, and dispatches the resulting prompts to a configured Genai.

The processor supports single-module and multi-module project layouts. For multi-module builds, modules are processed child-first (each module is scanned before the parent project directory). Processing is traversal-based; it does not attempt to build projects or resolve dependencies.

  • Field Details

    • GUIDANCE_TAG_NAME

      public static final String GUIDANCE_TAG_NAME
      Tag name for guidance comments.
      See Also:
    • promptBundle

      final ResourceBundle promptBundle
      Resource bundle supplying prompt templates for generators.
  • Constructor Details

    • GuidanceProcessor

      public GuidanceProcessor(File projectDir, String genai, Configurator configurator)
      Constructs a processor.
      Parameters:
      projectDir - root directory used as a base for relative paths
      genai - provider key/name to use
      configurator - configuration source
  • Method Details

    • loadReviewers

      void loadReviewers()
      Loads file reviewers via the ServiceLoader registry, mapping supported file extensions to a reviewer.
    • normalizeExtensionKey

      static String normalizeExtensionKey(String extension)
      Normalizes a file extension (with or without a leading dot) into a lower-case lookup key.
      Parameters:
      extension - the extension to normalize (e.g., "java" or ".java")
      Returns:
      normalized key, or null if the input is blank
    • match

      protected boolean match(File file, File projectDir)
      Applies matching logic and default-guidance behavior.
      Overrides:
      match in class AbstractFileProcessor
      Parameters:
      file - candidate file/directory
      projectDir - current project directory
      Returns:
      true when the candidate should be processed
    • processModule

      protected void processModule(File projectDir, String module) throws IOException
      Processes a module directory.

      When a scan directory or pattern is configured, modules are only processed when the module itself matches or contains the scan directory.

      Overrides:
      processModule in class ProjectProcessor
      Parameters:
      projectDir - parent project directory
      module - module relative path
      Throws:
      IOException - if scanning the module fails
    • processParentFiles

      protected void processParentFiles(ProjectLayout projectLayout) throws IOException
      Processes files and folders under the parent project directory (excluding modules).
      Overrides:
      processParentFiles in class AbstractFileProcessor
      Parameters:
      projectLayout - project layout
      Throws:
      IOException - if file reading fails
    • processFile

      protected void processFile(ProjectLayout projectLayout, File file) throws IOException
      Extracts guidance for a file and, when present, performs provider processing.
      Overrides:
      processFile in class AbstractFileProcessor
      Parameters:
      projectLayout - project layout
      file - file to process
      Throws:
      IOException - if reading the file or provider execution fails
    • process

      protected String process(ProjectLayout projectLayout, File file, String guidance) throws IOException
      Composes the final prompt and dispatches it to the configured provider.
      Parameters:
      projectLayout - project layout
      file - file currently being processed
      guidance - extracted guidance and/or default guidance
      Returns:
      provider output
      Throws:
      IOException - if provider execution fails
    • parseFile

      String parseFile(File projectDir, File file) throws IOException
      Uses a Reviewer (based on file extension) to extract guidance.
      Parameters:
      projectDir - project root directory
      file - file being parsed
      Returns:
      guidance text, or null if the file type is not supported
      Throws:
      IOException - if the file cannot be read
    • getReviewerForExtension

      Reviewer getReviewerForExtension(String extension)
      Resolves a reviewer for a given file extension.
      Parameters:
      extension - file extension (with or without a dot)
      Returns:
      reviewer, or null if none is registered for that extension
    • deleteTempFiles

      public static boolean deleteTempFiles(File basedir)
      Deletes the input-log temporary directory.
      Parameters:
      basedir - project base directory
      Returns:
      true if the directory was deleted, otherwise false