private static boolean isText(PsiElement leaf) {
    PsiElement parent = leaf.getParent();
    if (!(parent instanceof XmlText) &&
        !(PsiUtilCore.getElementType(parent) == XmlElementType.XML_CDATA && parent.getParent() instanceof XmlText) &&
        !(parent instanceof XmlDocument)) {
      return false;
    }

    IElementType type = PsiUtilCore.getElementType(leaf);
    return type == XmlTokenType.XML_WHITE_SPACE || type == TokenType.WHITE_SPACE ||
           type == XmlTokenType.XML_CHAR_ENTITY_REF || type == XmlTokenType.XML_DATA_CHARACTERS;
  }
private static boolean isText(PsiElement leaf)