Class CodeRefiner
java.lang.Object
uno.anahata.asi.agi.tool.ToolContext
uno.anahata.asi.agi.tool.AnahataToolkit
uno.anahata.asi.nb.tools.java.CodeRefiner
- All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable
V3.0.0 of the structural Java code refinement toolkit. High-precision
structural manipulation with a pragmatic approach to comment preservation.
- Author:
- anahata
-
Field Summary
Fields inherited from class AnahataToolkit
childrenProviders, propertyChangeSupportFields inherited from class ToolContext
toolkit -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddAnnotation(String filePath, String memberFqn, String annotation, boolean save) Adds an annotation to a class, method, or field.addImports(String filePath, List<String> imports, boolean save) Adds one or more imports to a file structurally.Gets a list of system instruction strings provided by this context provider.voidPerforms initial setup for a newly created toolkit instance.optimizeImports(String filePath, Boolean removeUnused, boolean save) Optimizes imports (converts FQNs to simple names, removes unused).static StringoptimizeImportsInMemory(org.netbeans.api.java.source.ClasspathInfo cpInfo, String sourceCode, boolean optimize, List<String> explicitImportsToAdd, List<String> explicitImportsToRemove) Helper to optimize imports entirely in-memory, preserving atomicity during batch edits.private voidoptimizeImportsInternal(org.openide.filesystems.FileObject fo, boolean removeUnused) Internal implementation of the import optimization logic.Reformats a file using IDE rules, logging each step and returning the resulting unified diff.Methods inherited from class AnahataToolkit
getChildrenProviders, getDescription, getId, getName, getParentProvider, getPropertyChangeSupport, 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
-
CodeRefiner
public CodeRefiner()
-
-
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.
-
addImports
Adds one or more imports to a file structurally.- Parameters:
filePath- the absolute path of the Java fileimports- list of FQNs to importsave- whether to save the file- Returns:
- a success message
- Throws:
Exception- if import fails
-
optimizeImports
Optimizes imports (converts FQNs to simple names, removes unused).- Parameters:
filePath- the absolute path of the Java fileremoveUnused- whether to remove unused importssave- whether to save the file- Returns:
- a success message
- Throws:
Exception- if optimization fails
-
reformat
Reformats a file using IDE rules, logging each step and returning the resulting unified diff.- Parameters:
filePath- the absolute path of the Java filesave- whether to save the file- Returns:
- the generated unified diff string or a no-changes message
- Throws:
Exception- if reformat fails
-
optimizeImportsInternal
-
optimizeImportsInMemory
public static String optimizeImportsInMemory(org.netbeans.api.java.source.ClasspathInfo cpInfo, String sourceCode, boolean optimize, List<String> explicitImportsToAdd, List<String> explicitImportsToRemove) throws Exception Helper to optimize imports entirely in-memory, preserving atomicity during batch edits.- Parameters:
cpInfo- The classpath infosourceCode- The source code stringoptimize- Whether to automatically resolve missing imports via ClassIndex and remove unused importsexplicitImportsToAdd- Additional FQNs to addexplicitImportsToRemove- FQNs to forcibly remove- Returns:
- The import-optimized source string
- Throws:
Exception
-
addAnnotation
public String addAnnotation(String filePath, String memberFqn, String annotation, boolean save) throws Exception Adds an annotation to a class, method, or field.- Parameters:
filePath- the absolute path of the Java filememberFqn- the ABSOLUTE FQN of the memberannotation- the annotation to addsave- whether to save- Returns:
- a success message
- Throws:
Exception- if it fails
-

