T (@Nullable final DomElement parent, final Editor editor) { if (parent == null) { return null; } final List<? extends DomCollectionChildDescription> list = parent.getGenericInfo().getCollectionChildrenDescriptions(); for (DomCollectionChildDescription childDescription : list) { if (ClassUtil.getRawType(childDescription.getType()).isAssignableFrom(myChildElementClass)) { XmlTag parentTag = parent.getXmlTag(); if (editor != null && parentTag != null) { int offset = editor.getCaretModel().getOffset(); PsiFile file = parentTag.getContainingFile(); PsiElement psiElement = file.findElementAt(offset); if (psiElement instanceof PsiWhiteSpace && PsiTreeUtil.isAncestor(parentTag, psiElement, false)) { Document document = editor.getDocument(); XmlTag childTag = parentTag.createChildTag(childDescription.getXmlElementName(), null, null, true); String text = childTag.getText(); document.insertString(offset, text); Project project = editor.getProject(); assert project != null; PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project); documentManager.commitDocument(document); PsiElement element = file.findElementAt(offset + 1); T domElement = DomUtil.findDomElement(element, myChildElementClass); if (domElement != null) return domElement; document.deleteString(offset, offset + text.length()); documentManager.commitDocument(document); } } int index = getCollectionIndex(parent, childDescription, editor); return index < 0 ? (T)childDescription.addValue(parent, myChildElementClass) : (T)childDescription.addValue(parent, myChildElementClass, index); } } return null; }