Skip to content

Commit a32bf89

Browse files
685: Code refactoring
1 parent a625f4b commit a32bf89

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,46 @@
2828

2929
public class ModuleDeclarationInModuleXmlInspection extends XmlSuppressableInspectionTool {
3030

31-
@NotNull
3231
@Override
33-
public PsiElementVisitor buildVisitor(
32+
public @NotNull PsiElementVisitor buildVisitor(
3433
final @NotNull ProblemsHolder problemsHolder,
3534
final boolean isOnTheFly
3635
) {
3736
return new XmlElementVisitor() {
37+
3838
@Override
3939
public void visitXmlAttributeValue(final XmlAttributeValue value) {
4040
final PsiFile file = value.getContainingFile();
4141
final String filename = file.getName();
42-
if (!filename.equals(ModuleXml.FILE_NAME)) {
42+
43+
if (!ModuleXml.FILE_NAME.equals(filename)) {
4344
return;
4445
}
46+
4547
if (!IsFileInEditableModuleUtil.execute(file)) {
4648
return;
4749
}
4850

4951
if (isSubTag(value, (XmlFile) file)) {
5052
return;
5153
}
52-
5354
final PsiDirectory etcDirectory = file.getParent();
55+
5456
if (etcDirectory == null) {
5557
return;
5658
}
57-
5859
final String attributeName = XmlAttributeValuePattern.getLocalName(value);
60+
5961
if (attributeName != null && attributeName.equals(ModuleXml.MODULE_ATTR_NAME)) {
6062
final String expectedName
6163
= GetEditableModuleNameByRootFileUtil.execute(etcDirectory);
6264
final String actualName = value.getValue();
65+
6366
if (actualName.equals(expectedName)) {
6467
return;
6568
}
6669
final InspectionBundle inspectionBundle = new InspectionBundle();
70+
6771
problemsHolder.registerProblem(
6872
value,
6973
inspectionBundle.message(
@@ -81,26 +85,27 @@ public void visitXmlAttributeValue(final XmlAttributeValue value) {
8185

8286
protected boolean isSubTag(final XmlAttributeValue value, final XmlFile file) {
8387
final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(value, XmlAttribute.class);
88+
8489
if (xmlAttribute == null) {
8590
return true;
8691
}
87-
8892
final XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlAttribute, XmlTag.class);
93+
8994
if (xmlTag == null) {
9095
return true;
9196
}
92-
9397
final XmlDocument xmlDocument = file.getDocument();
98+
9499
if (xmlDocument == null) {
95100
return true;
96101
}
97-
98102
final XmlTag xmlRootTag = xmlDocument.getRootTag();
103+
99104
if (xmlRootTag == null) {
100105
return true;
101106
}
102-
103107
final XmlTag rootTag = PsiTreeUtil.getParentOfType(xmlTag, XmlTag.class);
108+
104109
return rootTag == null || !(rootTag.getName().equals(xmlRootTag.getName()));
105110
}
106111
}

0 commit comments

Comments
 (0)