Class JavaReviewer
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final ResourceBundleLocalized prompt templates used to construct review requests for Java source files. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringextractPackageName(String content) Extracts the declared package name from a Java source snippet.String[]Returns the file extensions supported by this reviewer.Reviews the provided Java file and, if guidance is present, returns a formatted prompt fragment.
-
Field Details
-
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_fileandjava_package_info_filemessage keys. The field is initialized when a reviewer instance is created.
-
-
Constructor Details
-
JavaReviewer
public JavaReviewer()
-
-
Method Details
-
getSupportedFileExtensions
Returns the file extensions supported by this reviewer.- Specified by:
getSupportedFileExtensionsin interfaceReviewer- Returns:
- an array containing
"java"
-
perform
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.javareceives the package-level prompt containing its relative path. Only the first matching guidance comment is required to produce a result.- Specified by:
performin interfaceReviewer- Parameters:
projectDir- the project root directory used to compute a project-relative path for contextguidancesFile- the Java file to analyze- Returns:
- a formatted prompt fragment, or
nullwhen the file does not contain guidance - Throws:
IOException- if an error occurs while reading the fileIllegalArgumentException- if the file cannot be decoded as UTF-8
-
extractPackageName
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
-