Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix:685] Fixed empty psi element in module xml inspection #817

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,46 @@

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;
}

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)) {

if (actualName.equals(expectedName) || actualName.trim().isEmpty()) {
return;
}
final InspectionBundle inspectionBundle = new InspectionBundle();

problemsHolder.registerProblem(
value,
inspectionBundle.message(
Expand All @@ -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()));
}
}