From a32bf89911d4fa5f43b097b0ae843aa6b8dd9af9 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 30 Nov 2021 17:03:40 +0100 Subject: [PATCH 1/2] 685: Code refactoring --- ...oduleDeclarationInModuleXmlInspection.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java index b87e429ec..6af98f860 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java @@ -28,20 +28,22 @@ public class ModuleDeclarationInModuleXmlInspection extends XmlSuppressableInspectionTool { - @NotNull @Override - public PsiElementVisitor buildVisitor( + public @NotNull PsiElementVisitor buildVisitor( final @NotNull ProblemsHolder problemsHolder, final boolean isOnTheFly ) { return new XmlElementVisitor() { + @Override public void visitXmlAttributeValue(final XmlAttributeValue value) { final PsiFile file = value.getContainingFile(); final String filename = file.getName(); - if (!filename.equals(ModuleXml.FILE_NAME)) { + + if (!ModuleXml.FILE_NAME.equals(filename)) { return; } + if (!IsFileInEditableModuleUtil.execute(file)) { return; } @@ -49,21 +51,23 @@ public void visitXmlAttributeValue(final XmlAttributeValue value) { if (isSubTag(value, (XmlFile) file)) { return; } - final PsiDirectory etcDirectory = file.getParent(); + if (etcDirectory == null) { return; } - final String attributeName = XmlAttributeValuePattern.getLocalName(value); + if (attributeName != null && attributeName.equals(ModuleXml.MODULE_ATTR_NAME)) { final String expectedName = GetEditableModuleNameByRootFileUtil.execute(etcDirectory); final String actualName = value.getValue(); + if (actualName.equals(expectedName)) { return; } final InspectionBundle inspectionBundle = new InspectionBundle(); + problemsHolder.registerProblem( value, inspectionBundle.message( @@ -81,26 +85,27 @@ public void visitXmlAttributeValue(final XmlAttributeValue value) { protected boolean isSubTag(final XmlAttributeValue value, final XmlFile file) { final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(value, XmlAttribute.class); + if (xmlAttribute == null) { return true; } - final XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlAttribute, XmlTag.class); + if (xmlTag == null) { return true; } - final XmlDocument xmlDocument = file.getDocument(); + if (xmlDocument == null) { return true; } - final XmlTag xmlRootTag = xmlDocument.getRootTag(); + if (xmlRootTag == null) { return true; } - final XmlTag rootTag = PsiTreeUtil.getParentOfType(xmlTag, XmlTag.class); + return rootTag == null || !(rootTag.getName().equals(xmlRootTag.getName())); } } From 4dd58386c8f56b4ff91e8d28936e441330389d7d Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Tue, 30 Nov 2021 17:07:21 +0100 Subject: [PATCH 2/2] 685: Fixed empty PSI elements must not be passed to createDescriptor for ModuleDeclarationInModuleXmlInspection --- .../inspections/xml/ModuleDeclarationInModuleXmlInspection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java index 6af98f860..0d0ea58fb 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/ModuleDeclarationInModuleXmlInspection.java @@ -63,7 +63,7 @@ public void visitXmlAttributeValue(final XmlAttributeValue value) { = GetEditableModuleNameByRootFileUtil.execute(etcDirectory); final String actualName = value.getValue(); - if (actualName.equals(expectedName)) { + if (actualName.equals(expectedName) || actualName.trim().isEmpty()) { return; } final InspectionBundle inspectionBundle = new InspectionBundle();