Class Hints
java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.agi.tool.AnahataToolkit
uno.anahata.asi.nb.tools.java.Hints
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single Java hint or code fix suggestion.static classRepresents metadata for a registered Java hint type. -
Field Summary
Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyHintFix(String filePath, String hintId) Applies the first available fix for a specific Java hint identified by its ID.Gets all Java hints (warnings, suggestions) for a specific project, with pagination and optional type filtering.getFileHints(String filePath) Gets all Java hints for a specific file.getMemberHints(String filePath, String memberFqn) Gets all Java hints for a specific class member.Gets a list of system instruction strings provided by this context provider.Returns a list of all unique Hint IDs registered in the NetBeans IDE.removeUnusedImports(String filePath) Surgically removes all unused imports from a Java source file.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, initialize, isEffectivelyProviding, postActivate, rebindMethods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, error, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContextProvider
getAgi, getContextPosition, getFlattenedHierarchy, getFullyQualifiedId, getHeader, getIconId, getInstructionsTokenCount, getRagTokenCount, isProviding, populateMessage, setParentProvider, setProviding
-
Constructor Details
-
Hints
public Hints()
-
-
Method Details
-
getSystemInstructions
Description copied from interface:ContextProviderGets 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
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
Gets all Java hints for a specific class member.- Parameters:
filePath- the absolute path of the Java filememberFqn- the ABSOLUTE FQN of the member- Returns:
- a list of hints located within the member's source range
- Throws:
Exception- if resolution fails
-
applyHintFix
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
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
Returns a list of all unique Hint IDs registered in the NetBeans IDE.- Returns:
- A list of metadata for all registered hints.
-

