use of com.intellij.codeInsight.daemon.impl.analysis.RemoveAttributeIntentionFix in project intellij-community by JetBrains.
the class JavaFxRedundantPropertyValueInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
if (!JavaFxFileTypeFactory.isFxml(session.getFile()))
return PsiElementVisitor.EMPTY_VISITOR;
return new XmlElementVisitor() {
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
super.visitXmlAttribute(attribute);
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (!(descriptor instanceof JavaFxPropertyAttributeDescriptor))
return;
final String attributeName = attribute.getName();
final String attributeValue = attribute.getValue();
if (attributeValue == null || attributeValue.startsWith("$") || attributeValue.startsWith("#") || attributeValue.startsWith("%") || FxmlConstants.FX_ID.equals(attributeName) || FxmlConstants.FX_VALUE.equals(attributeName) || FxmlConstants.FX_CONSTANT.equals(attributeName) || FxmlConstants.FX_CONTROLLER.equals(attributeName)) {
return;
}
final PsiClass tagClass = JavaFxPsiUtil.getTagClass(attribute.getParent());
final String defaultValue = getDefaultValue(attributeName, tagClass);
if (defaultValue == null)
return;
if (isEqualValue(tagClass, attributeValue, defaultValue, descriptor.getDeclaration())) {
holder.registerProblem(attribute, "Attribute is redundant because it contains default value", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RemoveAttributeIntentionFix(attributeName, attribute));
}
}
@Override
public void visitXmlTag(XmlTag tag) {
super.visitXmlTag(tag);
final XmlElementDescriptor descriptor = tag.getDescriptor();
if (!(descriptor instanceof JavaFxPropertyTagDescriptor)) {
return;
}
if (tag.getSubTags().length != 0)
return;
final String tagText = tag.getValue().getTrimmedText();
if (tagText.startsWith("$") || tagText.startsWith("#") || tagText.startsWith("%")) {
return;
}
final XmlTag parentTag = tag.getParentTag();
if (parentTag == null)
return;
final PsiClass tagClass = JavaFxPsiUtil.getTagClass(parentTag);
final String defaultValue = getDefaultValue(tag.getName(), tagClass);
if (defaultValue == null)
return;
if (isEqualValue(tagClass, tagText, defaultValue, descriptor.getDeclaration())) {
holder.registerProblem(tag, "Tag is redundant because it contains default value", ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RemoveTagIntentionFix(tag.getName(), tag));
}
}
};
}
Aggregations