disable add required attribute in batch mode

EA-73302 - NPE: InsertRequiredAttributeFix.lambda$null$
This commit is contained in:
Anna Kozlova
2017-06-19 11:18:55 +03:00
parent 317091faa7
commit 6d4ab6449e
3 changed files with 26 additions and 26 deletions
@@ -89,13 +89,17 @@ public class InspectionMappingConsistencyInspection extends DevKitInspectionBase
private static void registerProblem(DomElement element, ProblemsHolder holder, String message, String... createAttrs) {
final Pair<TextRange, PsiElement> range = DomUtil.getProblemRange(element.getXmlTag());
holder.registerProblem(range.second, range.first, message, ContainerUtil.map(createAttrs,
s -> new InsertRequiredAttributeFix(PsiTreeUtil.getParentOfType(range.second, XmlTag.class, false), s) {
@NotNull
@Override
public String getText() {
return MessageFormat.format("Insert ''{0}'' attribute", s);
}
}, new LocalQuickFix[createAttrs.length]));
holder.registerProblem(range.second, range.first, message,
holder.isOnTheFly()
? ContainerUtil.map(createAttrs,
s -> new InsertRequiredAttributeFix(
PsiTreeUtil.getParentOfType(range.second, XmlTag.class, false), s) {
@NotNull
@Override
public String getText() {
return MessageFormat.format("Insert ''{0}'' attribute", s);
}
}, new LocalQuickFix[createAttrs.length])
: LocalQuickFix.EMPTY_ARRAY);
}
}
@@ -126,7 +126,7 @@ public class RequiredAttributesInspectionBase extends HtmlLocalInspectionTool im
if (!hasAttribute(tag, attrName) &&
!XmlExtension.getExtension(tag.getContainingFile()).isRequiredAttributeImplicitlyPresent(tag, attrName)) {
LocalQuickFix insertRequiredAttributeIntention = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, attrName);
LocalQuickFix insertRequiredAttributeIntention = isOnTheFly ? XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, attrName) : null;
final String localizedMessage = XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
reportOneTagProblem(
tag,
@@ -163,24 +163,17 @@ public class RequiredAttributesInspectionBase extends HtmlLocalInspectionTool im
if(isAdditionallyDeclared(getAdditionalEntries(), name)) return;
}
LocalQuickFix[] fixes;
ProblemHighlightType highlightType;
if (htmlTag) {
addElementsForTag(
tag,
localizedMessage,
isInjectedWithoutValidation(tag) ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
holder,
addAttributeFix,
basicIntention);
fixes = basicIntention == null ? new LocalQuickFix[] {addAttributeFix} : new LocalQuickFix[]{addAttributeFix, basicIntention};
highlightType = isInjectedWithoutValidation(tag) ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
}
else {
addElementsForTag(
tag,
localizedMessage,
ProblemHighlightType.ERROR,
holder,
basicIntention
);
fixes = basicIntention == null ? LocalQuickFix.EMPTY_ARRAY : new LocalQuickFix[] {basicIntention};
highlightType = ProblemHighlightType.ERROR;
}
addElementsForTag(tag, localizedMessage, highlightType, holder, fixes);
}
private static void addElementsForTag(XmlTag tag,
@@ -221,9 +221,12 @@ public abstract class XmlTagRuleProviderBase extends XmlTagRuleProvider {
PsiElement tagNameElement = getTagNameElement(tag);
if (tagNameElement == null) return;
LocalQuickFix[] fixes = new LocalQuickFix[myAttributeNames.length];
for (int i = 0; i < myAttributeNames.length; i++) {
fixes[i] = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, myAttributeNames[i]);
LocalQuickFix[] fixes = LocalQuickFix.EMPTY_ARRAY;
if (holder.isOnTheFly()) {
fixes = new LocalQuickFix[myAttributeNames.length];
for (int i = 0; i < myAttributeNames.length; i++) {
fixes[i] = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, myAttributeNames[i]);
}
}
holder.registerProblem(tagNameElement, "Tag should have one of following attributes: " + StringUtil.join(myAttributeNames, ", "),