|
5 | 5 | import com.intellij.java.language.psi.search.PsiShortNamesCache; |
6 | 6 | import com.intellij.uiDesigner.compiler.AsmCodeGenerator; |
7 | 7 | import com.intellij.uiDesigner.impl.make.FormSourceCodeGenerator; |
| 8 | +import consulo.annotation.access.RequiredWriteAction; |
8 | 9 | import consulo.language.editor.refactoring.BaseRefactoringProcessor; |
9 | 10 | import consulo.language.editor.refactoring.ui.UsageViewDescriptorAdapter; |
10 | 11 | import consulo.language.psi.PsiElement; |
11 | 12 | import consulo.language.psi.PsiFile; |
12 | 13 | import consulo.language.psi.scope.GlobalSearchScope; |
| 14 | +import consulo.localize.LocalizeValue; |
13 | 15 | import consulo.project.Project; |
14 | 16 | import consulo.usage.UsageInfo; |
15 | 17 | import consulo.usage.UsageViewDescriptor; |
|
22 | 24 | * @author VISTALL |
23 | 25 | * @since 2023-11-14 |
24 | 26 | */ |
25 | | -public class RemovingSetupMethodProcessor extends BaseRefactoringProcessor |
26 | | -{ |
27 | | - public RemovingSetupMethodProcessor(@Nonnull Project project) |
28 | | - { |
29 | | - super(project); |
30 | | - } |
| 27 | +public class RemovingSetupMethodProcessor extends BaseRefactoringProcessor { |
| 28 | + public RemovingSetupMethodProcessor(@Nonnull Project project) { |
| 29 | + super(project); |
| 30 | + } |
31 | 31 |
|
32 | | - @Nonnull |
33 | | - @Override |
34 | | - protected UsageViewDescriptor createUsageViewDescriptor(@Nonnull UsageInfo[] usageInfos) |
35 | | - { |
36 | | - return new UsageViewDescriptorAdapter() |
37 | | - { |
38 | | - @Nonnull |
39 | | - @Override |
40 | | - public PsiElement[] getElements() |
41 | | - { |
42 | | - return new PsiElement[0]; |
43 | | - } |
| 32 | + @Nonnull |
| 33 | + @Override |
| 34 | + protected UsageViewDescriptor createUsageViewDescriptor(@Nonnull UsageInfo[] usageInfos) { |
| 35 | + return new UsageViewDescriptorAdapter() { |
| 36 | + @Nonnull |
| 37 | + @Override |
| 38 | + public PsiElement[] getElements() { |
| 39 | + return new PsiElement[0]; |
| 40 | + } |
44 | 41 |
|
45 | | - @Override |
46 | | - public String getProcessedElementsHeader() |
47 | | - { |
48 | | - return null; |
49 | | - } |
50 | | - }; |
51 | | - } |
| 42 | + @Override |
| 43 | + public String getProcessedElementsHeader() { |
| 44 | + return null; |
| 45 | + } |
| 46 | + }; |
| 47 | + } |
52 | 48 |
|
53 | | - @Nonnull |
54 | | - @Override |
55 | | - protected UsageInfo[] findUsages() |
56 | | - { |
57 | | - final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myProject); |
58 | | - final PsiMethod[] methods = cache.getMethodsByName(AsmCodeGenerator.SETUP_METHOD_NAME, |
59 | | - GlobalSearchScope.projectScope(myProject)); |
| 49 | + @Nonnull |
| 50 | + @Override |
| 51 | + protected UsageInfo[] findUsages() { |
| 52 | + PsiShortNamesCache cache = PsiShortNamesCache.getInstance(myProject); |
| 53 | + PsiMethod[] methods = cache.getMethodsByName(AsmCodeGenerator.SETUP_METHOD_NAME, GlobalSearchScope.projectScope(myProject)); |
60 | 54 |
|
61 | | - return Arrays.stream(methods).map(UsageInfo::new).toArray(UsageInfo[]::new); |
62 | | - } |
| 55 | + return Arrays.stream(methods).map(UsageInfo::new).toArray(UsageInfo[]::new); |
| 56 | + } |
63 | 57 |
|
64 | | - @Override |
65 | | - protected boolean isPreviewUsages(@Nonnull UsageInfo[] usages) |
66 | | - { |
67 | | - return false; |
68 | | - } |
| 58 | + @Override |
| 59 | + protected boolean isPreviewUsages(@Nonnull UsageInfo[] usages) { |
| 60 | + return false; |
| 61 | + } |
69 | 62 |
|
70 | | - @Override |
71 | | - protected void performRefactoring(@Nonnull UsageInfo[] usageInfos) |
72 | | - { |
73 | | - for(UsageInfo usageInfo : usageInfos) |
74 | | - { |
75 | | - final PsiMethod method = (PsiMethod) usageInfo.getElement(); |
76 | | - final PsiClass aClass = method.getContainingClass(); |
77 | | - if(aClass != null) |
78 | | - { |
79 | | - final PsiFile psiFile = aClass.getContainingFile(); |
80 | | - final VirtualFile vFile = psiFile.getVirtualFile(); |
81 | | - if(vFile.isWritable()) |
82 | | - { |
83 | | - FormSourceCodeGenerator.cleanup(aClass); |
84 | | - } |
85 | | - } |
86 | | - } |
87 | | - } |
| 63 | + @Override |
| 64 | + @RequiredWriteAction |
| 65 | + protected void performRefactoring(@Nonnull UsageInfo[] usageInfos) { |
| 66 | + for (UsageInfo usageInfo : usageInfos) { |
| 67 | + PsiMethod method = (PsiMethod) usageInfo.getElement(); |
| 68 | + PsiClass aClass = method.getContainingClass(); |
| 69 | + if (aClass != null) { |
| 70 | + PsiFile psiFile = aClass.getContainingFile(); |
| 71 | + VirtualFile vFile = psiFile.getVirtualFile(); |
| 72 | + if (vFile.isWritable()) { |
| 73 | + FormSourceCodeGenerator.cleanup(aClass); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
88 | 78 |
|
89 | | - @Nonnull |
90 | | - @Override |
91 | | - protected String getCommandName() |
92 | | - { |
93 | | - return "Converting Methods"; |
94 | | - } |
| 79 | + @Nonnull |
| 80 | + @Override |
| 81 | + protected LocalizeValue getCommandName() { |
| 82 | + return LocalizeValue.localizeTODO("Converting Methods"); |
| 83 | + } |
95 | 84 | } |
0 commit comments