Class Hints

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Hints extends AnahataToolkit
A toolkit for managing and applying Java hints and code fixes within the NetBeans IDE.

This toolkit provides tools for automated code cleanup, such as removing unused imports, based on the IDE's internal static analysis and AST-aware transformation engines.

Author:
anahata
  • Constructor Details

    • Hints

      public Hints()
  • Method Details

    • getSystemInstructions

      public List<String> getSystemInstructions() throws Exception
      Description copied from interface: ContextProvider
      Gets a list of system instruction strings provided by this context provider. These are typically prepended to the conversation as high-level guidance.
      Returns:
      A list of system instruction strings.
      Throws:
      Exception - if an error occurs during instruction generation.
    • removeUnusedImports

      public String removeUnusedImports(String filePath) throws Exception
      Surgically removes all unused imports from a Java source file.

      This tool uses the NetBeans 'JavaFixAllImports' API to identify and remove import statements that are not referenced within the file's scope (including nested and anonymous classes). The operation is performed synchronously within a modification task.

      Parameters:
      filePath - The absolute path of the Java file to clean.
      Returns:
      A message indicating the result of the operation.
      Throws:
      Exception - if the operation fails or the file is not a valid Java source.
    • getMemberHints

      public List<Hints.HintInfo> getMemberHints(String filePath, String memberFqn) throws Exception
      Gets all Java hints for a specific class member.
      Parameters:
      filePath - the absolute path of the Java file
      memberFqn - the ABSOLUTE FQN of the member
      Returns:
      a list of hints located within the member's source range
      Throws:
      Exception - if resolution fails
    • applyHintFix

      public String applyHintFix(String filePath, String hintId) throws Exception
      Applies the first available fix for a specific Java hint identified by its ID.

      This tool computes all hints for the given file, searches for the one matching the provided hintId, and invokes its primary fix implementation. The operation is performed within a modification task to ensure atomic application of changes to the underlying source.

      Parameters:
      filePath - The absolute path of the Java file.
      hintId - The unique identifier of the hint whose fix should be applied.
      Returns:
      A descriptive message indicating whether the fix was successfully applied or if the hint/fix was not found.
      Throws:
      Exception - if the Java source cannot be resolved or the modification task fails.
    • getFileHints

      public List<Hints.HintInfo> getFileHints(String filePath) throws Exception
      Gets all Java hints for a specific file.
      Parameters:
      filePath - The absolute path of the Java file.
      Returns:
      A list of hints found in the file.
      Throws:
      Exception - if the file cannot be processed.
    • getAllHints

      public Page<Hints.HintInfo> getAllHints(String projectPath, List<String> hintIds, Integer startIndex, Integer pageSize) throws Exception
      Gets all Java hints (warnings, suggestions) for a specific project, with pagination and optional type filtering.
      Parameters:
      projectPath - The absolute path of the project to scan.
      hintIds - Optional list of hint IDs to filter by.
      startIndex - The starting index for pagination.
      pageSize - The maximum number of hints to return.
      Returns:
      A paginated list of all found hints.
      Throws:
      Exception - if the project cannot be found or the scan fails.
    • listAvailableHints

      public List<Hints.HintMetadata> listAvailableHints()
      Returns a list of all unique Hint IDs registered in the NetBeans IDE.
      Returns:
      A list of metadata for all registered hints.