Class BatchCodeRefiner
java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.agi.tool.AnahataToolkit
uno.anahata.asi.nb.tools.java.BatchCodeRefiner
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
The authoritative toolkit for structural Java refinement.
This toolkit replaces the legacy path-based CodeRefiner with a batch-oriented, resource-centric approach. It guarantees atomicity and context-integrity through optimistic locking and memory-backed AST simulation.
- Author:
- anahata
-
Field Summary
Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportModifier and TypeFieldDescriptionprotected List<ContextProvider> The list of child context providers managed by this toolkit.protected PropertyChangeSupportSupport for firing property change events.Fields inherited from class ToolContext
toolkitModifier and TypeFieldDescriptionprotected JavaObjectToolkitThe toolkit instance that owns this context. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intfindMemberIndex(org.netbeans.api.java.source.CompilationInfo info, List<? extends Tree> members, String memberName) Finds the 0-based index of a member within a list of AST class members by matching its signature.static TreefindMemberInWorkingCopy(org.netbeans.api.java.source.CompilationInfo info, String memberFqn) Locates a member tree within a working copy compilation context by its canonical FQN.static intgetInsertIndex(org.netbeans.api.java.source.CompilationInfo wc, List<? extends Tree> members, RelativePosition position, String anchor) Calculates the insertion index for a new member based on a relative position and an anchor name.static StringgetMemberSignature(String memberFqn) Extracts the raw signature from a canonical identification FQN to be used for matching.Gets a list of system instruction strings provided by this context provider.voidPerforms initial setup for a newly created toolkit instance.static TreeparseMember(org.netbeans.api.java.source.WorkingCopy wc, String declaration, String body, org.netbeans.api.java.source.ClasspathInfo cpInfo) Parses a raw Java string into a detached AST Tree node, capturing and importing all inline comments.static ClassTreerebuildClassTree(org.netbeans.api.java.source.TreeMaker make, ClassTree ct, List<Tree> members) Rebuilds a ClassTree node with a new, modified list of class members based on class kind.refine(CodeRefinementBatch batch) Applies a batch of member-level modifications to ONE Java file synchronously, saving and rebuilding the AST.static voidthrowMemberNotFound(org.netbeans.api.java.source.CompilationInfo info, String memberFqn) Throws a highly descriptive exception with available suggestions when a member is not found.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, isEffectivelyProviding, postActivate, rebindModifier and TypeMethodDescriptionGets the list of immediate child context providers.Gets a detailed description of what this context provider does.getId()Gets the unique identifier for this context provider.getName()Gets the human-readable name of this context provider.Gets the parent context provider in the hierarchy, if any.Gets the PropertyChangeSupport instance for this object.booleanOverride to also take into consideration theAbstractToolkit.enabledvoidCallback method triggered by the Asi Container once the Agi session has been fully deserialized and associated to the ASI container.voidrebind()Rebinds the toolkit after deserialization.Methods inherited from class ToolContext
addAttachment, addAttachment, addAttachment, error, getAgi, getApplicationMap, getAsiContainer, getAsiContainerMap, getCall, getExecutorService, getModelId, getModelMessage, getResourceManager, getResponse, getSessionMap, getThreadSafeLogger, getTool, getToolContext, getToolkit, getToolManager, getTurnMap, isToolExecution, log, peekResponse, runAsyncModifier and TypeMethodDescriptionvoidaddAttachment(byte[] data, String mimeType) Attaches a binary blob to the current tool's response.voidaddAttachment(File file) Convenience method to attach a file to the current tool's response.voidaddAttachment(Path path) Convenience method to attach a file from a Path to the current tool's response.voidAdds an error message to the current tool's response.getAgi()Convenience method to get the parent agi container for the current execution.Gets a static, application-scoped map for sharing objects across all containers in the current JVM.Gets the current ASI container hosting this Agi container is running.Gets a map for sharing objects across all sessions within the current ASI container.getCall()Convenience method to get the current tool call that initiated this execution.Convenience method to get the executor service for the current agi session.The id of model that is executing the tool.The id of model that is executing the tool.Convenience method to get the application's ResourceManager.Gets the current tool response from the thread-local context.Gets a shared map for storing state across turns within the current agi session.Gets a thread-safe logging consumer that automatically propagates the current tool execution context whenever a message is logged.getTool()Convenience method to get the metadata for the tool currently being executed.Returns a thread-safe snapshot of this context.<T> TgetToolkit(Class<T> toolkitClass) Retrieves the singleton instance of a registered toolkit class.Convenience method to get the application's global ToolManager.Gets a shared map for storing state across turns within the current agi session.booleanChecks if the current thread or this context instance is associated with an active tool execution.voidAdds a standard log message to the current tool's response.protected JavaMethodToolResponseInternal helper to retrieve the response if it exists, without throwing an exception.voidExecutes a task asynchronously in the session's executor service, automatically propagating the current tool execution context to the background thread.Methods 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, setProvidingModifier and TypeMethodDescriptiongetAgi()Gets the parent AGI session this context provider is registered under.default ContextPositionGets the designated position of this provider's content in the AI prompt.default List<ContextProvider> getFlattenedHierarchy(boolean providingOnly) Gets a flattened list of this provider and all its descendants in the hierarchy.default StringGets the fully qualified ID of this provider, reflecting its position in the hierarchy.default StringGenerates a machine-readable header string for this context provider, used to identify the source of injected context in the final prompt.default StringGets an optional icon identifier for this provider.default intCalculates the token count for the system instructions provided by this instance using the active model.default intCalculates the token count for the RAG content provided by this instance using the active model.booleanChecks if this context provider is currently active and providing context.default voidpopulateMessage(RagMessage ragMessage) Populates the givenRagMessagewith dynamic, just-in-time context parts.default voidsetParentProvider(ContextProvider parent) Sets the parent context provider for this instance.default voidsetProviding(boolean enabled) Sets whether this context provider is enabled.
-
Constructor Details
-
BatchCodeRefiner
public BatchCodeRefiner()
-
-
Method Details
-
initialize
public void initialize()Description copied from class:AnahataToolkitPerforms initial setup for a newly created toolkit instance.This method is called exactly once by the
ToolManagerafter the toolkit has been instantiated and registered. It provides a clean hook for toolkits to perform one-time initialization logic that requires the tool environment to be fully configured, such as scanning for project instructions or registering default resources.- Overrides:
initializein classAnahataToolkit
-
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.
-
refine
Applies a batch of member-level modifications to ONE Java file synchronously, saving and rebuilding the AST.- Parameters:
batch- The robust refinement batch containing modifications.- Returns:
- The generated unified diff string representing changes applied to disk.
- Throws:
Exception- if validation or file I/O fails.
-
findMemberInWorkingCopy
public static Tree findMemberInWorkingCopy(org.netbeans.api.java.source.CompilationInfo info, String memberFqn) Locates a member tree within a working copy compilation context by its canonical FQN.- Parameters:
info- The active compilation context.memberFqn- The canonical FQN identifying the target member.- Returns:
- The matching Tree node if found, or null otherwise.
-
findMemberIndex
public static int findMemberIndex(org.netbeans.api.java.source.CompilationInfo info, List<? extends Tree> members, String memberName) Finds the 0-based index of a member within a list of AST class members by matching its signature.- Parameters:
info- The active compilation context.members- The list of class member trees to search.memberName- The canonical name or signature to match against.- Returns:
- The 0-based index of the matching member, or -1 if no match is found.
-
parseMember
public static Tree parseMember(org.netbeans.api.java.source.WorkingCopy wc, String declaration, String body, org.netbeans.api.java.source.ClasspathInfo cpInfo) throws Exception Parses a raw Java string into a detached AST Tree node, capturing and importing all inline comments.- Parameters:
wc- The target working copy context.declaration- The member declaration header string.body- The optional member body code block.cpInfo- The classpath information for resolution context.- Returns:
- The successfully parsed and detached AST Tree node.
- Throws:
Exception- if parsing, compile phase resolution, or compilation fails.
-
getInsertIndex
public static int getInsertIndex(org.netbeans.api.java.source.CompilationInfo wc, List<? extends Tree> members, RelativePosition position, String anchor) throws AgiToolException Calculates the insertion index for a new member based on a relative position and an anchor name.- Parameters:
wc- The target working copy or compilation context.members- The list of existing class members.position- The relative position (START, END, BEFORE, AFTER).anchor- The anchor member name, required for BEFORE and AFTER positions.- Returns:
- The calculated 0-based insertion index.
- Throws:
AgiToolException- if anchor position rules are violated or the anchor is not found.
-
getMemberSignature
-
throwMemberNotFound
public static void throwMemberNotFound(org.netbeans.api.java.source.CompilationInfo info, String memberFqn) Throws a highly descriptive exception with available suggestions when a member is not found.- Parameters:
info- The active compilation context.memberFqn- The canonical member FQN that was not resolved.- Throws:
AgiToolException- always, containing detailed candidate recommendations.
-
rebuildClassTree
public static ClassTree rebuildClassTree(org.netbeans.api.java.source.TreeMaker make, ClassTree ct, List<Tree> members) Rebuilds a ClassTree node with a new, modified list of class members based on class kind.- Parameters:
make- The TreeMaker utility instance.ct- The original class tree to reconstruct.members- The new list of member trees.- Returns:
- The newly constructed and reconstructed ClassTree node.
-

