2828
2929public 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 ();
63- if (actualName .equals (expectedName )) {
65+
66+ if (actualName .equals (expectedName ) || actualName .trim ().isEmpty ()) {
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