use of com.intellij.psi.xml.XmlAttribute 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.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class IdRefReference method getIdValueElement.
@Nullable
protected PsiElement getIdValueElement(PsiElement element) {
if (element instanceof XmlTag) {
final XmlTag tag = (XmlTag) element;
XmlAttribute attribute = tag.getAttribute(IdReferenceProvider.ID_ATTR_NAME, null);
if (!myIdAttrsOnly) {
if (attribute == null) {
attribute = tag.getAttribute(IdReferenceProvider.NAME_ATTR_NAME, null);
}
if (attribute == null) {
attribute = tag.getAttribute(IdReferenceProvider.STYLE_ID_ATTR_NAME, null);
}
}
return attribute != null ? attribute.getValueElement() : getImplicitIdRefValueElement(tag);
} else {
return element;
}
}
use of com.intellij.psi.xml.XmlAttribute 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.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class DomAnchorImpl method diagnoseNegativeIndex2.
private static <T extends DomElement> void diagnoseNegativeIndex2(T t, DomElement parent, AbstractDomChildrenDescription description, List<? extends DomElement> values) {
final XmlTag parentTag = parent.getXmlTag();
StringBuilder diag = new StringBuilder("Index<0: description=" + description + "\nparent=" + parent + "\nt=" + t + "\nvalues=" + values + "\n");
for (int i = 0, size = values.size(); i < size; i++) {
DomElement value = values.get(i);
if (value.toString().equals(t.toString())) {
final XmlElement tElement = t.getXmlElement();
final XmlElement valElement = value.getXmlElement();
diag.append(" hasSame, i=" + i + "; same=" + (value == t) + ", equal=" + value.equals(t) + ", equal2=" + t.equals(value) + ", t.physical=" + (tElement == null ? "null" : String.valueOf(tElement.isPhysical())) + ", value.physical=" + (valElement == null ? "null" : String.valueOf(valElement.isPhysical())) + ", sameElements=" + (tElement == value.getXmlElement()) + "\n");
if (tElement != null && valElement != null) {
diag.append(" sameFile=" + (tElement.getContainingFile() == valElement.getContainingFile()) + ", sameParent=" + (tElement.getParent() == valElement.getParent()) + "\n");
}
}
}
if (parentTag != null) {
diag.append("Parent tag: ").append(parentTag.getName()).append("\n");
if (t instanceof GenericAttributeValue) {
for (XmlAttribute attribute : parentTag.getAttributes()) {
diag.append(", attr: ").append(attribute.getName());
}
diag.append("\n");
} else {
for (XmlTag tag : parentTag.getSubTags()) {
diag.append("\n subtag: ").append(tag.getName());
}
diag.append("\n");
}
}
diag.append("Child name: ").append(t.getXmlElementName()).append(";").append(t.getXmlElementNamespaceKey());
LOG.error(diag);
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class DomCompletionContributor method domKnowsBetter.
private boolean domKnowsBetter(final CompletionParameters parameters, final CompletionResultSet result) {
final XmlAttributeValue element = PsiTreeUtil.getParentOfType(parameters.getPosition(), XmlAttributeValue.class);
if (element == null) {
return false;
}
if (isSchemaEnumerated(element)) {
return false;
}
final PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute) {
XmlAttributeDescriptor descriptor = ((XmlAttribute) parent).getDescriptor();
if (descriptor != null && descriptor.getDefaultValue() != null) {
final PsiReference[] references = myProvider.getReferencesByElement(element, new ProcessingContext());
if (references.length > 0) {
return LegacyCompletionContributor.completeReference(parameters, result);
}
}
}
return false;
}
Aggregations