Class CodeRefinementBatch
java.lang.Object
uno.anahata.asi.toolkit.resources.text.AbstractTextResourceWrite
uno.anahata.asi.intellij.tools.java.coderefiner.CodeRefinementBatch
An atomic batch of member-level
CodeRefinementIntents applied to a single Java
file by BatchCodeRefiner#refine.
Extends AbstractTextResourceWrite to participate in the interactive diff UI
lifecycle, optimistic locking, and manual override capture.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<LineComment> Optional calculated line comments for UI commentary rendering.private StringThe absolute path of the Java file to modify (optional if resourceUuid is provided).private List<CodeRefinementIntent> The ordered list of structural modifications to apply.private booleanWhether to optimize imports (shorten FQNs, remove unused) after applying the intents.private booleanWhether to persist the file to disk after applying the intents.Fields inherited from class AbstractTextResourceWrite
lastModified, manualOverride, originalContent, originalResourceName, resourceUuid, resultingContent -
Constructor Summary
ConstructorsConstructorDescriptionCodeRefinementBatch(String uuid, long lastModified) Minimal constructor for standard tool invocation. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyIntentToPsi(com.intellij.openapi.project.Project project, com.intellij.psi.PsiElementFactory factory, com.intellij.psi.PsiJavaFile file, CodeRefinementIntent intent) Applies a structural intent to the target PSI file in-memory.protected StringPerforms the actual, tool-specific calculation of the resulting content.private static com.intellij.psi.PsiClassfindClassInFile(com.intellij.psi.PsiJavaFile file, String classFqn) Locates a class by FQN or simple name within the PSI file.private static voidinsertMember(com.intellij.psi.PsiClass target, com.intellij.psi.PsiMember member, RelativePosition position, String anchorName) private static com.intellij.psi.PsiMemberparseMember(com.intellij.psi.PsiElementFactory factory, String declaration, com.intellij.psi.PsiElement context) private static com.intellij.psi.PsiMemberrequireAnchor(com.intellij.psi.PsiClass target, String anchorName) private static com.intellij.psi.PsiElementrequireMemberInFile(com.intellij.psi.PsiJavaFile file, String memberFqn) Locates a member by canonical FQN within the PSI file.private com.intellij.openapi.project.ProjectresolveProject(Agi agi) Resolves the hosting IntelliJ project for AST parsing and styling.private static com.intellij.psi.PsiElementsearchClassForMember(com.intellij.psi.PsiClass cls, String memberFqn, String simpleName, boolean isMethod) voidPerforms pre-flight validation of the update operation.Methods inherited from class AbstractTextResourceWrite
calculateResultingContent, captureOriginalContent, getUnifiedDiff, validateIdenticalContent, validateStructuralState
-
Field Details
-
filePath
The absolute path of the Java file to modify (optional if resourceUuid is provided). -
intents
The ordered list of structural modifications to apply. -
optimizeImports
private boolean optimizeImportsWhether to optimize imports (shorten FQNs, remove unused) after applying the intents. -
save
private boolean saveWhether to persist the file to disk after applying the intents. -
calculatedComments
Optional calculated line comments for UI commentary rendering.
-
-
Constructor Details
-
CodeRefinementBatch
Minimal constructor for standard tool invocation.- Parameters:
uuid- the resource UUID.lastModified- optimistic locking timestamp.
-
-
Method Details
-
doCalculateResultingContent
Performs the actual, tool-specific calculation of the resulting content.Replays the refinement intents in-memory on a dummy
PsiJavaFilecreated viaPsiFileFactory, shortens class references, optionally optimizes imports, and reformats code without mutating workspace files until committed.- Specified by:
doCalculateResultingContentin classAbstractTextResourceWrite- Parameters:
agi- The parent agi session.- Returns:
- The calculated resulting content as a String.
- Throws:
Exception- if the calculation logic fails.
-
validate
Performs pre-flight validation of the update operation. Note: This method ensures state is captured.- Overrides:
validatein classAbstractTextResourceWrite- Parameters:
agi- The parent agi session.- Throws:
Exception- if validation fails.
-
resolveProject
Resolves the hosting IntelliJ project for AST parsing and styling.- Parameters:
agi- the parent agi session.- Returns:
- the hosting project or default project.
-
applyIntentToPsi
public static void applyIntentToPsi(com.intellij.openapi.project.Project project, com.intellij.psi.PsiElementFactory factory, com.intellij.psi.PsiJavaFile file, CodeRefinementIntent intent) throws AgiToolException Applies a structural intent to the target PSI file in-memory.- Parameters:
project- the project.factory- the element factory.file- the Java PSI file.intent- the structural intent.- Throws:
AgiToolException- if an intent target cannot be resolved.
-
findClassInFile
private static com.intellij.psi.PsiClass findClassInFile(com.intellij.psi.PsiJavaFile file, String classFqn) Locates a class by FQN or simple name within the PSI file.- Parameters:
file- the Java PSI file.classFqn- the class FQN or simple name.- Returns:
- the resolved class, or first class if unspecified.
-
requireMemberInFile
private static com.intellij.psi.PsiElement requireMemberInFile(com.intellij.psi.PsiJavaFile file, String memberFqn) throws AgiToolException Locates a member by canonical FQN within the PSI file.- Parameters:
file- the Java PSI file.memberFqn- the member FQN.- Returns:
- the matching member.
- Throws:
AgiToolException- if member is absent.
-
searchClassForMember
-
parseMember
private static com.intellij.psi.PsiMember parseMember(com.intellij.psi.PsiElementFactory factory, String declaration, com.intellij.psi.PsiElement context) throws AgiToolException - Throws:
AgiToolException
-
insertMember
private static void insertMember(com.intellij.psi.PsiClass target, com.intellij.psi.PsiMember member, RelativePosition position, String anchorName) throws AgiToolException - Throws:
AgiToolException
-
requireAnchor
private static com.intellij.psi.PsiMember requireAnchor(com.intellij.psi.PsiClass target, String anchorName) throws AgiToolException - Throws:
AgiToolException
-

