public static @Nullable Element saveFacetConfiguration(@NotNull FacetConfiguration configuration) {
    if (configuration instanceof PersistentStateComponent) {
      Object state = ((PersistentStateComponent<?>)configuration).getState();
      if (state instanceof Element) {
        return ((Element)state);
      }
      else {
        Element result = XmlSerializer.serialize(state);
        return result == null ? new Element(JpsFacetSerializer.CONFIGURATION_TAG) : result;
      }
    }
    else if (configuration instanceof InvalidFacetConfiguration) {
      return ((InvalidFacetConfiguration)configuration).getFacetState().getConfiguration();
    }
    else {
      final Element config = new Element(JpsFacetSerializer.CONFIGURATION_TAG);
      configuration.writeExternal(config);
      return config;
    }
  }
public static @Nullable Element saveFacetConfiguration(@NotNull FacetConfiguration configuration)