|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - |
17 | 16 | package com.jetbrains.python.impl.buildout.config.inspection; |
18 | 17 |
|
19 | 18 | import com.google.common.collect.Lists; |
20 | | -import com.jetbrains.python.impl.PyBundle; |
21 | 19 | import com.jetbrains.python.impl.buildout.config.BuildoutCfgFileType; |
22 | 20 | import com.jetbrains.python.impl.buildout.config.psi.impl.BuildoutCfgValueLine; |
23 | 21 | import com.jetbrains.python.impl.buildout.config.ref.BuildoutPartReference; |
|
31 | 29 | import consulo.language.psi.PsiFile; |
32 | 30 | import consulo.language.psi.PsiRecursiveElementVisitor; |
33 | 31 | import consulo.language.psi.PsiReference; |
34 | | -import org.jetbrains.annotations.Nls; |
35 | | - |
| 32 | +import consulo.localize.LocalizeValue; |
| 33 | +import consulo.python.impl.localize.PyLocalize; |
36 | 34 | import jakarta.annotation.Nonnull; |
| 35 | + |
37 | 36 | import java.util.List; |
38 | 37 |
|
39 | 38 | /** |
40 | 39 | * @author traff |
41 | 40 | */ |
42 | 41 | @ExtensionImpl |
43 | 42 | 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 | + } |
81 | 48 |
|
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(); |
88 | 53 | } |
89 | | - return problems.toArray(new ProblemDescriptor[problems.size()]); |
90 | | - } |
91 | 54 |
|
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 | + } |
94 | 60 |
|
| 61 | + @Nonnull |
95 | 62 | @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 | + } |
104 | 66 |
|
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; |
107 | 70 | } |
108 | 71 |
|
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()]); |
111 | 91 | } |
112 | | - } |
113 | 92 |
|
| 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 | + } |
114 | 109 |
|
| 110 | + public List<BuildoutPartReference> getUnresolvedParts() { |
| 111 | + return unresolvedParts; |
| 112 | + } |
| 113 | + } |
115 | 114 | } |
0 commit comments