mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-27035 Redundant default attribute value assignment.
This commit is contained in:
@@ -57,4 +57,10 @@ public class XmlInspectionsTest extends LightPlatformCodeInsightFixtureTestCase
|
||||
"</html>\n");
|
||||
myFixture.checkHighlighting();
|
||||
}
|
||||
|
||||
public void testDefaultAttributeInHtml() {
|
||||
myFixture.enableInspections(new XmlDefaultAttributeValueInspection());
|
||||
myFixture.configureByText(HtmlFileType.INSTANCE, "<input type=\"text\"/>");
|
||||
myFixture.checkHighlighting();
|
||||
}
|
||||
}
|
||||
|
||||
+27
-23
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.XmlElementVisitor;
|
||||
import com.intellij.psi.html.HtmlTag;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
@@ -40,30 +41,33 @@ public class XmlDefaultAttributeValueInspection extends XmlSuppressableInspectio
|
||||
@Override
|
||||
public void visitXmlAttributeValue(XmlAttributeValue value) {
|
||||
PsiElement parent = value.getParent();
|
||||
if (parent instanceof XmlAttribute) {
|
||||
XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
|
||||
if (descriptor != null) {
|
||||
String defaultValue = descriptor.getDefaultValue();
|
||||
if (defaultValue != null && defaultValue.equals(value.getValue())) {
|
||||
holder.registerProblem(value, "Redundant default attribute value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
new LocalQuickFix() {
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return XmlErrorMessages.message("remove.attribute.quickfix.family");
|
||||
}
|
||||
if (!(parent instanceof XmlAttribute)) {
|
||||
return;
|
||||
}
|
||||
if (parent.getParent() instanceof HtmlTag && "input".equals(((HtmlTag)parent.getParent()).getName())) return;
|
||||
XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
|
||||
if (descriptor == null) {
|
||||
return;
|
||||
}
|
||||
String defaultValue = descriptor.getDefaultValue();
|
||||
if (defaultValue != null && defaultValue.equals(value.getValue())) {
|
||||
holder.registerProblem(value, "Redundant default attribute value assignment", ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
new LocalQuickFix() {
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return XmlErrorMessages.message("remove.attribute.quickfix.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
XmlAttribute attribute = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), XmlAttribute.class);
|
||||
if (attribute != null) {
|
||||
attribute.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
XmlAttribute attribute = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), XmlAttribute.class);
|
||||
if (attribute != null) {
|
||||
attribute.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user