Skip to content

Commit f1d1f58

Browse files
committed
Localizing ProcessAnnotationsAction.
1 parent 6becd5f commit f1d1f58

2 files changed

Lines changed: 34 additions & 35 deletions

File tree

java-compiler-impl/src/main/java/com/intellij/java/compiler/impl/actions/ProcessAnnotationsAction.java

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,18 @@
2424
import consulo.compiler.Compiler;
2525
import consulo.compiler.CompilerManager;
2626
import consulo.compiler.action.CompileActionBase;
27-
import consulo.compiler.localize.CompilerLocalize;
2827
import consulo.compiler.resourceCompiler.ResourceCompiler;
2928
import consulo.compiler.scope.FileSetCompileScope;
3029
import consulo.compiler.scope.ModuleCompileScope;
3130
import consulo.dataContext.DataContext;
31+
import consulo.java.compiler.localize.JavaCompilerLocalize;
3232
import consulo.language.editor.LangDataKeys;
3333
import consulo.language.psi.PsiDirectory;
3434
import consulo.language.psi.PsiElement;
3535
import consulo.language.psi.PsiManager;
36-
import consulo.localize.LocalizeValue;
3736
import consulo.module.Module;
3837
import consulo.module.content.ProjectFileIndex;
3938
import consulo.module.content.ProjectRootManager;
40-
import consulo.platform.base.localize.ActionLocalize;
4139
import consulo.project.Project;
4240
import consulo.ui.annotation.RequiredUIAccess;
4341
import consulo.ui.ex.action.ActionPlaces;
@@ -56,6 +54,10 @@
5654
import java.util.function.Predicate;
5755

5856
public class ProcessAnnotationsAction extends CompileActionBase {
57+
public ProcessAnnotationsAction() {
58+
super(JavaCompilerLocalize.actionRunAptText(), JavaCompilerLocalize.actionRunAptDescription(), null);
59+
}
60+
5961
@Override
6062
@RequiredUIAccess
6163
protected void doAction(DataContext dataContext, Project project) {
@@ -106,17 +108,18 @@ public void update(@Nonnull AnActionEvent event) {
106108
return;
107109
}
108110

111+
presentation.setEnabled(true);
109112
presentation.setVisible(true);
110-
presentation.setTextValue(createPresentationText(""));
113+
presentation.setTextValue(JavaCompilerLocalize.actionRunAptText());
114+
111115
FileSetCompileScope scope = getCompilableFiles(project, event.getData(VirtualFile.KEY_OF_ARRAY));
112116
if (moduleContext == null && scope == null) {
113117
presentation.setEnabled(false);
114118
return;
115119
}
116120

117-
LocalizeValue elementDescription = LocalizeValue.empty();
118121
if (moduleContext != null) {
119-
elementDescription = CompilerLocalize.actionCompileDescriptionModule(moduleContext.getName());
122+
presentation.setTextValue(JavaCompilerLocalize.actionRunAptModuleText(trimName(moduleContext.getName())));
120123
}
121124
else {
122125
PsiJavaPackage aPackage = null;
@@ -136,49 +139,33 @@ public void update(@Nonnull AnActionEvent event) {
136139

137140
if (aPackage != null) {
138141
String name = aPackage.getQualifiedName();
139-
if (name.isEmpty()) {
140-
//noinspection HardCodedStringLiteral
141-
name = "<default>";
142-
}
143-
elementDescription = LocalizeValue.localizeTODO("'" + name + "'");
142+
presentation.setTextValue(
143+
StringUtil.isNotEmpty(name)
144+
? JavaCompilerLocalize.actionRunApt0Text(trimName(name))
145+
: JavaCompilerLocalize.actionRunAptDefaultText()
146+
);
144147
}
145148
else if (files.size() == 1) {
146149
VirtualFile file = files.iterator().next();
147150
FileType fileType = file.getFileType();
148151
if (CompilerManager.getInstance(project).isCompilableFileType(fileType)) {
149-
elementDescription = LocalizeValue.localizeTODO("'" + file.getName() + "'");
152+
presentation.setTextValue(JavaCompilerLocalize.actionRunApt0Text(trimName(file.getName())));
150153
}
151154
else {
152-
if (!ActionPlaces.MAIN_MENU.equals(event.getPlace())) {
153-
// the action should be invisible in popups for non-java files
154-
presentation.setEnabled(false);
155-
presentation.setVisible(false);
156-
return;
157-
}
155+
presentation.setEnabled(false);
156+
// the action should be invisible in popups for non-java files
157+
presentation.setVisible(ActionPlaces.MAIN_MENU.equals(event.getPlace()));
158158
}
159159
}
160160
else {
161-
elementDescription = CompilerLocalize.actionCompileDescriptionSelectedFiles();
161+
presentation.setTextValue(JavaCompilerLocalize.actionRunAptSelectedFilesText());
162162
}
163163
}
164-
165-
if (elementDescription == null) {
166-
presentation.setEnabled(false);
167-
return;
168-
}
169-
170-
presentation.setTextValue(createPresentationText(elementDescription.get()));
171-
presentation.setEnabled(true);
172164
}
173165

174-
private static LocalizeValue createPresentationText(String elementDescription) {
175-
int length = elementDescription.length();
176-
String target = length > 23
177-
? (StringUtil.startsWithChar(elementDescription, '\'') ? "'..." : "...") + elementDescription.substring(length - 20, length)
178-
: elementDescription;
179-
return StringUtil.isEmpty(target)
180-
? ActionLocalize.actionRunaptText()
181-
: ActionLocalize.actionRunapt1Text(target);
166+
private static String trimName(String name) {
167+
int length = name.length();
168+
return length > 23 ? '…' + name.substring(length - 20, length) : name;
182169
}
183170

184171
@Nullable

java-compiler-impl/src/main/resources/LOCALIZE-LIB/en_US/consulo.java.compiler.JavaCompilerLocalize.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
action.run.apt.0.text:
2+
text: Process ''{0}'' _Annotations
3+
action.run.apt.default.text:
4+
text: Process <default> _Annotations
5+
action.run.apt.description:
6+
text: Run Annotation Processors on the selected scope
7+
action.run.apt.module.text:
8+
text: Process Module ''{0}'' _Annotations
9+
action.run.apt.selected.files.text:
10+
text: Process Selected Files _Annotations
11+
action.run.apt.text:
12+
text: Process _Annotations
113
add.notnull.assertions:
214
text: Add @NotNull &assertions
315
compiler.eclipse.embedded.name:

0 commit comments

Comments
 (0)