XmlTag (@NotNull XmlTag rootTag, @NotNull String ownerName, @NotNull ExternalAnnotation annotation, @Nullable XmlTag startTag) { if (startTag == null) { startTag = PsiTreeUtil.findChildOfType(rootTag, XmlTag.class); } XmlTag prevItem = null; XmlTag curItem = startTag; while (curItem != null) { XmlTag addedItem = addAnnotation(rootTag, ownerName, annotation, curItem, prevItem); if (addedItem != null) { return addedItem; } prevItem = curItem; curItem = PsiTreeUtil.getNextSiblingOfType(curItem, XmlTag.class); } return addItemTag(rootTag, prevItem, ownerName, annotation); }