Class JavaReviewer

java.lang.Object
org.machanism.machai.gw.reviewer.JavaReviewer
All Implemented Interfaces:
Reviewer

public class JavaReviewer extends Object implements Reviewer
Reviewer implementation for Java source files (.java).

The reviewer reads source files as UTF-8 and detects the presence of the @guidance tag in either block or line comments. A matching file is converted into the localized prompt fragment appropriate for its kind of Java source file.

When processing package-info.java, the reviewer emits a package-level prompt fragment containing path context only. For all other Java files, it emits a prompt fragment containing the complete file content.

  • Field Details

    • promptBundle

      private final ResourceBundle promptBundle
      Localized prompt templates used to construct review requests for Java source files.

      The bundle is loaded using the default locale and must provide the java_file and java_package_info_file message keys. The field is initialized when a reviewer instance is created.

  • Constructor Details

    • JavaReviewer

      public JavaReviewer()
  • Method Details

    • getSupportedFileExtensions

      public String[] getSupportedFileExtensions()
      Returns the file extensions supported by this reviewer.
      Specified by:
      getSupportedFileExtensions in interface Reviewer
      Returns:
      an array containing "java"
    • perform

      public String perform(File projectDir, File guidancesFile) throws IOException
      Reviews the provided Java file and, if guidance is present, returns a formatted prompt fragment.

      The file is read as UTF-8. The complete source is included in the prompt for ordinary Java files, while package-info.java receives the package-level prompt containing its relative path. Only the first matching guidance comment is required to produce a result.

      Specified by:
      perform in interface Reviewer
      Parameters:
      projectDir - the project root directory used to compute a project-relative path for context
      guidancesFile - the Java file to analyze
      Returns:
      a formatted prompt fragment, or null when the file does not contain guidance
      Throws:
      IOException - if an error occurs while reading the file
      IllegalArgumentException - if the file cannot be decoded as UTF-8
    • extractPackageName

      public static String extractPackageName(String content)
      Extracts the declared package name from a Java source snippet.

      The first declaration matching the Java package-name syntax is returned; this method does not attempt to parse comments or string literals.

      Parameters:
      content - the full text content of a Java source file
      Returns:
      the declared package name, or "<default package>" when no package declaration is present