public Element getState() {
    final Element element = new Element(COMPONENT_NAME);

    JDOMExternalizerUtil.writeField(
        element, INSTRUMENTATION_TYPE_NAME, myInstrumentationType.toString());
    JDOMExternalizerUtil.writeField(element, LANGUAGE_ANNOTATION_NAME, myLanguageAnnotation);
    JDOMExternalizerUtil.writeField(element, PATTERN_ANNOTATION_NAME, myPatternAnnotation);
    JDOMExternalizerUtil.writeField(element, SUBST_ANNOTATION_NAME, mySubstAnnotation);
    JDOMExternalizerUtil.writeField(
        element, RESOLVE_REFERENCES, String.valueOf(myResolveReferences));

    final List<String> injectorIds = new ArrayList<String>(myInjections.keySet());
    Collections.sort(injectorIds);
    for (String key : injectorIds) {
      final List<BaseInjection> injections = new ArrayList<BaseInjection>(myInjections.get(key));
      if (myDefaultInjections != null) {
        injections.removeAll(myDefaultInjections);
      }
      Collections.sort(
          injections,
          new Comparator<BaseInjection>() {
            public int compare(final BaseInjection o1, final BaseInjection o2) {
              return Comparing.compare(o1.getDisplayName(), o2.getDisplayName());
            }
          });
      for (BaseInjection injection : injections) {
        element.addContent(injection.getState());
      }
    }
    return element;
  }
 private void writeState(final Element element) {
   JDOMExternalizerUtil.writeField(
       element, INSTRUMENTATION_TYPE_NAME, myInstrumentationType.toString());
   JDOMExternalizerUtil.writeField(element, LANGUAGE_ANNOTATION_NAME, myLanguageAnnotation);
   JDOMExternalizerUtil.writeField(element, PATTERN_ANNOTATION_NAME, myPatternAnnotation);
   JDOMExternalizerUtil.writeField(element, SUBST_ANNOTATION_NAME, mySubstAnnotation);
   if (myIncludeUncomputablesAsLiterals) {
     JDOMExternalizerUtil.writeField(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, "true");
   }
   if (mySourceModificationAllowed) {
     JDOMExternalizerUtil.writeField(element, SOURCE_MODIFICATION_ALLOWED, "true");
   }
   switch (myDfaOption) {
     case OFF:
       break;
     case RESOLVE:
       JDOMExternalizerUtil.writeField(element, RESOLVE_REFERENCES, Boolean.TRUE.toString());
       break;
     case ASSIGNMENTS:
       JDOMExternalizerUtil.writeField(
           element, LOOK_FOR_VAR_ASSIGNMENTS, Boolean.TRUE.toString());
       break;
     case DFA:
       JDOMExternalizerUtil.writeField(element, USE_DFA_IF_AVAILABLE, Boolean.TRUE.toString());
       break;
   }
 }
 private void loadState(final Element element) {
   setInstrumentationType(JDOMExternalizerUtil.readField(element, INSTRUMENTATION_TYPE_NAME));
   setLanguageAnnotation(JDOMExternalizerUtil.readField(element, LANGUAGE_ANNOTATION_NAME));
   setPatternAnnotation(JDOMExternalizerUtil.readField(element, PATTERN_ANNOTATION_NAME));
   setSubstAnnotation(JDOMExternalizerUtil.readField(element, SUBST_ANNOTATION_NAME));
   if (readBoolean(element, RESOLVE_REFERENCES, true)) {
     setDfaOption(DfaOption.RESOLVE);
   }
   if (readBoolean(element, LOOK_FOR_VAR_ASSIGNMENTS, false)) {
     setDfaOption(DfaOption.ASSIGNMENTS);
   }
   if (readBoolean(element, USE_DFA_IF_AVAILABLE, false)) {
     setDfaOption(DfaOption.DFA);
   }
   setIncludeUncomputablesAsLiterals(
       readBoolean(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, false));
   setSourceModificationAllowed(readBoolean(element, SOURCE_MODIFICATION_ALLOWED, false));
 }
  public void loadState(final Element element, final boolean mergeWithOriginalAndCompile) {
    final THashMap<String, LanguageInjectionSupport> supports =
        new THashMap<String, LanguageInjectionSupport>();
    for (LanguageInjectionSupport support :
        Extensions.getExtensions(LanguageInjectionSupport.EP_NAME)) {
      supports.put(support.getId(), support);
    }
    loadStateOld(
        element,
        supports.get(LanguageInjectionSupport.XML_SUPPORT_ID),
        supports.get(LanguageInjectionSupport.JAVA_SUPPORT_ID));
    for (Element child : (List<Element>) element.getChildren("injection")) {
      final String key = child.getAttributeValue("injector-id");
      final LanguageInjectionSupport support = supports.get(key);
      final BaseInjection injection =
          support == null ? new BaseInjection(key) : support.createInjection(child);
      injection.loadState(child);
      myInjections.get(key).add(injection);
    }
    setInstrumentationType(JDOMExternalizerUtil.readField(element, INSTRUMENTATION_TYPE_NAME));
    setLanguageAnnotation(JDOMExternalizerUtil.readField(element, LANGUAGE_ANNOTATION_NAME));
    setPatternAnnotation(JDOMExternalizerUtil.readField(element, PATTERN_ANNOTATION_NAME));
    setSubstAnnotation(JDOMExternalizerUtil.readField(element, SUBST_ANNOTATION_NAME));
    setResolveReferences(readBoolean(element, RESOLVE_REFERENCES, true));
    setUseDfaIfAvailable(readBoolean(element, USE_DFA_IF_AVAILABLE, false));
    setIncludeUncomputablesAsLiterals(
        readBoolean(element, INCLUDE_UNCOMPUTABLES_AS_LITERALS, false));

    if (mergeWithOriginalAndCompile) {
      mergeWithDefaultConfiguration();

      for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) {
        for (BaseInjection injection : getInjections(supportId)) {
          injection.initializePlaces(true);
        }
      }
    }
  }
 private static boolean readBoolean(Element element, String key, boolean defValue) {
   final String value = JDOMExternalizerUtil.readField(element, key);
   if (value == null) return defValue;
   return Boolean.parseBoolean(value);
 }