use of com.intellij.xml.XmlAttributeDescriptor 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.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class RequiredAttributesInspectionBase method hasAttribute.
private static boolean hasAttribute(XmlTag tag, String attrName) {
final XmlAttribute attribute = tag.getAttribute(attrName);
if (attribute == null)
return false;
if (attribute.getValueElement() != null)
return true;
if (!(tag instanceof HtmlTag))
return false;
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
return descriptor != null && HtmlUtil.isBooleanAttribute(descriptor, tag);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class IdReferenceProvider method getReferencesByElement.
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
if (element instanceof XmlAttributeValue) {
final XmlExtension extension = XmlExtension.getExtensionByElement(element);
if (extension != null && extension.hasDynamicComponents(element)) {
return PsiReference.EMPTY_ARRAY;
}
final PsiElement parentElement = element.getParent();
if (!(parentElement instanceof XmlAttribute))
return PsiReference.EMPTY_ARRAY;
final String name = ((XmlAttribute) parentElement).getName();
final String ns = ((XmlAttribute) parentElement).getParent().getNamespace();
final boolean jsfNs = Arrays.asList(XmlUtil.JSF_CORE_URIS).contains(ns) || Arrays.asList(XmlUtil.JSF_HTML_URIS).contains(ns);
if (FOR_ATTR_NAME.equals(name)) {
return new PsiReference[] { jsfNs && element.getText().indexOf(':') == -1 ? new IdRefReference(element) : new IdRefReference(element) {
@Override
public boolean isSoft() {
final XmlAttributeDescriptor descriptor = ((XmlAttribute) parentElement).getDescriptor();
return descriptor != null && !descriptor.hasIdRefType();
}
} };
} else {
final boolean allowReferences = !ourNamespacesWithoutNameReference.contains(ns);
if (ID_ATTR_NAME.equals(name) && allowReferences || STYLE_ID_ATTR_NAME.equals(name) || NAME_ATTR_NAME.equals(name) && allowReferences) {
final AttributeValueSelfReference attributeValueSelfReference;
if (jsfNs) {
attributeValueSelfReference = new AttributeValueSelfReference(element);
} else {
if (hasOuterLanguageElement(element))
return PsiReference.EMPTY_ARRAY;
attributeValueSelfReference = new GlobalAttributeValueSelfReference(element, true);
}
return new PsiReference[] { attributeValueSelfReference };
}
}
}
return PsiReference.EMPTY_ARRAY;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlHighlightingTest method testAnyAttributeNavigation.
public void testAnyAttributeNavigation() throws Exception {
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);
XmlElementDescriptorImpl descriptor = (XmlElementDescriptorImpl) tag.getDescriptor();
XmlAttributeDescriptor[] descriptors = descriptor.getAttributesDescriptors(tag);
System.out.println(Arrays.asList(descriptors));
doDoTest(true, false);
PsiElement resolve = at.resolve();
assertTrue(resolve instanceof XmlTag);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class PsiDocumentNavigator method getElementById.
public Object getElementById(Object object, final String elementId) {
final XmlTag rootTag = ((XmlFile) ((XmlElement) object).getContainingFile()).getRootTag();
if (rootTag == null) {
return null;
}
final Ref<XmlTag> ref = new Ref<>();
rootTag.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (ref.get() == null) {
super.visitElement(element);
}
}
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
final String value = attribute.getValue();
if ((value != null && (descriptor != null && descriptor.hasIdType()))) {
if (elementId.equals(value)) {
ref.set(attribute.getParent());
}
}
}
});
return ref.get();
}
Aggregations