use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class HtmlUnknownAttributeInspectionBase method checkAttribute.
@Override
protected void checkAttribute(@NotNull final XmlAttribute attribute, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
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 && !attribute.isNamespaceDeclaration()) {
final String name = attribute.getName();
if (!XmlUtil.attributeFromTemplateFramework(name, tag) && (!isCustomValuesEnabled() || !isCustomValue(name))) {
boolean maySwitchToHtml5 = HtmlUtil.isCustomHtml5Attribute(name) && !HtmlUtil.hasNonHtml5Doctype(tag);
LocalQuickFix[] quickfixes = new LocalQuickFix[maySwitchToHtml5 ? 3 : 2];
quickfixes[0] = new AddCustomHtmlElementIntentionAction(ATTRIBUTE_KEY, name, XmlBundle.message("add.custom.html.attribute", name));
quickfixes[1] = new RemoveAttributeIntentionAction(name);
if (maySwitchToHtml5) {
quickfixes[2] = new SwitchToHtml5WithHighPriorityAction();
}
registerProblemOnAttributeName(attribute, XmlErrorMessages.message("attribute.is.not.allowed.here", attribute.getName()), holder, quickfixes);
}
}
}
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class RequiredAttributesInspectionBase method checkTag.
@Override
protected void checkTag(@NotNull XmlTag tag, @NotNull ProblemsHolder holder, boolean isOnTheFly) {
String name = tag.getName();
XmlElementDescriptor elementDescriptor = XmlUtil.getDescriptorFromContext(tag);
if (elementDescriptor instanceof AnyXmlElementDescriptor || elementDescriptor == null) {
elementDescriptor = tag.getDescriptor();
}
if (elementDescriptor == null)
return;
if ((elementDescriptor instanceof XmlHighlightingAwareElementDescriptor) && !((XmlHighlightingAwareElementDescriptor) elementDescriptor).shouldCheckRequiredAttributes()) {
return;
}
XmlAttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributesDescriptors(tag);
Set<String> requiredAttributes = null;
for (XmlAttributeDescriptor attribute : attributeDescriptors) {
if (attribute != null && attribute.isRequired()) {
if (requiredAttributes == null) {
requiredAttributes = new HashSet<>();
}
requiredAttributes.add(attribute.getName(tag));
}
}
if (requiredAttributes != null) {
for (final String attrName : requiredAttributes) {
if (!hasAttribute(tag, attrName) && !XmlExtension.getExtension(tag.getContainingFile()).isRequiredAttributeImplicitlyPresent(tag, attrName)) {
LocalQuickFix insertRequiredAttributeIntention = XmlQuickFixFactory.getInstance().insertRequiredAttributeFix(tag, attrName);
final String localizedMessage = XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
reportOneTagProblem(tag, attrName, localizedMessage, insertRequiredAttributeIntention, holder, getIntentionAction(attrName));
}
}
}
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlHighlightingTest method testDropAnyAttributeCacheOnExitFromDumbMode.
public void testDropAnyAttributeCacheOnExitFromDumbMode() throws Exception {
try {
DumbServiceImpl.getInstance(myProject).setDumb(true);
configureByFiles(null, getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"), getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd"));
PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset());
XmlTag tag = PsiTreeUtil.getParentOfType(at.getElement(), XmlTag.class);
XmlElementDescriptor descriptor = tag.getDescriptor();
XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
System.out.println(Arrays.asList(descriptors));
} finally {
DumbServiceImpl.getInstance(myProject).setDumb(false);
}
doDoTest(true, false);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class HtmlElementDescriptorImpl method getAttributeDescriptor.
@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
String caseSensitiveAttributeName = !myCaseSensitive ? attributeName.toLowerCase() : attributeName;
XmlAttributeDescriptor descriptor = super.getAttributeDescriptor(caseSensitiveAttributeName, context);
if (descriptor == null)
descriptor = RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(attributeName, context);
if (descriptor == null) {
String prefix = XmlUtil.findPrefixByQualifiedName(attributeName);
if ("xml".equals(prefix)) {
// todo this is not technically correct dtd document references namespaces but we should handle it at least for xml stuff
XmlNSDescriptor nsdescriptor = context.getNSDescriptor(XmlUtil.XML_NAMESPACE_URI, true);
if (nsdescriptor instanceof XmlNSDescriptorImpl) {
descriptor = ((XmlNSDescriptorImpl) nsdescriptor).getAttribute(XmlUtil.findLocalNameByQualifiedName(caseSensitiveAttributeName), XmlUtil.XML_NAMESPACE_URI, context);
}
}
}
if (descriptor == null && HtmlUtil.isHtml5Context(context)) {
descriptor = myDelegate.getAttributeDescriptor(attributeName, context);
}
return descriptor;
}
Aggregations