Skip to content

Commit d1ad4e5

Browse files
authored
Merge pull request #24 from unv-unv/inspection-fix-localize-4
Localizing inspection, intentions and quick fixes (part 4)
2 parents 25c6331 + 108bd6a commit d1ad4e5

36 files changed

+3151
-3258
lines changed

python-impl/src/main/java/com/jetbrains/python/impl/buildout/config/inspection/BuildoutUnresolvedPartInspection.java

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package com.jetbrains.python.impl.buildout.config.inspection;
1817

1918
import com.google.common.collect.Lists;
20-
import com.jetbrains.python.impl.PyBundle;
2119
import com.jetbrains.python.impl.buildout.config.BuildoutCfgFileType;
2220
import com.jetbrains.python.impl.buildout.config.psi.impl.BuildoutCfgValueLine;
2321
import com.jetbrains.python.impl.buildout.config.ref.BuildoutPartReference;
@@ -31,85 +29,86 @@
3129
import consulo.language.psi.PsiFile;
3230
import consulo.language.psi.PsiRecursiveElementVisitor;
3331
import consulo.language.psi.PsiReference;
34-
import org.jetbrains.annotations.Nls;
35-
32+
import consulo.localize.LocalizeValue;
33+
import consulo.python.impl.localize.PyLocalize;
3634
import jakarta.annotation.Nonnull;
35+
3736
import java.util.List;
3837

3938
/**
4039
* @author traff
4140
*/
4241
@ExtensionImpl
4342
public class BuildoutUnresolvedPartInspection extends LocalInspectionTool {
44-
@Nls
45-
@Nonnull
46-
@Override
47-
public String getGroupDisplayName() {
48-
return PyBundle.message("buildout");
49-
}
50-
51-
@Nls
52-
@Nonnull
53-
@Override
54-
public String getDisplayName() {
55-
return PyBundle.message("buildout.unresolved.part.inspection");
56-
}
57-
58-
@Nonnull
59-
@Override
60-
public String getShortName() {
61-
return "BuildoutUnresolvedPartInspection";
62-
}
63-
64-
@Nonnull
65-
@Override
66-
public HighlightDisplayLevel getDefaultLevel() {
67-
return HighlightDisplayLevel.WARNING;
68-
}
69-
70-
@Override
71-
public boolean isEnabledByDefault() {
72-
return true;
73-
}
74-
75-
@Override
76-
public ProblemDescriptor[] checkFile(@Nonnull PsiFile file, @Nonnull InspectionManager manager, boolean isOnTheFly) {
77-
List<ProblemDescriptor> problems = Lists.newArrayList();
78-
if (file.getFileType().equals(BuildoutCfgFileType.INSTANCE)) {
79-
Visitor visitor = new Visitor();
80-
file.accept(visitor);
43+
@Nonnull
44+
@Override
45+
public LocalizeValue getGroupDisplayName() {
46+
return PyLocalize.buildout();
47+
}
8148

82-
for (BuildoutPartReference ref : visitor.getUnresolvedParts()) {
83-
ProblemDescriptor d = manager
84-
.createProblemDescriptor(ref.getElement(), ref.getRangeInElement(), PyBundle.message("buildout.unresolved.part.inspection.msg"),
85-
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
86-
problems.add(d);
87-
}
49+
@Nonnull
50+
@Override
51+
public LocalizeValue getDisplayName() {
52+
return PyLocalize.buildoutUnresolvedPartInspection();
8853
}
89-
return problems.toArray(new ProblemDescriptor[problems.size()]);
90-
}
9154

92-
private class Visitor extends PsiRecursiveElementVisitor {
93-
private final List<BuildoutPartReference> unresolvedParts = Lists.newArrayList();
55+
@Nonnull
56+
@Override
57+
public String getShortName() {
58+
return "BuildoutUnresolvedPartInspection";
59+
}
9460

61+
@Nonnull
9562
@Override
96-
public void visitElement(PsiElement element) {
97-
if (element instanceof BuildoutCfgValueLine) {
98-
PsiReference[] refs = element.getReferences();
99-
for (PsiReference ref : refs) {
100-
if (ref instanceof BuildoutPartReference && ref.resolve() == null) {
101-
unresolvedParts.add((BuildoutPartReference)ref);
102-
}
103-
}
63+
public HighlightDisplayLevel getDefaultLevel() {
64+
return HighlightDisplayLevel.WARNING;
65+
}
10466

105-
}
106-
super.visitElement(element); //To change body of overridden methods use File | Settings | File Templates.
67+
@Override
68+
public boolean isEnabledByDefault() {
69+
return true;
10770
}
10871

109-
public List<BuildoutPartReference> getUnresolvedParts() {
110-
return unresolvedParts;
72+
@Override
73+
public ProblemDescriptor[] checkFile(@Nonnull PsiFile file, @Nonnull InspectionManager manager, boolean isOnTheFly) {
74+
List<ProblemDescriptor> problems = Lists.newArrayList();
75+
if (file.getFileType().equals(BuildoutCfgFileType.INSTANCE)) {
76+
Visitor visitor = new Visitor();
77+
file.accept(visitor);
78+
79+
for (BuildoutPartReference ref : visitor.getUnresolvedParts()) {
80+
ProblemDescriptor d = manager.createProblemDescriptor(
81+
ref.getElement(),
82+
ref.getRangeInElement(),
83+
PyLocalize.buildoutUnresolvedPartInspectionMsg().get(),
84+
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
85+
false
86+
);
87+
problems.add(d);
88+
}
89+
}
90+
return problems.toArray(new ProblemDescriptor[problems.size()]);
11191
}
112-
}
11392

93+
private class Visitor extends PsiRecursiveElementVisitor {
94+
private final List<BuildoutPartReference> unresolvedParts = Lists.newArrayList();
95+
96+
@Override
97+
public void visitElement(PsiElement element) {
98+
if (element instanceof BuildoutCfgValueLine) {
99+
PsiReference[] refs = element.getReferences();
100+
for (PsiReference ref : refs) {
101+
if (ref instanceof BuildoutPartReference && ref.resolve() == null) {
102+
unresolvedParts.add((BuildoutPartReference) ref);
103+
}
104+
}
105+
106+
}
107+
super.visitElement(element); //To change body of overridden methods use File | Settings | File Templates.
108+
}
114109

110+
public List<BuildoutPartReference> getUnresolvedParts() {
111+
return unresolvedParts;
112+
}
113+
}
115114
}

python-impl/src/main/java/com/jetbrains/python/impl/codeInsight/intentions/ImportFromToImportIntention.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
package com.jetbrains.python.impl.codeInsight.intentions;
1717

1818
import com.google.common.collect.Sets;
19-
import com.jetbrains.python.impl.PyBundle;
2019
import com.jetbrains.python.impl.psi.PyUtil;
20+
import com.jetbrains.python.impl.psi.types.PyModuleType;
2121
import com.jetbrains.python.psi.*;
2222
import com.jetbrains.python.psi.impl.PyPsiUtils;
23-
import com.jetbrains.python.impl.psi.types.PyModuleType;
2423
import com.jetbrains.python.psi.types.TypeEvalContext;
2524
import consulo.codeEditor.Editor;
2625
import consulo.document.Document;
@@ -33,7 +32,6 @@
3332
import consulo.project.Project;
3433
import consulo.python.impl.localize.PyLocalize;
3534
import consulo.ui.NotificationType;
36-
3735
import jakarta.annotation.Nonnull;
3836
import jakarta.annotation.Nullable;
3937

@@ -325,7 +323,7 @@ public boolean execute(@Nonnull PsiElement element) {
325323
//myFromImportStatement.replace(new_import);
326324
}
327325
catch (IncorrectOperationException ignored) {
328-
PyUtil.showBalloon(project, PyBundle.message("QFIX.action.failed"), NotificationType.WARNING);
326+
PyUtil.showBalloon(project, PyLocalize.qfixActionFailed().get(), NotificationType.WARNING);
329327
}
330328
}
331329
}

python-impl/src/main/java/com/jetbrains/python/impl/codeInsight/intentions/PyBaseIntentionAction.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package com.jetbrains.python.impl.codeInsight.intentions;
1817

19-
2018
import jakarta.annotation.Nonnull;
2119

2220
import consulo.language.editor.FileModificationService;
@@ -26,15 +24,14 @@
2624
import consulo.language.psi.PsiFile;
2725
import consulo.language.util.IncorrectOperationException;
2826

29-
public abstract class PyBaseIntentionAction extends BaseIntentionAction
30-
{
31-
32-
@Override
33-
public final void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
34-
{
35-
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
36-
doInvoke(project, editor, file);
37-
}
27+
public abstract class PyBaseIntentionAction extends BaseIntentionAction {
28+
@Override
29+
public final void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
30+
if (!FileModificationService.getInstance().prepareFileForWrite(file)) {
31+
return;
32+
}
33+
doInvoke(project, editor, file);
34+
}
3835

39-
public abstract void doInvoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException;
36+
public abstract void doInvoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException;
4037
}

0 commit comments

Comments
 (0)