com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters Java Examples

The following examples show how to use com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultilanguageDuplocatorSettings.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Element getState() {
  synchronized (mySettingsMap) {
    Element state = new Element("state");
    if (mySettingsMap.isEmpty()) {
      return state;
    }

    SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters();
    for (String name : mySettingsMap.keySet()) {
      Element child = XmlSerializer.serializeIfNotDefault(mySettingsMap.get(name), filter);
      if (child != null) {
        child.setName("object");
        child.setAttribute("language", name);
        state.addContent(child);
      }
    }
    return state;
  }
}
 
Example #2
Source File: SdkFieldsTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void roundTripShouldPreserveFields() {
  final SdkFields before = new SdkFields();
  before.setFilePath("main.dart");
  before.setAdditionalArgs("--trace-startup");

  final Element elt = new Element("test");
  XmlSerializer.serializeInto(before, elt, new SkipDefaultValuesSerializationFilters());

  // Make sure we no longer serialize workingDirectory
  assertArrayEquals(new String[]{"additionalArgs", "filePath"}, getOptionNames(elt).toArray());

  final SdkFields after = new SdkFields();
  XmlSerializer.deserializeInto(after, elt);
  assertEquals("main.dart", before.getFilePath());
  assertEquals("--trace-startup", before.getAdditionalArgs());
}
 
Example #3
Source File: RunnerLayout.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public Element write(@Nonnull Element parentNode) {
  for (ViewImpl eachState : myViews.values()) {
    if (myLightWeightIds != null && myLightWeightIds.contains(eachState.getID())) {
      continue;
    }
    parentNode.addContent(XmlSerializer.serialize(eachState));
  }

  SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters();
  for (TabImpl eachTab : myTabs) {
    if (isUsed(eachTab)) {
      parentNode.addContent(XmlSerializer.serialize(eachTab, filter));
    }
  }

  parentNode.addContent(XmlSerializer.serialize(myGeneral, filter));

  return parentNode;
}
 
Example #4
Source File: SdkFieldsTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void roundTripShouldPreserveFields() {
  final SdkFields before = new SdkFields();
  before.setFilePath("main.dart");
  before.setAdditionalArgs("--trace-startup");

  final Element elt = new Element("test");
  XmlSerializer.serializeInto(before, elt, new SkipDefaultValuesSerializationFilters());

  // Make sure we no longer serialize workingDirectory
  assertArrayEquals(new String[]{"additionalArgs", "filePath"}, getOptionNames(elt).toArray());

  final SdkFields after = new SdkFields();
  XmlSerializer.deserializeInto(after, elt);
  assertEquals("main.dart", before.getFilePath());
  assertEquals("--trace-startup", before.getAdditionalArgs());
}
 
Example #5
Source File: XDebuggerSettingManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public SettingsState getState() {
  SettingsState settingsState = new SettingsState();
  settingsState.setDataViewSettings(myDataViewSettings);
  settingsState.setGeneralSettings(myGeneralSettings);

  initSettings();
  if (!mySettingsById.isEmpty()) {
    SkipDefaultValuesSerializationFilters filter = new SkipDefaultValuesSerializationFilters();
    for (XDebuggerSettings<?> settings : mySettingsById.values()) {
      Object subState = settings.getState();
      if (subState != null) {
        Element serializedState = XmlSerializer.serializeIfNotDefault(subState, filter);
        if (!JDOMUtil.isEmpty(serializedState)) {
          SpecificSettingsState state = new SpecificSettingsState();
          state.id = settings.getId();
          state.configuration = serializedState;
          settingsState.specificStates.add(state);
        }
      }
    }
  }
  return settingsState;
}
 
Example #6
Source File: MuleSdkManagerImpl.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Element getState()
{
    Element element = new Element("mule-sdks");
    try
    {
        for (MuleSdk sdk : sdks)
        {
            final Element sdkElement = new Element("mule-sdk");
            XmlSerializer.serializeInto(sdk, sdkElement, new SkipDefaultValuesSerializationFilters());
            element.addContent(sdkElement);
        }
    }
    catch (XmlSerializationException e)
    {
        LOG.error(e);
    }
    return element;
}
 
Example #7
Source File: TableModelEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <T> T cloneUsingXmlSerialization(@Nonnull T oldItem, @Nonnull T newItem) {
  Element serialized = XmlSerializer.serialize(oldItem, new SkipDefaultValuesSerializationFilters());
  if (!JDOMUtil.isEmpty(serialized)) {
    XmlSerializer.deserializeInto(newItem, serialized);
  }
  return newItem;
}
 
Example #8
Source File: CodeInsightSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void writeExternal(final Element element) {
  try {
    XmlSerializer.serializeInto(this, element, new SkipDefaultValuesSerializationFilters());
  }
  catch (XmlSerializationException e) {
    LOG.info(e);
  }
}
 
Example #9
Source File: CommonCodeStyleSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void serialize(Element indentOptionsElement, final IndentOptions defaultOptions) {
  XmlSerializer.serializeInto(this, indentOptionsElement, new SkipDefaultValuesSerializationFilters() {
    @Override
    protected void configure(@Nonnull Object o) {
      if (o instanceof IndentOptions && defaultOptions != null) {
        ((IndentOptions)o).copyFrom(defaultOptions);
      }
    }
  });
}
 
Example #10
Source File: WebBrowserManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Element getState() {
  Element state = new Element("state");
  if (defaultBrowserPolicy != DefaultBrowserPolicy.SYSTEM) {
    state.setAttribute("default", StringUtil.toLowerCase(defaultBrowserPolicy.name()));
  }
  if (!myShowBrowserHover) {
    state.setAttribute("showHover", "false");
  }

  if (!browsers.equals(getPredefinedBrowsers())) {
    for (ConfigurableWebBrowser browser : browsers) {
      Element entry = new Element("browser");
      entry.setAttribute("id", browser.getId().toString());
      entry.setAttribute("name", browser.getName());
      entry.setAttribute("family", browser.getFamily().name());

      String path = browser.getPath();
      if (path != null && !path.equals(browser.getFamily().getExecutionPath())) {
        entry.setAttribute("path", path);
      }

      if (!browser.isActive()) {
        entry.setAttribute("active", "false");
      }

      BrowserSpecificSettings specificSettings = browser.getSpecificSettings();
      if (specificSettings != null) {
        Element settingsElement = new Element("settings");
        XmlSerializer.serializeInto(specificSettings, settingsElement, new SkipDefaultValuesSerializationFilters());
        if (!JDOMUtil.isEmpty(settingsElement)) {
          entry.addContent(settingsElement);
        }
      }
      state.addContent(entry);
    }
  }
  return state;
}
 
Example #11
Source File: DefaultStateSerializer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Element serializeState(@Nonnull Object state, @Nullable final Storage storage) throws WriteExternalException {
  if (state instanceof Element) {
    return (Element)state;
  }
  else if (state instanceof JDOMExternalizable) {
    Element element = new Element("temp_element");
    ((JDOMExternalizable)state).writeExternal(element);
    return element;
  }
  else {
    return XmlSerializer.serializeIfNotDefault(state, new SkipDefaultValuesSerializationFilters());
  }
}
 
Example #12
Source File: ArtifactManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Element serializePackagingElement(PackagingElement<?> packagingElement) {
  Element element = new Element(PACKAGING_ELEMENT_NAME);
  element.setAttribute(TYPE_ID_ATTRIBUTE, packagingElement.getType().getId());
  final Object bean = packagingElement.getState();
  if (bean != null) {
    XmlSerializer.serializeInto(bean, element, new SkipDefaultValuesSerializationFilters());
  }
  if (packagingElement instanceof CompositePackagingElement) {
    for (PackagingElement<?> child : ((CompositePackagingElement<?>)packagingElement).getChildren()) {
      element.addContent(serializePackagingElement(child));
    }
  }
  return element;
}
 
Example #13
Source File: ArtifactManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static <S> ArtifactPropertiesState serializeProperties(ArtifactPropertiesProvider provider, ArtifactProperties<S> properties) {
  final ArtifactPropertiesState state = new ArtifactPropertiesState();
  state.setId(provider.getId());
  final Element options = new Element("options");
  XmlSerializer.serializeInto(properties.getState(), options, new SkipDefaultValuesSerializationFilters());
  if (options.getContent().isEmpty() && options.getAttributes().isEmpty()) return null;
  state.setOptions(options);
  return state;
}
 
Example #14
Source File: XBreakpointsTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected Element save() {
  return XmlSerializer.serialize(myBreakpointManager.getState(), new SkipDefaultValuesSerializationFilters());
}
 
Example #15
Source File: PostfixTemplatesSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Element getState() {
  return XmlSerializer.serialize(this, new SkipDefaultValuesSerializationFilters());
}
 
Example #16
Source File: SdkRunConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void writeExternal(@NotNull final Element element) throws WriteExternalException {
  super.writeExternal(element);
  XmlSerializer.serializeInto(getFields(), element, new SkipDefaultValuesSerializationFilters());
}
 
Example #17
Source File: SdkRunConfig.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void writeExternal(@NotNull final Element element) throws WriteExternalException {
  super.writeExternal(element);
  XmlSerializer.serializeInto(getFields(), element, new SkipDefaultValuesSerializationFilters());
}