// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.browsers;

import com.google.common.base.CharMatcher;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Tag("browser")
public class StartBrowserSettings {
  private boolean mySelected;
  private WebBrowser myBrowser;

  private String myUrl;
  private boolean myStartJavaScriptDebugger;

  @Attribute("start")
  public boolean isSelected() {
    return mySelected;
  }

  public void setSelected(boolean selected) {
    mySelected = selected;
  }

  @Nullable
  @Attribute(value = "name", converter = WebBrowserReferenceConverter.class)
  public WebBrowser getBrowser() {
    return myBrowser;
  }

  public void setBrowser(@Nullable WebBrowser value) {
    myBrowser = value;
  }

  @Nullable
  @Attribute
  public String getUrl() {
    return myUrl;
  }

  public void setUrl(@Nullable String value) {
    String normalized = StringUtil.nullize(value, true);
    if (normalized != null) {
      normalized = CharMatcher.whitespace().trimFrom(normalized);
    }
    myUrl = normalized;
  }

  @Attribute("with-js-debugger")
  public boolean isStartJavaScriptDebugger() {
    return myStartJavaScriptDebugger;
  }

  public void setStartJavaScriptDebugger(boolean value) {
    myStartJavaScriptDebugger = value;
  }

  @NotNull
  public static StartBrowserSettings readExternal(@NotNull Element parent) {
    Element state = parent.getChild("browser");
    StartBrowserSettings settings = new StartBrowserSettings();
    if (state != null) {
      XmlSerializer.deserializeInto(settings, state);
    }
    return settings;
  }

  public void writeExternal(@NotNull Element parent) {
    Element state = XmlSerializer.serialize(this, new SkipDefaultValuesSerializationFilters());
    if (!JDOMUtil.isEmpty(state)) {
      parent.addContent(state);
    }
  }
}

@@ -18,9 +18,9 @@
 -201
-8
+9
  Jet
@@ -237,148 +237,40 @@
 lij.
-openapi.util.JDOMUtil;%0Aimport com.intellij.openapi.util.text.StringUtil;%0Aimport com.intellij.util.xmlb.SkipDefaultValuesSerializationFilt
+configurationStore.XmlSerializ
 er
-s
 ;%0Aim
@@ -291,31 +291,36 @@
 lij.
-util.xmlb.XmlSerializer
+openapi.util.text.StringUtil
 ;%0Aim
@@ -1908,22 +1908,22 @@
 to(s
+tate, s
 ettings
-, state
 );%0A 
@@ -2060,88 +2060,32 @@
 this
-, new SkipDefaultValuesSerializationFilters());%0A    if (!JDOMUtil.isEmpty(state)
+);%0A    if (state != null
 ) %7B%0A

use shared default filter