use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class DomInvocationHandler method getAttributeChild.
@NotNull
final AttributeChildInvocationHandler getAttributeChild(final AttributeChildDescriptionImpl description) {
final EvaluatedXmlName evaluatedXmlName = createEvaluatedXmlName(description.getXmlName());
if (myStub != null && description.isStubbed()) {
AttributeStub stub = myStub.getAttributeStub(description.getXmlName());
StubParentStrategy strategy = StubParentStrategy.createAttributeStrategy(stub, myStub);
return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, strategy, stub);
}
final XmlTag tag = getXmlTag();
if (tag != null) {
// TODO: this seems ugly
String ns = evaluatedXmlName.getNamespace(tag, getFile());
final XmlAttribute attribute = tag.getAttribute(description.getXmlName().getLocalName(), ns.equals(tag.getNamespace()) ? null : ns);
if (attribute != null) {
PsiUtilCore.ensureValid(attribute);
AttributeChildInvocationHandler semElement = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
if (semElement == null) {
final AttributeChildInvocationHandler take2 = myManager.getSemService().getSemElement(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute);
throw new AssertionError("No DOM at XML. Parent=" + tag + "; attribute=" + attribute + "; second attempt=" + take2);
}
return semElement;
}
}
return new AttributeChildInvocationHandler(evaluatedXmlName, description, myManager, new VirtualDomParentStrategy(this), null);
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class AttributeChildInvocationHandler method setValue.
@Override
protected void setValue(@Nullable final String value) {
final XmlTag tag = ensureTagExists();
final String attributeName = getXmlElementName();
final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
final String newValue = XmlStringUtil.escapeString(value);
if (Comparing.equal(oldValue, newValue, true))
return;
getManager().runChange(() -> {
try {
XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
setXmlElement(attribute);
getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
final DomElement proxy = getProxy();
getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(proxy, true));
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class XmlSchemaTagsProcessor method processTag.
private void processTag(XmlTag tag, @Nullable XmlTag context) {
if (myVisited.contains(tag))
return;
myVisited.add(tag);
if (!XmlNSDescriptorImpl.checkSchemaNamespace(tag)) {
processTagWithSubTags(tag, context, null);
return;
}
String tagName = tag.getLocalName();
if (checkTagName(tagName, "element", "attribute")) {
XmlAttribute ref = tag.getAttribute("ref");
if (ref != null) {
XmlTag resolved = resolveTagReference(ref);
if (resolved != null) {
tagStarted(resolved, resolved.getLocalName(), tag, tag);
}
} else {
tagStarted(tag, tag.getLocalName(), context, null);
}
} else if (checkTagName(tagName, "group")) {
String value = tag.getAttributeValue("ref");
if (value != null) {
XmlTag group = myNsDescriptor.findGroup(value);
if (group == null)
group = resolveTagReference(tag.getAttribute("ref"));
processTagWithSubTags(group, tag, tag);
}
} else if (checkTagName(tagName, "attributeGroup")) {
String ref = tag.getAttributeValue("ref");
if (ref == null)
return;
XmlTag group;
XmlTag parentTag = tag.getParentTag();
assert parentTag != null;
if (XmlNSDescriptorImpl.equalsToSchemaName(parentTag, "attributeGroup") && ref.equals(parentTag.getAttributeValue("name"))) {
group = resolveTagReference(tag.getAttribute("ref"));
if (group == null)
group = myNsDescriptor.findAttributeGroup(ref);
} else {
group = myNsDescriptor.findAttributeGroup(ref);
if (group == null)
group = resolveTagReference(tag.getAttribute("ref"));
}
processTagWithSubTags(group, tag, null);
} else if (checkTagName(tagName, "restriction", "extension")) {
processTagWithSubTags(resolveTagReference(tag.getAttribute("base")), tag, null);
processTagWithSubTags(tag, context, null);
} else if (!checkTagName(tagName, myTagsToIgnore)) {
processTagWithSubTags(tag, context, null);
}
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class XmlTagTreeElement method getLocationString.
@Override
public String getLocationString() {
final StringBuilder buffer = new StringBuilder();
final XmlTag element = getElement();
assert element != null;
String id = element.getAttributeValue(ID_ATTR_NAME);
String usedAttrName = null;
if (id == null) {
id = element.getAttributeValue(NAME_ATTR_NAME);
if (id != null) {
usedAttrName = NAME_ATTR_NAME;
}
} else {
usedAttrName = ID_ATTR_NAME;
}
id = toCanonicalForm(id);
for (XmlAttribute attribute : element.getAttributes()) {
if (buffer.length() != 0) {
buffer.append(' ');
}
final String name = attribute.getName();
if (usedAttrName != null && id != null && usedAttrName.equals(name)) {
// we output this name in name
continue;
}
buffer.append(name);
buffer.append('=').append('"').append(attribute.getValue()).append('"');
}
return buffer.toString();
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-community by JetBrains.
the class XmlAttributeValueImpl method updateText.
@Override
public PsiLanguageInjectionHost updateText(@NotNull String text) {
try {
final String quoteChar = getTextLength() > 0 ? getText().substring(0, 1) : "";
String contents = StringUtil.containsAnyChar(quoteChar, "'\"") ? StringUtil.trimEnd(StringUtil.trimStart(text, quoteChar), quoteChar) : text;
XmlAttribute newAttribute = XmlElementFactory.getInstance(getProject()).createAttribute("q", contents, this);
XmlAttributeValue newValue = newAttribute.getValueElement();
CheckUtil.checkWritable(this);
replaceAllChildrenToChildrenOf(newValue.getNode());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return this;
}
Aggregations