1717
1818import com .intellij .java .impl .refactoring .actions .TypeCookAction ;
1919import consulo .annotation .access .RequiredReadAction ;
20- import consulo .application .Result ;
2120import consulo .codeEditor .Editor ;
2221import consulo .fileEditor .FileEditorManager ;
2322import consulo .java .analysis .impl .localize .JavaQuickFixLocalize ;
2423import consulo .language .editor .FileModificationService ;
25- import consulo .language .editor .WriteCommandAction ;
2624import consulo .language .editor .inspection .LocalQuickFix ;
2725import consulo .language .editor .inspection .ProblemDescriptor ;
2826import consulo .language .editor .intention .SyntheticIntentionAction ;
3230import consulo .localize .LocalizeValue ;
3331import consulo .project .Project ;
3432import consulo .ui .annotation .RequiredUIAccess ;
33+ import consulo .undoRedo .CommandProcessor ;
3534import jakarta .annotation .Nonnull ;
3635
3736public class GenerifyFileFix implements SyntheticIntentionAction , LocalQuickFix {
3837 @ Nonnull
39- private String myFileName = "" ;
38+ private LocalizeValue myText = LocalizeValue . empty () ;
4039
4140 @ Nonnull
4241 @ Override
4342 public LocalizeValue getText () {
44- return JavaQuickFixLocalize . generifyText ( myFileName ) ;
43+ return myText ;
4544 }
4645
4746 @ Nonnull
@@ -52,32 +51,29 @@ public LocalizeValue getName() {
5251
5352 @ Override
5453 @ RequiredUIAccess
55- public void applyFix (@ Nonnull final Project project , @ Nonnull ProblemDescriptor descriptor ) {
54+ public void applyFix (@ Nonnull Project project , @ Nonnull ProblemDescriptor descriptor ) {
5655 PsiElement element = descriptor .getPsiElement ();
5756 if (element == null ) {
5857 return ;
5958 }
60- final PsiFile file = element .getContainingFile ();
59+ PsiFile file = element .getContainingFile ();
6160 if (isAvailable (project , null , file )) {
62- myFileName = file .getName ();
63- new WriteCommandAction (project ) {
64- @ Override
65- @ RequiredUIAccess
66- protected void run (Result result ) throws Throwable {
67- invoke (project , FileEditorManager .getInstance (project ).getSelectedTextEditor (), file );
68- }
69- }.execute ();
61+ CommandProcessor .getInstance ().newCommand ()
62+ .project (project )
63+ .inWriteAction ()
64+ .run (() -> invoke (project , FileEditorManager .getInstance (project ).getSelectedTextEditor (), file ));
7065 }
7166 }
7267
7368 @ Override
7469 @ RequiredReadAction
7570 public boolean isAvailable (@ Nonnull Project project , Editor editor , PsiFile file ) {
7671 if (file != null && file .isValid ()) {
77- myFileName = file .getName ();
72+ myText = JavaQuickFixLocalize . generifyText ( file .getName () );
7873 return PsiManager .getInstance (project ).isInProject (file );
7974 }
8075 else {
76+ myText = LocalizeValue .empty ();
8177 return false ;
8278 }
8379 }
0 commit comments