use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class DomInvocationHandler method getCollectionChildren.
public List<? extends DomElement> getCollectionChildren(final AbstractCollectionChildDescription description) {
if (myStub != null && description.isStubbed()) {
if (description instanceof DomChildDescriptionImpl) {
XmlName xmlName = ((DomChildDescriptionImpl) description).getXmlName();
List<DomStub> stubs = myStub.getChildrenByName(xmlName.getLocalName(), xmlName.getNamespaceKey());
return ContainerUtil.map(stubs, stub -> stub.getOrCreateHandler((DomChildDescriptionImpl) description, myManager).getProxy());
} else if (description instanceof CustomDomChildrenDescriptionImpl) {
List<DomStub> stubs = myStub.getChildrenStubs();
return ContainerUtil.mapNotNull(stubs, (NullableFunction<DomStub, DomElement>) stub -> {
if (stub instanceof ElementStub && stub.isCustom()) {
EvaluatedXmlName name = new DummyEvaluatedXmlName(stub.getName(), "");
return new CollectionElementInvocationHandler(name, (CustomDomChildrenDescriptionImpl) description, myManager, (ElementStub) stub).getProxy();
}
return null;
});
}
}
XmlTag tag = getXmlTag();
if (tag == null)
return Collections.emptyList();
final List<XmlTag> subTags = getCollectionSubTags(description, tag);
if (subTags.isEmpty())
return Collections.emptyList();
List<DomElement> elements = new ArrayList<>(subTags.size());
for (XmlTag subTag : subTags) {
final SemKey<? extends DomInvocationHandler> key = description instanceof CustomDomChildrenDescription ? DomManagerImpl.DOM_CUSTOM_HANDLER_KEY : DomManagerImpl.DOM_COLLECTION_HANDLER_KEY;
final DomInvocationHandler semElement = myManager.getSemService().getSemElement(key, subTag);
if (semElement == null) {
String msg = "No child for subTag '" + subTag.getName() + "' in tag '" + tag.getName() + "' using key " + key + "; subtag count=" + subTags.size();
DomInvocationHandler anyDom = myManager.getDomHandler(subTag);
if (anyDom != null) {
msg += "\n sub-dom=" + anyDom + " with " + anyDom.getChildDescription();
}
throw new AssertionError(msg);
} else {
elements.add(semElement.getProxy());
}
}
return Collections.unmodifiableList(elements);
}
use of com.intellij.psi.xml.XmlTag 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.XmlTag in project intellij-community by JetBrains.
the class DomRootInvocationHandler method checkValidity.
@Override
protected String checkValidity() {
final XmlTag tag = (XmlTag) getXmlElement();
if (tag != null && !tag.isValid()) {
return "invalid root tag";
}
final String s = myParent.checkValidity();
if (s != null) {
return "root: " + s;
}
return null;
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class DomRootInvocationHandler method setEmptyXmlTag.
@Override
protected XmlTag setEmptyXmlTag() {
final XmlTag[] result = new XmlTag[] { null };
getManager().runChange(() -> {
try {
final String namespace = getXmlElementNamespace();
@NonNls final String nsDecl = StringUtil.isEmpty(namespace) ? "" : " xmlns=\"" + namespace + "\"";
final XmlFile xmlFile = getFile();
final XmlTag tag = XmlElementFactory.getInstance(xmlFile.getProject()).createTagFromText("<" + getXmlElementName() + nsDecl + "/>");
result[0] = ((XmlDocument) xmlFile.getDocument().replace(((XmlFile) tag.getContainingFile()).getDocument())).getRootTag();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
return result[0];
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class DomRootInvocationHandler method undefineInternal.
@Override
public void undefineInternal() {
try {
final XmlTag tag = getXmlTag();
if (tag != null) {
deleteTag(tag);
detach();
fireUndefinedEvent();
}
} catch (Exception e) {
LOG.error(e);
}
}
Aggregations