Skip to content

Commit b313606

Browse files
authored
Localizing refactoring handlers after platform update (part 1). (#268)
1 parent 567fcc3 commit b313606

15 files changed

Lines changed: 1117 additions & 973 deletions

‎plugin/src/main/java/com/intellij/java/impl/codeInspection/inferNullity/InferNullityAnnotationsAction.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private void showUsageView(
329329
SimpleReference<Usage[]> convertUsagesRef = new SimpleReference<>();
330330
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(
331331
() -> project.getApplication().runReadAction(() -> convertUsagesRef.set(UsageInfo2UsageAdapter.convert(usageInfos))),
332-
"Preprocess Usages",
332+
LocalizeValue.localizeTODO("Preprocess Usages"),
333333
true,
334334
project
335335
)) {
@@ -342,27 +342,30 @@ private void showUsageView(
342342
Usage[] usages = convertUsagesRef.get();
343343

344344
UsageViewPresentation presentation = new UsageViewPresentation();
345-
presentation.setTabText("Infer Nullity Preview");
345+
presentation.setTabText(LocalizeValue.localizeTODO("Infer Nullity Preview"));
346346
presentation.setShowReadOnlyStatusAsRed(true);
347347
presentation.setShowCancelButton(true);
348348
presentation.setUsagesString(RefactoringLocalize.usageviewUsagestext());
349349

350350
UsageView usageView =
351-
UsageViewManager.getInstance(project).showUsages(targets, usages, presentation, rerunFactory(annotateLocalVars, project, scope));
351+
UsageViewManager.getInstance(project)
352+
.showUsages(targets, usages, presentation, rerunFactory(annotateLocalVars, project, scope));
352353

353354
Runnable refactoringRunnable = applyRunnable(project, () ->
354355
{
355356
Set<UsageInfo> infos = UsageViewUtil.getNotExcludedUsageInfos(usageView);
356357
return infos.toArray(new UsageInfo[infos.size()]);
357358
});
358359

359-
String canNotMakeString = "Cannot perform operation.\n" +
360-
"There were changes in code after usages have been found.\n" +
361-
"Please perform operation search again.";
360+
LocalizeValue canNotMakeString = LocalizeValue.localizeTODO(
361+
"Cannot perform operation.\n" +
362+
"There were changes in code after usages have been found.\n" +
363+
"Please perform operation search again."
364+
);
362365

363366
usageView.addPerformOperationAction(
364367
refactoringRunnable,
365-
INFER_NULLITY_ANNOTATIONS.get(),
368+
INFER_NULLITY_ANNOTATIONS,
366369
canNotMakeString,
367370
INFER_NULLITY_ANNOTATIONS,
368371
false

‎plugin/src/main/java/com/intellij/java/impl/refactoring/changeClassSignature/ChangeClassSignatureDialog.java‎

Lines changed: 276 additions & 246 deletions
Large diffs are not rendered by default.

‎plugin/src/main/java/com/intellij/java/impl/refactoring/changeClassSignature/ChangeClassSignatureProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected void refreshElements(PsiElement[] elements) {
6666

6767
@Nonnull
6868
@Override
69-
protected String getCommandName() {
69+
protected LocalizeValue getCommandName() {
7070
return ChangeClassSignatureDialog.REFACTORING_NAME;
7171
}
7272

‎plugin/src/main/java/com/intellij/java/impl/refactoring/changeSignature/JavaChangeSignatureUsageSearcher.java‎

Lines changed: 253 additions & 221 deletions
Large diffs are not rendered by default.

‎plugin/src/main/java/com/intellij/java/impl/refactoring/changeSignature/NewParameterCollidesWithLocalUsageInfo.java‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,26 @@
2424
import consulo.localize.LocalizeValue;
2525

2626
/**
27-
* @author dsl
27+
* @author dsl
2828
*/
2929
public class NewParameterCollidesWithLocalUsageInfo extends UnresolvableCollisionUsageInfo {
30-
private final PsiElement myConflictingElement;
31-
private final PsiMethod myMethod;
30+
private final PsiElement myConflictingElement;
31+
private final PsiMethod myMethod;
3232

33-
public NewParameterCollidesWithLocalUsageInfo(PsiElement element, PsiElement referencedElement,
34-
PsiMethod method) {
35-
super(element, referencedElement);
36-
myConflictingElement = referencedElement;
37-
myMethod = method;
38-
}
33+
public NewParameterCollidesWithLocalUsageInfo(
34+
PsiElement element, PsiElement referencedElement,
35+
PsiMethod method
36+
) {
37+
super(element, referencedElement);
38+
myConflictingElement = referencedElement;
39+
myMethod = method;
40+
}
3941

40-
public String getDescription() {
41-
LocalizeValue buffer = RefactoringLocalize.thereIsAlreadyA0In1ItWillConflictWithTheNewParameter(
42-
RefactoringUIUtil.getDescription(myConflictingElement, true),
43-
RefactoringUIUtil.getDescription(myMethod, true)
44-
);
45-
46-
return CommonRefactoringUtil.capitalize(buffer.get());
47-
}
42+
@Override
43+
public LocalizeValue getDescription() {
44+
return RefactoringLocalize.thereIsAlreadyA0In1ItWillConflictWithTheNewParameter(
45+
RefactoringUIUtil.getDescription(myConflictingElement, true),
46+
RefactoringUIUtil.getDescription(myMethod, true)
47+
);
48+
}
4849
}

‎plugin/src/main/java/com/intellij/java/impl/refactoring/convertToInstanceMethod/ConvertToInstanceMethodHandler.java‎

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import consulo.codeEditor.Editor;
2121
import consulo.codeEditor.ScrollType;
2222
import consulo.dataContext.DataContext;
23-
import consulo.language.editor.refactoring.RefactoringBundle;
2423
import consulo.language.editor.refactoring.action.RefactoringActionHandler;
2524
import consulo.language.editor.refactoring.localize.RefactoringLocalize;
2625
import consulo.language.editor.refactoring.util.CommonRefactoringUtil;
@@ -39,90 +38,99 @@
3938
* @author dsl
4039
*/
4140
public class ConvertToInstanceMethodHandler implements RefactoringActionHandler {
42-
private static final Logger LOG = Logger.getInstance(ConvertToInstanceMethodHandler.class);
43-
static final String REFACTORING_NAME = RefactoringBundle.message("convert.to.instance.method.title");
41+
private static final Logger LOG = Logger.getInstance(ConvertToInstanceMethodHandler.class);
42+
static final LocalizeValue REFACTORING_NAME = RefactoringLocalize.convertToInstanceMethodTitle();
4443

45-
@RequiredUIAccess
46-
public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataContext dataContext) {
47-
PsiElement element = dataContext.getData(PsiElement.KEY);
48-
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
49-
if (element == null) {
50-
element = file.findElementAt(editor.getCaretModel().getOffset());
51-
}
44+
@Override
45+
@RequiredUIAccess
46+
public void invoke(@Nonnull Project project, Editor editor, PsiFile file, DataContext dataContext) {
47+
PsiElement element = dataContext.getData(PsiElement.KEY);
48+
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
49+
if (element == null) {
50+
element = file.findElementAt(editor.getCaretModel().getOffset());
51+
}
5252

53-
if (element == null) return;
54-
if (element instanceof PsiIdentifier) element = element.getParent();
53+
if (element == null) {
54+
return;
55+
}
56+
if (element instanceof PsiIdentifier) {
57+
element = element.getParent();
58+
}
5559

56-
if (!(element instanceof PsiMethod)) {
57-
LocalizeValue message = RefactoringLocalize.cannotPerformRefactoringWithReason(RefactoringLocalize.errorWrongCaretPositionMethod());
58-
CommonRefactoringUtil.showErrorHint(project, editor, message.get(), REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
59-
return;
60-
}
61-
if (LOG.isDebugEnabled()) {
62-
LOG.debug("MakeMethodStaticHandler invoked");
60+
if (!(element instanceof PsiMethod)) {
61+
LocalizeValue message =
62+
RefactoringLocalize.cannotPerformRefactoringWithReason(RefactoringLocalize.errorWrongCaretPositionMethod());
63+
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
64+
return;
65+
}
66+
if (LOG.isDebugEnabled()) {
67+
LOG.debug("MakeMethodStaticHandler invoked");
68+
}
69+
invoke(project, new PsiElement[]{element}, dataContext);
6370
}
64-
invoke(project, new PsiElement[]{element}, dataContext);
65-
}
6671

67-
@RequiredUIAccess
68-
public void invoke(@Nonnull Project project, @Nonnull PsiElement[] elements, DataContext dataContext) {
69-
if (elements.length != 1 || !(elements[0] instanceof PsiMethod)) return;
70-
PsiMethod method = (PsiMethod)elements[0];
71-
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
72-
LocalizeValue message = RefactoringLocalize.converttoinstancemethodMethodIsNotStatic(method.getName());
73-
Editor editor = dataContext.getData(Editor.KEY);
74-
CommonRefactoringUtil.showErrorHint(project, editor, message.get(), REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
75-
return;
76-
}
77-
PsiParameter[] parameters = method.getParameterList().getParameters();
78-
List<PsiParameter> suitableParameters = new ArrayList<>();
79-
boolean classTypesFound = false;
80-
boolean resolvableClassesFound = false;
81-
boolean classesInProjectFound = false;
82-
for (PsiParameter parameter : parameters) {
83-
PsiType type = parameter.getType();
84-
if (type instanceof PsiClassType classType) {
85-
classTypesFound = true;
86-
PsiClass psiClass = classType.resolve();
87-
if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) {
88-
resolvableClassesFound = true;
89-
boolean inProject = method.getManager().isInProject(psiClass);
90-
if (inProject) {
91-
classesInProjectFound = true;
92-
suitableParameters.add(parameter);
93-
}
72+
@Override
73+
@RequiredUIAccess
74+
public void invoke(@Nonnull Project project, @Nonnull PsiElement[] elements, DataContext dataContext) {
75+
if (elements.length != 1 || !(elements[0] instanceof PsiMethod)) {
76+
return;
77+
}
78+
PsiMethod method = (PsiMethod) elements[0];
79+
if (!method.isStatic()) {
80+
LocalizeValue message = RefactoringLocalize.converttoinstancemethodMethodIsNotStatic(method.getName());
81+
Editor editor = dataContext.getData(Editor.KEY);
82+
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.CONVERT_TO_INSTANCE_METHOD);
83+
return;
84+
}
85+
PsiParameter[] parameters = method.getParameterList().getParameters();
86+
List<PsiParameter> suitableParameters = new ArrayList<>();
87+
boolean classTypesFound = false;
88+
boolean resolvableClassesFound = false;
89+
boolean classesInProjectFound = false;
90+
for (PsiParameter parameter : parameters) {
91+
PsiType type = parameter.getType();
92+
if (type instanceof PsiClassType classType) {
93+
classTypesFound = true;
94+
PsiClass psiClass = classType.resolve();
95+
if (psiClass != null && !(psiClass instanceof PsiTypeParameter)) {
96+
resolvableClassesFound = true;
97+
boolean inProject = method.getManager().isInProject(psiClass);
98+
if (inProject) {
99+
classesInProjectFound = true;
100+
suitableParameters.add(parameter);
101+
}
102+
}
103+
}
104+
}
105+
if (suitableParameters.isEmpty()) {
106+
LocalizeValue message;
107+
if (!classTypesFound) {
108+
message = RefactoringLocalize.converttoinstancemethodNoParametersWithReferenceType();
109+
}
110+
else if (!resolvableClassesFound) {
111+
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametresHaveUnknownTypes();
112+
}
113+
else if (!classesInProjectFound) {
114+
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametersAreNotInProject();
115+
}
116+
else {
117+
LOG.assertTrue(false);
118+
return;
119+
}
120+
Editor editor = dataContext.getData(Editor.KEY);
121+
CommonRefactoringUtil.showErrorHint(
122+
project,
123+
editor,
124+
RefactoringLocalize.cannotPerformRefactoringWithReason(message),
125+
REFACTORING_NAME,
126+
HelpID.CONVERT_TO_INSTANCE_METHOD
127+
);
128+
return;
94129
}
95-
}
96-
}
97-
if (suitableParameters.isEmpty()) {
98-
LocalizeValue message;
99-
if (!classTypesFound) {
100-
message = RefactoringLocalize.converttoinstancemethodNoParametersWithReferenceType();
101-
}
102-
else if (!resolvableClassesFound) {
103-
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametresHaveUnknownTypes();
104-
}
105-
else if (!classesInProjectFound) {
106-
message = RefactoringLocalize.converttoinstancemethodAllReferenceTypeParametersAreNotInProject();
107-
}
108-
else {
109-
LOG.assertTrue(false);
110-
return;
111-
}
112-
Editor editor = dataContext.getData(Editor.KEY);
113-
CommonRefactoringUtil.showErrorHint(
114-
project,
115-
editor,
116-
RefactoringLocalize.cannotPerformRefactoringWithReason(message).get(),
117-
REFACTORING_NAME,
118-
HelpID.CONVERT_TO_INSTANCE_METHOD
119-
);
120-
return;
121-
}
122130

123-
new ConvertToInstanceMethodDialog(
124-
method,
125-
suitableParameters.toArray(new PsiParameter[suitableParameters.size()])
126-
).show();
127-
}
131+
new ConvertToInstanceMethodDialog(
132+
method,
133+
suitableParameters.toArray(new PsiParameter[suitableParameters.size()])
134+
).show();
135+
}
128136
}

‎plugin/src/main/java/com/intellij/java/impl/refactoring/convertToInstanceMethod/ConvertToInstanceMethodProcessor.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected boolean preprocessUsages(@Nonnull SimpleReference<UsageInfo[]> refUsag
184184
}
185185

186186
@Override
187-
@RequiredUIAccess
187+
@RequiredWriteAction
188188
protected void performRefactoring(@Nonnull UsageInfo[] usages) {
189189
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, myTargetClass)) {
190190
return;
@@ -240,7 +240,8 @@ else if (usage instanceof ImplementingClassUsageInfo implementingClassUsageInfo)
240240
PsiMethod newMethod = addMethodToClass(psiClass);
241241
PsiUtil.setModifierProperty(
242242
newMethod,
243-
myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY) ? myNewVisibility
243+
myNewVisibility != null && !myNewVisibility.equals(VisibilityUtil.ESCALATE_VISIBILITY)
244+
? myNewVisibility
244245
: PsiModifier.PUBLIC,
245246
true
246247
);
@@ -381,7 +382,7 @@ private void processMethodCall(MethodCallUsageInfo usageInfo) throws IncorrectOp
381382

382383
@Nonnull
383384
@Override
384-
protected String getCommandName() {
385+
protected LocalizeValue getCommandName() {
385386
return ConvertToInstanceMethodHandler.REFACTORING_NAME;
386387
}
387388

‎plugin/src/main/java/com/intellij/java/impl/refactoring/encapsulateFields/EncapsulateFieldsProcessor.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ protected UsageViewDescriptor createUsageViewDescriptor(@Nonnull UsageInfo[] usa
9191
@Nonnull
9292
@Override
9393
@RequiredReadAction
94-
protected String getCommandName() {
95-
return RefactoringLocalize.encapsulateFieldsCommandName(DescriptiveNameUtil.getDescriptiveName(myClass)).get();
94+
protected LocalizeValue getCommandName() {
95+
return RefactoringLocalize.encapsulateFieldsCommandName(DescriptiveNameUtil.getDescriptiveName(myClass));
9696
}
9797

9898
@Override

0 commit comments

Comments
 (0)