Skip to content

Commit 836178f

Browse files
committed
Extracting the inspection static text to Inspection Bundle
1 parent 49c7687 commit 836178f

File tree

4 files changed

+73
-27
lines changed

4 files changed

+73
-27
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
inspection.class.hierarchyImplementationCheck=Class must implement {0}
2+
inspection.class.hierarchyExtendingCheck=Class must extend {0}
13
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
24
inspection.plugin.duplicateInOtherPlaces=The plugin name "{0}" for targeted "{1}" class is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
35
inspection.graphql.resolver.mustImplement=Class must implements any of the following interfaces: \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchServiceContractResolverInterface
46
inspection.graphql.resolver.fix.family=Implement Resolver interface
57
inspection.graphql.resolver.fix.title=Select one of the following interface
8+
inspection.plugin.error.nonPublicMethod=You can't declare a plugin for a not public method.
9+
inspection.plugin.error.finalClass=You can't declare a plugin for a final class.
10+
inspection.plugin.error.finalMethod=You can't declare a plugin for a final method.
11+
inspection.plugin.error.staticMethod=You can't declare a plugin for a static method.
12+
inspection.plugin.error.constructMethod=You can't declare a plugin for a __construct method.
13+
inspection.plugin.error.redundantParameter=Redundant parameter
14+
inspection.plugin.error.typeIncompatibility=Possible type incompatibility. Consider changing the parameter according to the target method.
15+
inspection.observer.duplicateInSameFile=The observer name already used in this file. For more details see Inspection Description.
16+
inspection.observer.duplicateInOtherPlaces=The observer name "{0}" for event "{1}" is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
17+
inspection.cache.disabledCache=Cacheable false attribute on the default layout will disable cache site-wide

src/com/magento/idea/magento2plugin/inspections/php/PluginInspection.java

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.jetbrains.php.lang.psi.elements.Parameter;
1919
import com.jetbrains.php.lang.psi.elements.PhpClass;
2020
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
21+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
2122
import com.magento.idea.magento2plugin.inspections.php.util.PhpClassImplementsInterfaceUtil;
2223
import com.magento.idea.magento2plugin.magento.files.Plugin;
2324
import com.magento.idea.magento2plugin.magento.packages.Package;
@@ -32,15 +33,9 @@ public class PluginInspection extends PhpInspection {
3233
@Override
3334
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
3435
return new PhpElementVisitor() {
35-
private static final String pluginOnNotPublicMethodProblemDescription = "You can't declare a plugin for a not public method";
36-
private static final String pluginOnFinalClassProblemDescription = "You can't declare a plugin for a final class!";
37-
private static final String pluginOnFinalMethodProblemDescription = "You can't declare a plugin for a final method!";
38-
private static final String pluginOnStaticMethodProblemDescription = "You can't declare a plugin for a static method!";
39-
private static final String pluginOnConstructorMethodProblemDescription = "You can't declare a plugin for a __construct method!";
40-
private static final String redundantParameterProblemDescription = "Redundant parameter";
41-
private static final String possibleTypeIncompatibilityProblemDescription = "Possible type incompatibility. Consider changing the parameter according to the target method.";
4236
private final Integer beforePluginExtraParamsStart = 2;
4337
private final Integer afterAndAroundPluginExtraParamsStart = 3;
38+
private InspectionBundle inspectionBundle = new InspectionBundle();
4439

4540
private String getPluginPrefix(Method pluginMethod) {
4641
String pluginMethodName = pluginMethod.getName();
@@ -99,23 +94,43 @@ private void checkTargetClass(PsiElement currentClassNameIdentifier, PhpClass ta
9994
ProblemDescriptor[] currentResults = problemsHolder.getResultsArray();
10095
int finalClassProblems = getFinalClassProblems(currentResults);
10196
if (finalClassProblems == 0) {
102-
problemsHolder.registerProblem(currentClassNameIdentifier, pluginOnFinalClassProblemDescription, ProblemHighlightType.ERROR);
97+
problemsHolder.registerProblem(
98+
currentClassNameIdentifier,
99+
inspectionBundle.message("inspection.plugin.error.finalClass"),
100+
ProblemHighlightType.ERROR
101+
);
103102
}
104103
}
105104
}
106105

107106
private void checkTargetMethod(Method pluginMethod, String targetClassMethodName, Method targetMethod) {
108107
if (targetClassMethodName.equals(Plugin.constructMethodName)) {
109-
problemsHolder.registerProblem(pluginMethod.getNameIdentifier(), pluginOnConstructorMethodProblemDescription, ProblemHighlightType.ERROR);
108+
problemsHolder.registerProblem(
109+
pluginMethod.getNameIdentifier(),
110+
inspectionBundle.message("inspection.plugin.error.constructMethod"),
111+
ProblemHighlightType.ERROR
112+
);
110113
}
111114
if (targetMethod.isFinal()) {
112-
problemsHolder.registerProblem(pluginMethod.getNameIdentifier(), pluginOnFinalMethodProblemDescription, ProblemHighlightType.ERROR);
115+
problemsHolder.registerProblem(
116+
pluginMethod.getNameIdentifier(),
117+
inspectionBundle.message("inspection.plugin.error.finalMethod"),
118+
ProblemHighlightType.ERROR
119+
);
113120
}
114121
if (targetMethod.isStatic()) {
115-
problemsHolder.registerProblem(pluginMethod.getNameIdentifier(), pluginOnStaticMethodProblemDescription, ProblemHighlightType.ERROR);
122+
problemsHolder.registerProblem(
123+
pluginMethod.getNameIdentifier(),
124+
inspectionBundle.message("inspection.plugin.error.staticMethod"),
125+
ProblemHighlightType.ERROR
126+
);
116127
}
117128
if (!targetMethod.getAccess().toString().equals(Plugin.publicAccess)) {
118-
problemsHolder.registerProblem(pluginMethod.getNameIdentifier(), pluginOnNotPublicMethodProblemDescription, ProblemHighlightType.ERROR);
129+
problemsHolder.registerProblem(
130+
pluginMethod.getNameIdentifier(),
131+
inspectionBundle.message("inspection.plugin.error.nonPublicMethod"),
132+
ProblemHighlightType.ERROR
133+
);
119134
}
120135
}
121136

@@ -134,7 +149,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
134149
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, targetClassFqn}), ProblemHighlightType.ERROR);
135150
}
136151
if (!checkPossibleTypeIncompatibility(targetClassFqn, declaredType, phpIndex)) {
137-
problemsHolder.registerProblem(pluginMethodParameter, possibleTypeIncompatibilityProblemDescription, ProblemHighlightType.WEAK_WARNING);
152+
problemsHolder.registerProblem(
153+
pluginMethodParameter,
154+
inspectionBundle.message("inspection.plugin.error.typeIncompatibility"),
155+
ProblemHighlightType.WEAK_WARNING
156+
);
138157
}
139158
continue;
140159
}
@@ -154,7 +173,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
154173
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, targetMethod.getDeclaredType().toString()}), ProblemHighlightType.ERROR);
155174
}
156175
if (!checkPossibleTypeIncompatibility(targetMethod.getDeclaredType().toString(), declaredType, phpIndex)) {
157-
problemsHolder.registerProblem(pluginMethodParameter, possibleTypeIncompatibilityProblemDescription, ProblemHighlightType.WEAK_WARNING);
176+
problemsHolder.registerProblem(
177+
pluginMethodParameter,
178+
inspectionBundle.message("inspection.plugin.error.typeIncompatibility"),
179+
ProblemHighlightType.WEAK_WARNING
180+
);
158181
}
159182
continue;
160183
}
@@ -172,7 +195,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
172195
beforePluginExtraParamsStart :
173196
afterAndAroundPluginExtraParamsStart);
174197
if (targetMethodParameters.length <= targetParameterKey) {
175-
problemsHolder.registerProblem(pluginMethodParameter, redundantParameterProblemDescription, ProblemHighlightType.ERROR);
198+
problemsHolder.registerProblem(
199+
pluginMethodParameter,
200+
inspectionBundle.message("inspection.plugin.error.redundantParameter"),
201+
ProblemHighlightType.ERROR
202+
);
176203
continue;
177204
}
178205
Parameter targetMethodParameter = targetMethodParameters[targetParameterKey];
@@ -182,7 +209,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
182209
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, targetMethodParameterDeclaredType}), ProblemHighlightType.ERROR);
183210
}
184211
if (!checkPossibleTypeIncompatibility(targetMethodParameterDeclaredType, declaredType, phpIndex)) {
185-
problemsHolder.registerProblem(pluginMethodParameter, possibleTypeIncompatibilityProblemDescription, ProblemHighlightType.WEAK_WARNING);
212+
problemsHolder.registerProblem(
213+
pluginMethodParameter,
214+
inspectionBundle.message("inspection.plugin.error.typeIncompatibility"),
215+
ProblemHighlightType.WEAK_WARNING
216+
);
186217
}
187218
}
188219
}
@@ -204,7 +235,7 @@ private String getTargetMethodName(Method pluginMethod, String pluginPrefix) {
204235
private int getFinalClassProblems(ProblemDescriptor[] currentResults) {
205236
int finalClassProblems = 0;
206237
for (ProblemDescriptor currentProblem : currentResults) {
207-
if (currentProblem.getDescriptionTemplate().equals(pluginOnFinalClassProblemDescription)) {
238+
if (currentProblem.getDescriptionTemplate().equals(inspectionBundle.message("inspection.plugin.error.finalClass"))) {
208239
finalClassProblems++;
209240
}
210241
}

src/com/magento/idea/magento2plugin/inspections/xml/CacheableFalseInDefaultLayoutInspection.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
import com.intellij.psi.PsiElementVisitor;
1111
import com.intellij.psi.XmlElementVisitor;
1212
import com.intellij.psi.xml.XmlAttribute;
13+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
1314
import com.magento.idea.magento2plugin.inspections.xml.fix.XmlRemoveCacheableAttributeQuickFix;
1415
import com.magento.idea.magento2plugin.magento.files.LayoutXml;
1516
import org.jetbrains.annotations.NotNull;
1617

1718
public class CacheableFalseInDefaultLayoutInspection extends XmlSuppressableInspectionTool {
18-
public static final String CacheDisableProblemDescription = "Cacheable false attribute on the default layout will disable cache site-wide";
19-
2019
@NotNull
2120
@Override
2221
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly) {
2322
return new XmlElementVisitor() {
23+
private InspectionBundle inspectionBundle = new InspectionBundle();
24+
2425
@Override
2526
public void visitXmlAttribute(XmlAttribute attribute) {
2627
String fileName = holder.getFile().getName();
@@ -32,9 +33,12 @@ public void visitXmlAttribute(XmlAttribute attribute) {
3233
&& !attribute.getParent().getName().equals(LayoutXml.REFERENCE_BLOCK_ATTRIBUTE_TAG_NAME)) return;
3334
if (text == null) return;
3435
if (text.equals(LayoutXml.CACHEABLE_ATTRIBUTE_VALUE_FALSE)) {
35-
holder.registerProblem(attribute, CacheDisableProblemDescription,
36-
ProblemHighlightType.WARNING,
37-
new XmlRemoveCacheableAttributeQuickFix());
36+
holder.registerProblem(
37+
attribute,
38+
inspectionBundle.message("inspection.cache.disabledCache"),
39+
ProblemHighlightType.WARNING,
40+
new XmlRemoveCacheableAttributeQuickFix()
41+
);
3842
}
3943
}
4044
};

src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.intellij.psi.xml.XmlDocument;
1818
import com.intellij.psi.xml.XmlTag;
1919
import com.jetbrains.php.lang.inspections.PhpInspection;
20+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
2021
import com.magento.idea.magento2plugin.indexes.EventIndex;
2122
import com.magento.idea.magento2plugin.magento.files.ModuleXml;
2223
import com.magento.idea.magento2plugin.magento.packages.Package;
@@ -36,10 +37,8 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, bo
3637
return new XmlElementVisitor() {
3738
private final String moduleXmlFileName = ModuleXml.getInstance().getFileName();
3839
private static final String eventsXmlFileName = "events.xml";
39-
private static final String duplicatedObserverNameSameFileProblemDescription = "The observer name already used in this file. For more details see Inspection Description.";
40-
private static final String duplicatedObserverNameProblemDescription =
41-
"The observer name \"%s\" for event \"%s\" is already used in the module \"%s\" (%s scope). For more details see Inspection Description.";
4240
private HashMap<String, VirtualFile> loadedFileHash = new HashMap<>();
41+
private InspectionBundle inspectionBundle = new InspectionBundle();
4342
private final ProblemHighlightType errorSeverity = ProblemHighlightType.WARNING;
4443

4544
@Override
@@ -88,7 +87,7 @@ public void visitFile(PsiFile file) {
8887
if (targetObserversHash.containsKey(observerKey)) {
8988
problemsHolder.registerProblem(
9089
observerNameAttribute.getValueElement(),
91-
duplicatedObserverNameSameFileProblemDescription,
90+
inspectionBundle.message("inspection.observer.duplicateInSameFile"),
9291
errorSeverity
9392
);
9493
}
@@ -104,7 +103,7 @@ public void visitFile(PsiFile file) {
104103
problemsHolder.registerProblem(
105104
observerNameAttribute.getValueElement(),
106105
String.format(
107-
duplicatedObserverNameProblemDescription,
106+
inspectionBundle.message("inspection.observer.duplicateInOtherPlaces"),
108107
observerName,
109108
eventNameAttributeValue,
110109
moduleName,

0 commit comments

Comments
 (0)