Skip to content

Commit 0f178c7

Browse files
author
Vasilii Burlacu
committed
Added usage of translation bundle for warning messages
1 parent 0935c9a commit 0f178c7

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
2+
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.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.bundles;
7+
8+
public class InspectionBundle extends AbstractBundle {
9+
protected final String BUNDLE_NAME = "magento2.inspection";
10+
11+
public String getBundleName() {
12+
return BUNDLE_NAME;
13+
}
14+
}

src/com/magento/idea/magento2plugin/indexes/PluginIndex.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.intellij.psi.xml.XmlAttributeValue;
1313
import com.intellij.psi.xml.XmlFile;
1414
import com.intellij.util.indexing.FileBasedIndex;
15+
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
1516
import com.magento.idea.magento2plugin.xml.XmlPsiTreeUtil;
1617

1718
import java.util.ArrayList;
@@ -48,7 +49,7 @@ public Collection<PsiElement> getPluginElements(final String name, final GlobalS
4849
for (VirtualFile virtualFile : virtualFiles) {
4950
XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(virtualFile);
5051
Collection<XmlAttributeValue> valueElements = XmlPsiTreeUtil
51-
.findAttributeValueElements(xmlFile, "type", "name", name);
52+
.findAttributeValueElements(xmlFile, ModuleDiXml.PLUGIN_TYPE_ATTRIBUTE, ModuleDiXml.PLUGIN_TYPE_ATTR_NAME, name);
5253
result.addAll(valueElements);
5354
}
5455
return result;

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import com.intellij.psi.xml.XmlDocument;
1919
import com.intellij.psi.xml.XmlTag;
2020
import com.jetbrains.php.lang.inspections.PhpInspection;
21+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
2122
import com.magento.idea.magento2plugin.indexes.PluginIndex;
2223
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
2324
import com.magento.idea.magento2plugin.magento.files.ModuleXml;
2425
import com.magento.idea.magento2plugin.magento.packages.Package;
2526
import org.jetbrains.annotations.NotNull;
2627
import org.jetbrains.annotations.Nullable;
27-
2828
import java.io.File;
2929
import java.net.MalformedURLException;
3030
import java.net.URL;
@@ -37,9 +37,7 @@ public class PluginDeclarationInspection extends PhpInspection {
3737
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
3838
return new XmlElementVisitor() {
3939
private final String moduleXmlFileName = ModuleXml.getInstance().getFileName();
40-
private static final String duplicatedPluginNameSameFileProblemDescription = "The plugin name already used in this file. For more details see Inspection Description.";
41-
private static final String duplicatedPluginNameProblemDescription =
42-
"The plugin name \"%s\" for targeted \"%s\" class is already used in the module \"%s\" (%s scope). For more details see Inspection Description.";
40+
private InspectionBundle inspectionBundle = new InspectionBundle();
4341
private HashMap<String, VirtualFile> loadedFileHash = new HashMap<>();
4442
private final ProblemHighlightType errorSeverity = ProblemHighlightType.WARNING;
4543

@@ -86,7 +84,7 @@ public void visitFile(PsiFile file) {
8684
if (targetPluginHash.containsKey(pluginTypeKey)) {
8785
problemsHolder.registerProblem(
8886
pluginTypeNameAttribute.getValueElement(),
89-
duplicatedPluginNameSameFileProblemDescription,
87+
inspectionBundle.message("inspection.plugin.duplicateInSameFile"),
9088
errorSeverity
9189
);
9290
}
@@ -101,8 +99,8 @@ public void visitFile(PsiFile file) {
10199
if (!pluginProblems.containsKey(problemKey)){
102100
problemsHolder.registerProblem(
103101
pluginTypeNameAttribute.getValueElement(),
104-
String.format(
105-
duplicatedPluginNameProblemDescription,
102+
inspectionBundle.message(
103+
"inspection.plugin.duplicateInOtherPlaces",
106104
pluginTypeName,
107105
pluginNameAttributeValue,
108106
moduleName,

0 commit comments

Comments
 (0)