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).

This reviewer reads Java source as UTF-8 and detects the presence of the @guidance tag in either block (/* ... */) or line (// ...) comments.

When processing package-info.java, the reviewer emits a package-level prompt fragment that only includes path context; for other Java files it emits a prompt fragment containing the full file content.

  • 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.
      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
    • extractPackageName

      public static String extractPackageName(String content)
      Extracts the declared package name from a Java source snippet.
      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