use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class XmlUnboundNsPrefixInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
private Boolean isXml;
private boolean isXmlFile(XmlElement element) {
if (isXml == null) {
final PsiFile file = element.getContainingFile();
isXml = file instanceof XmlFile && !InjectedLanguageManager.getInstance(element.getProject()).isInjectedFragment(file);
}
return isXml.booleanValue();
}
@Override
public void visitXmlToken(final XmlToken token) {
if (isXmlFile(token) && token.getTokenType() == XmlTokenType.XML_NAME) {
PsiElement element = token.getPrevSibling();
while (element instanceof PsiWhiteSpace) element = element.getPrevSibling();
if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_START_TAG_START) {
PsiElement parent = element.getParent();
if (parent instanceof XmlTag && !(token.getNextSibling() instanceof OuterLanguageElement)) {
XmlTag tag = (XmlTag) parent;
checkUnboundNamespacePrefix(tag, tag, tag.getNamespacePrefix(), token, holder, isOnTheFly);
}
}
}
}
@Override
public void visitXmlAttribute(final XmlAttribute attribute) {
if (!isXmlFile(attribute)) {
return;
}
final String namespace = attribute.getNamespace();
if (attribute.isNamespaceDeclaration() || XmlUtil.XML_SCHEMA_INSTANCE_URI.equals(namespace)) {
return;
}
XmlTag tag = attribute.getParent();
if (tag == null)
return;
XmlElementDescriptor elementDescriptor = tag.getDescriptor();
if (elementDescriptor == null || elementDescriptor instanceof AnyXmlElementDescriptor) {
return;
}
final String name = attribute.getName();
checkUnboundNamespacePrefix(attribute, tag, XmlUtil.findPrefixByQualifiedName(name), null, holder, isOnTheFly);
}
@Override
public void visitXmlAttributeValue(XmlAttributeValue value) {
PsiReference[] references = value.getReferences();
for (PsiReference reference : references) {
if (reference instanceof SchemaPrefixReference) {
if (!XML.equals(((SchemaPrefixReference) reference).getNamespacePrefix()) && reference.resolve() == null) {
holder.registerProblem(reference, XmlErrorMessages.message("unbound.namespace", ((SchemaPrefixReference) reference).getNamespacePrefix()), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
}
}
};
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor 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.impl.schema.AnyXmlElementDescriptor 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.impl.schema.AnyXmlElementDescriptor in project intellij-plugins by JetBrains.
the class AngularJSTagDescriptorsProvider method getDescriptor.
@Nullable
@Override
public XmlElementDescriptor getDescriptor(XmlTag xmlTag) {
final Project project = xmlTag.getProject();
if (!(xmlTag instanceof HtmlTag && AngularIndexUtil.hasAngularJS(project)))
return null;
final String tagName = xmlTag.getName();
final String directiveName = DirectiveUtil.normalizeAttributeName(tagName);
final XmlNSDescriptor nsDescriptor = xmlTag.getNSDescriptor(xmlTag.getNamespace(), false);
final XmlElementDescriptor descriptor = nsDescriptor != null ? nsDescriptor.getElementDescriptor(xmlTag) : null;
if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
return null;
}
if ((NG_CONTAINER.equals(directiveName) || NG_CONTENT.equals(directiveName) || NG_TEMPLATE.equals(directiveName)) && AngularIndexUtil.hasAngularJS2(project)) {
return new AngularJSTagDescriptor(directiveName, createDirective(xmlTag, directiveName));
}
JSImplicitElement directive = DirectiveUtil.getTagDirective(directiveName, project);
if (DirectiveUtil.isAngular2Directive(directive) && !directive.getName().equals(tagName)) {
// we've found directive via normalized name for Angular, it should not work
directive = null;
}
if (directive == null && !tagName.equals(directiveName) && AngularIndexUtil.hasAngularJS2(project)) {
directive = DirectiveUtil.getTagDirective(tagName, project);
if (!DirectiveUtil.isAngular2Directive(directive))
directive = null;
}
return directive != null ? new AngularJSTagDescriptor(directiveName, directive) : null;
}
Aggregations