|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | +package com.magento.idea.magento2plugin.inspections.xml; |
| 6 | + |
| 7 | +import com.intellij.codeInspection.ProblemHighlightType; |
| 8 | +import com.intellij.codeInspection.ProblemsHolder; |
| 9 | +import com.intellij.codeInspection.XmlSuppressableInspectionTool; |
| 10 | +import com.intellij.psi.PsiElementVisitor; |
| 11 | +import com.intellij.psi.XmlElementVisitor; |
| 12 | +import com.intellij.psi.xml.XmlAttribute; |
| 13 | +import com.magento.idea.magento2plugin.inspections.xml.fix.XmlRemoveCacheableAttributeQuickFix; |
| 14 | +import com.magento.idea.magento2plugin.magento.files.LayoutXml; |
| 15 | +import org.jetbrains.annotations.NotNull; |
| 16 | + |
| 17 | +public class CacheableFalseInDefaultLayoutInspection extends XmlSuppressableInspectionTool { |
| 18 | + @NotNull |
| 19 | + @Override |
| 20 | + public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly) { |
| 21 | + return new XmlElementVisitor() { |
| 22 | + private static final String CacheDisableProblemDescription = "Cacheable false attribute on the default layout will disable cache site-wide"; |
| 23 | + @Override |
| 24 | + public void visitXmlAttribute(XmlAttribute attribute) { |
| 25 | + String fileName = holder.getFile().getName(); |
| 26 | + if (!fileName.equals(LayoutXml.DefaultFileName)) return; |
| 27 | + final String text = attribute.getValue(); |
| 28 | + final String attributeName = attribute.getName(); |
| 29 | + if (!attributeName.equals(LayoutXml.CacheableAttributeName)) return; |
| 30 | + if (!attribute.getParent().getName().equals(LayoutXml.BlockAttributeTagName)) return; |
| 31 | + if (text == null) return; |
| 32 | + if (text.equals(LayoutXml.CacheableAttributeFalseValue)) { |
| 33 | + holder.registerProblem(attribute, CacheDisableProblemDescription, |
| 34 | + ProblemHighlightType.WARNING, |
| 35 | + new XmlRemoveCacheableAttributeQuickFix()); |
| 36 | + } |
| 37 | + } |
| 38 | + }; |
| 39 | + } |
| 40 | +} |
0 commit comments