@Nullable public final DomElement getDomElement(final XmlTag element) { if (myChanging) return null; final DomInvocationHandler handler = getDomHandler(element); return handler != null ? handler.getProxy() : null; }
@NotNull public XmlFile getContainingFile(@NotNull DomElement domElement) { if (domElement instanceof DomFileElement) { return ((DomFileElement) domElement).getFile(); } DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(domElement); assert handler != null : domElement; while (handler != null && !(handler instanceof DomRootInvocationHandler) && handler.getXmlTag() == null) { handler = handler.getParentHandler(); } if (handler instanceof DomRootInvocationHandler) { return ((DomRootInvocationHandler) handler).getParent().getFile(); } assert handler != null; XmlTag tag = handler.getXmlTag(); assert tag != null; while (true) { final PsiElement parentTag = PhysicalDomParentStrategy.getParentTagCandidate(tag); if (!(parentTag instanceof XmlTag)) { return (XmlFile) tag.getContainingFile(); } tag = (XmlTag) parentTag; } }
protected XmlElement recomputeXmlElement(@NotNull final DomInvocationHandler parent) { if (!parent.isValid()) return null; final XmlTag tag = parent.getXmlTag(); if (tag == null) return null; return tag.getAttribute(getXmlElementName(), getXmlApiCompatibleNamespace(parent)); }
@Nullable private String getXmlApiCompatibleNamespace(DomInvocationHandler parent) { final XmlTag tag = parent.getXmlTag(); if (tag == null) { return null; } String ns = getXmlName().getNamespace(tag, parent.getFile()); // TODO: this seems ugly return tag.getNamespace().equals(ns) ? null : ns; }
public final boolean checkInitialized() { if (myInitialized) return true; myStaticGenericInfo.buildMethodMaps(); if (myComputing.get() == Boolean.TRUE) return false; final XmlElement element = myInvocationHandler.getXmlElement(); if (element == null) return true; myComputing.set(Boolean.TRUE); try { DomExtensionsRegistrarImpl registrar = runDomExtenders(); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (element) { if (myInitialized) return true; if (registrar != null) { applyExtensions(registrar); } myInitialized = true; } } finally { myComputing.set(null); } return true; }
public static List<XmlTag> getCustomSubTags( final DomInvocationHandler handler, final XmlTag[] subTags, final XmlFile file) { if (subTags.length == 0) { return Collections.emptyList(); } final DomGenericInfoEx info = handler.getGenericInfo(); final Set<XmlName> usedNames = new THashSet<XmlName>(); List<? extends DomCollectionChildDescription> collectionChildrenDescriptions = info.getCollectionChildrenDescriptions(); //noinspection ForLoopReplaceableByForEach for (int i = 0, size = collectionChildrenDescriptions.size(); i < size; i++) { DomCollectionChildDescription description = collectionChildrenDescriptions.get(i); usedNames.add(description.getXmlName()); } List<? extends DomFixedChildDescription> fixedChildrenDescriptions = info.getFixedChildrenDescriptions(); //noinspection ForLoopReplaceableByForEach for (int i = 0, size = fixedChildrenDescriptions.size(); i < size; i++) { DomFixedChildDescription description = fixedChildrenDescriptions.get(i); usedNames.add(description.getXmlName()); } return ContainerUtil.findAll( subTags, tag -> { if (StringUtil.isEmpty(tag.getName())) return false; for (final XmlName name : usedNames) { if (isNameSuitable(name, tag, handler, file)) { return false; } } return true; }); }
public static boolean isNameSuitable( final XmlName name, final XmlTag tag, @NotNull final DomInvocationHandler handler, final XmlFile file) { return isNameSuitable(handler.createEvaluatedXmlName(name), tag, file); }
public static void assertValidity(DomElement element, String msg) { if (element instanceof DomFileElementImpl) { final String s = ((DomFileElementImpl) element).checkValidity(); if (s != null) { throw new AssertionError(s); } return; } final DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(element); assert handler != null; try { handler.assertValid(); } catch (AssertionError e) { throw new AssertionError(msg + e.getMessage()); } }
static XmlFile getFile(DomElement domElement) { if (domElement instanceof DomFileElement) { return ((DomFileElement) domElement).getFile(); } DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(domElement); assert handler != null : domElement; while (true) { if (handler instanceof DomRootInvocationHandler) { return ((DomRootInvocationHandler) handler).getParent().getFile(); } XmlTag tag = handler.getXmlTag(); if (tag != null) { return getContainingFile(tag); } DomInvocationHandler parent = handler.getParentHandler(); if (parent == null) { throw new AssertionError("No parent for " + handler.toStringEx()); } handler = parent; } }
@Nullable private DomExtensionsRegistrarImpl runDomExtenders() { DomExtensionsRegistrarImpl registrar = null; final DomElement domElement = myInvocationHandler.getProxy(); final Project project = myInvocationHandler.getManager().getProject(); for (final DomExtenderEP extenderEP : Extensions.getExtensions(DomExtenderEP.EP_NAME)) { registrar = extenderEP.extend(project, domElement, registrar); } final AbstractDomChildDescriptionImpl description = myInvocationHandler.getChildDescription(); if (description != null) { final List<DomExtender> extenders = description.getUserData(DomExtensionImpl.DOM_EXTENDER_KEY); if (extenders != null) { if (registrar == null) registrar = new DomExtensionsRegistrarImpl(); for (final DomExtender extender : extenders) { //noinspection unchecked extender.registerExtensions(domElement, registrar); } } } return registrar; }
public final XmlTag ensureTagExists() { final DomInvocationHandler parent = getParentHandler(); assert parent != null : "write operations should be performed on the DOM having a parent, your DOM may be not very fresh"; return parent.ensureTagExists(); }
@Nullable public final XmlTag getXmlTag() { final DomInvocationHandler handler = getParentHandler(); return handler == null ? null : handler.getXmlTag(); }
static AbstractDomChildrenDescription findChildrenDescription( final XmlTag tag, final DomInvocationHandler parent) { final DomGenericInfoEx info = parent.getGenericInfo(); return info.findChildrenDescription( parent, tag.getLocalName(), tag.getNamespace(), false, tag.getName()); }