use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class HtmlUnknownBooleanAttributeInspectionBase method checkAttribute.
@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (attribute.getValueElement() == null) {
final XmlTag tag = attribute.getParent();
if (tag instanceof HtmlTag) {
XmlElementDescriptor elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
return;
}
XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
if (attributeDescriptor != null && !(attributeDescriptor instanceof AnyXmlAttributeDescriptor)) {
String name = attribute.getName();
if (!HtmlUtil.isBooleanAttribute(attributeDescriptor, null) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
final boolean html5 = HtmlUtil.isHtml5Context(tag);
LocalQuickFix[] quickFixes = !html5 ? new LocalQuickFix[] { new AddCustomHtmlElementIntentionAction(BOOLEAN_ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.boolean.attribute", name)), XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute), new RemoveAttributeIntentionAction(name) } : new LocalQuickFix[] { XmlQuickFixFactory.getInstance().addAttributeValueFix(attribute) };
String error = null;
if (html5) {
if (attributeDescriptor instanceof XmlEnumerationDescriptor && ((XmlEnumerationDescriptor) attributeDescriptor).getValueDeclaration(attribute, "") == null) {
error = XmlErrorMessages.message("wrong.value", "attribute");
}
} else {
error = XmlErrorMessages.message("attribute.is.not.boolean", attribute.getName());
}
if (error != null) {
registerProblemOnAttributeName(attribute, error, holder, quickFixes);
}
}
}
}
}
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class XmlHighlightVisitor method checkTagByDescriptor.
private void checkTagByDescriptor(final XmlTag tag) {
String name = tag.getName();
XmlElementDescriptor elementDescriptor;
final PsiElement parent = tag.getParent();
if (parent instanceof XmlTag) {
XmlTag parentTag = (XmlTag) parent;
elementDescriptor = XmlUtil.getDescriptorFromContext(tag);
final XmlElementDescriptor parentDescriptor = parentTag.getDescriptor();
if (parentDescriptor != null && elementDescriptor == null && shouldBeValidated(tag)) {
if (tag instanceof HtmlTag) {
//if (inspection != null /*&& isAdditionallyDeclared(inspection.getAdditionalEntries(XmlEntitiesInspection.UNKNOWN_TAG), name)*/) {
return;
//}
}
addElementsForTag(tag, XmlErrorMessages.message("element.is.not.allowed.here", name), getTagProblemInfoType(tag));
return;
}
if (elementDescriptor instanceof AnyXmlElementDescriptor || elementDescriptor == null) {
elementDescriptor = tag.getDescriptor();
}
if (elementDescriptor == null)
return;
} else {
//root tag
elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null) {
addElementsForTag(tag, XmlErrorMessages.message("element.must.be.declared", name), HighlightInfoType.WRONG_REF);
return;
}
}
if (elementDescriptor instanceof Validator) {
//noinspection unchecked
((Validator<XmlTag>) elementDescriptor).validate(tag, this);
}
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class XmlHighlightVisitor method checkTag.
private void checkTag(XmlTag tag) {
if (ourDoJaxpTesting)
return;
if (!myHolder.hasErrorResults()) {
checkTagByDescriptor(tag);
}
if (!myHolder.hasErrorResults()) {
if (!skipValidation(tag)) {
final XmlElementDescriptor descriptor = tag.getDescriptor();
if (tag instanceof HtmlTag && (descriptor instanceof AnyXmlElementDescriptor || descriptor == null)) {
return;
}
checkReferences(tag);
}
}
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class XmlHighlightVisitor method checkAttribute.
private void checkAttribute(XmlAttribute attribute) {
XmlTag tag = attribute.getParent();
if (tag == null)
return;
final String name = attribute.getName();
PsiElement prevLeaf = PsiTreeUtil.prevLeaf(attribute);
if (!(prevLeaf instanceof PsiWhiteSpace)) {
TextRange textRange = attribute.getTextRange();
HighlightInfoType type = tag instanceof HtmlTag ? HighlightInfoType.WARNING : HighlightInfoType.ERROR;
String description = XmlErrorMessages.message("attribute.should.be.preceded.with.space");
HighlightInfo info = HighlightInfo.newHighlightInfo(type).range(textRange.getStartOffset(), textRange.getStartOffset()).descriptionAndTooltip(description).create();
addToResults(info);
}
if (attribute.isNamespaceDeclaration() || XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(attribute.getNamespace())) {
//checkReferences(attribute.getValueElement());
return;
}
XmlElementDescriptor elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor || ourDoJaxpTesting) {
return;
}
XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor(attribute);
if (attributeDescriptor == null) {
if (!XmlUtil.attributeFromTemplateFramework(name, tag)) {
final String localizedMessage = XmlErrorMessages.message("attribute.is.not.allowed.here", name);
final HighlightInfo highlightInfo = reportAttributeProblem(tag, name, attribute, localizedMessage);
if (highlightInfo != null) {
PsiFile file = tag.getContainingFile();
if (file != null) {
for (XmlUndefinedElementFixProvider fixProvider : Extensions.getExtensions(XmlUndefinedElementFixProvider.EP_NAME)) {
IntentionAction[] fixes = fixProvider.createFixes(attribute);
if (fixes != null) {
for (IntentionAction action : fixes) {
QuickFixAction.registerQuickFixAction(highlightInfo, action);
}
break;
}
}
}
}
}
} else {
checkDuplicateAttribute(tag, attribute);
// we skip resolve of attribute references since there is separate check when taking attribute descriptors
PsiReference[] attrRefs = attribute.getReferences();
doCheckRefs(attribute, attrRefs, !attribute.getNamespacePrefix().isEmpty() ? 2 : 1);
}
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class TagNameReference method resolve.
@Override
public PsiElement resolve() {
final XmlTag tag = getTagElement();
final XmlElementDescriptor descriptor = tag != null ? tag.getDescriptor() : null;
if (LOG.isDebugEnabled()) {
LOG.debug("Descriptor for tag " + (tag != null ? tag.getName() : "NULL") + " is " + (descriptor != null ? (descriptor.toString() + ": " + descriptor.getClass().getCanonicalName()) : "NULL"));
}
if (descriptor != null) {
return descriptor instanceof AnyXmlElementDescriptor ? tag : descriptor.getDeclaration();
}
return null;
}
Aggregations