@Nullable
  private static BaseInjection createFrom(final BaseInjection injection) {
    if (injection.getInjectionPlaces().length == 0 || injection.getInjectionPlaces().length > 1) return null;

    AbstractTagInjection result;
    final InjectionPlace place = injection.getInjectionPlaces()[0];
    final ElementPattern<? extends PsiElement> rootPattern = place.getElementPattern();
    final ElementPatternCondition<? extends PsiElement> rootCondition = rootPattern.getCondition();
    final Class<? extends PsiElement> elementClass = rootCondition.getInitialCondition().getAcceptedClass();
    if (XmlAttribute.class.equals(elementClass)) {
      result = new XmlAttributeInjection().copyFrom(injection);
    }
    else if (XmlTag.class.equals(elementClass)) {
      result = new XmlTagInjection().copyFrom(injection);
    }
    else return null;
    result.setInjectionPlaces(InjectionPlace.EMPTY_ARRAY);
    for (PatternCondition<?> condition : rootCondition.getConditions()) {
      final String value = extractValue(condition);
      if ("withLocalName".equals(condition.getDebugMethodName())) {
        if (value == null) return null;
        if (result instanceof XmlAttributeInjection) {
          ((XmlAttributeInjection)result).setAttributeName(value);
        }
        else {
          result.setTagName(value);
        }
      }
      else if ("withNamespace".equals(condition.getDebugMethodName())) {
        if (value == null) return null;
        if (result instanceof XmlAttributeInjection) {
          ((XmlAttributeInjection)result).setAttributeNamespace(value);
        }
        else {
          result.setTagNamespace(value);
        }
      }
      else if (result instanceof XmlAttributeInjection && condition instanceof PatternConditionPlus) {
        boolean strict = "withParent".equals(condition.getDebugMethodName());
        if (!strict && !"inside".equals(condition.getDebugMethodName())) return null;

        result.setApplyToSubTags(!strict);
        ElementPattern<?> insidePattern = ((PatternConditionPlus<?, ?>)condition).getValuePattern();
        if (!XmlTag.class.equals(insidePattern.getCondition().getInitialCondition().getAcceptedClass())) return null;
        for (PatternCondition<?> insideCondition : insidePattern.getCondition().getConditions()) {
          String tagValue = extractValue(insideCondition);
          if (tagValue == null) return null;
          if ("withLocalName".equals(insideCondition.getDebugMethodName())) {
            result.setTagName(tagValue);
          }
          else if ("withNamespace".equals(insideCondition.getDebugMethodName())) {
            result.setTagNamespace(tagValue);
          }
        }
      }
      else {
        return null;
      }
    }
    result.generatePlaces();
    return result;
  }
@Nullable
  private static BaseInjection createFrom(final BaseInjection injection)