Java Code Examples for com.intellij.openapi.util.JDOMUtil#areElementsEqual()

The following examples show how to use com.intellij.openapi.util.JDOMUtil#areElementsEqual() . 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: ScopeToolState.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean equalTo(@Nonnull ScopeToolState state2) {
  if (isEnabled() != state2.isEnabled()) return false;
  if (getLevel() != state2.getLevel()) return false;
  InspectionToolWrapper toolWrapper = getTool();
  InspectionToolWrapper toolWrapper2 = state2.getTool();
  if (!toolWrapper.isInitialized() && !toolWrapper2.isInitialized()) return true;
  try {
    @NonNls String tempRoot = "root";
    Element oldToolSettings = new Element(tempRoot);
    toolWrapper.getTool().writeSettings(oldToolSettings);
    Element newToolSettings = new Element(tempRoot);
    toolWrapper2.getTool().writeSettings(newToolSettings);
    return JDOMUtil.areElementsEqual(oldToolSettings, newToolSettings);
  }
  catch (WriteExternalException e) {
    LOG.error(e);
  }
  return false;
}
 
Example 2
Source File: DaemonCodeAnalyzerSettingsImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isCodeHighlightingChanged(DaemonCodeAnalyzerSettings oldSettings) {
  try {
    Element rootNew = new Element(ROOT_TAG);
    writeExternal(rootNew);
    Element rootOld = new Element(ROOT_TAG);
    ((DaemonCodeAnalyzerSettingsImpl)oldSettings).writeExternal(rootOld);

    return !JDOMUtil.areElementsEqual(rootOld, rootNew);
  }
  catch (WriteExternalException e) {
    LOG.error(e);
  }

  return false;
}
 
Example 3
Source File: InspectionElementsMerger.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean markSettingsMerged(Map<String, Element> inspectionsSettings) {
  final Element merge = merge(inspectionsSettings, true);
  if (merge != null) {
    final Element defaultElement = merge(Collections.<String, Element>emptyMap(), true);
    return !JDOMUtil.areElementsEqual(merge, defaultElement);
  }
  return false;
}
 
Example 4
Source File: StorageData.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public final Object setState(@Nonnull String componentName, @Nullable Element newState, @Nonnull Map<String, Element> newLiveStates) {
  if (newState == null || JDOMUtil.isEmpty(newState)) {
    return myStates.remove(componentName);
  }

  prepareElement(newState);

  newLiveStates.put(componentName, newState);

  Object oldState = myStates.get(componentName);

  byte[] newBytes = null;
  if (oldState instanceof Element) {
    if (JDOMUtil.areElementsEqual((Element)oldState, newState)) {
      return null;
    }
  }
  else if (oldState != null) {
    newBytes = StateMap.getNewByteIfDiffers(componentName, newState, (byte[])oldState);
    if (newBytes == null) {
      return null;
    }
  }

  myStates.put(componentName, newBytes == null ? newState : newBytes);
  return newState;
}
 
Example 5
Source File: SkipDefaultValuesSerializationFilters.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean accepts(@Nonnull Accessor accessor, @Nonnull Object bean, @Nullable Object beanValue) {
  Object defValue = accessor.read(getDefaultBean(bean));
  if (defValue instanceof Element && beanValue instanceof Element) {
    return !JDOMUtil.areElementsEqual((Element)beanValue, (Element)defValue);
  }
  else {
    return !Comparing.equal(beanValue, defValue);
  }
}
 
Example 6
Source File: SingleInspectionProfilePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean wereToolSettingsModified(Descriptor descriptor, boolean isDefault) {
  if (!mySelectedProfile.isToolEnabled(descriptor.getKey(), descriptor.getScope(), myProjectProfileManager.getProject())) {
    return false;
  }
  Element oldConfig = descriptor.getConfig();
  if (oldConfig == null) return false;

  ScopeToolState state = null;
  if (isDefault) {
    state =
            mySelectedProfile.getToolDefaultState(descriptor.getKey().toString(), myProjectProfileManager.getProject());
  } else {
    for (ScopeToolState candidate : mySelectedProfile
            .getNonDefaultTools(descriptor.getKey().toString(), myProjectProfileManager.getProject())) {
      final String scope = descriptor.getScopeName();
      if (Comparing.equal(candidate.getScopeName(), scope)) {
        state = candidate;
        break;
      }
    }
  }

  if (state == null) {
    return true;
  }

  Element newConfig = Descriptor.createConfigElement(state.getTool());
  if (!JDOMUtil.areElementsEqual(oldConfig, newConfig)) {
    myAlarm.cancelAllRequests();
    myAlarm.addRequest(new Runnable() {
      @Override
      public void run() {
        myTreeTable.repaint();
      }
    }, 300);
    myModified = true;
    return true;
  }
  return false;
}
 
Example 7
Source File: UnknownBeforeRunTaskProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object o) {
  if (this == o) return true;
  if (o == null || getClass() != o.getClass()) return false;
  if (!super.equals(o)) return false;

  UnknownTask that = (UnknownTask)o;

  if (!JDOMUtil.areElementsEqual(myConfig, that.myConfig)) return false;

  return true;
}
 
Example 8
Source File: PlatformTestUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void assertElementsEqual(final Element expected, final Element actual) throws IOException {
  if (!JDOMUtil.areElementsEqual(expected, actual)) {
    junit.framework.Assert.assertEquals(printElement(expected), printElement(actual));
  }
}
 
Example 9
Source File: InspectionElementsMerger.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected boolean areSettingsMerged(Map<String, Element> inspectionsSettings, Element inspectionElement) {
  final Element merge = merge(inspectionsSettings, true);
  return merge != null && JDOMUtil.areElementsEqual(merge, inspectionElement);
}
 
Example 10
Source File: SkipDefaultsSerializationFilter.java    From consulo with Apache License 2.0 4 votes vote down vote up
boolean equal(@Nullable Binding binding, @Nullable Object currentValue, @Nullable Object defaultValue) {
  if (defaultValue instanceof Element && currentValue instanceof Element) {
    return JDOMUtil.areElementsEqual((Element)currentValue, (Element)defaultValue);
  }
  else {
    if (currentValue == defaultValue) {
      return true;
    }
    if (currentValue == null || defaultValue == null) {
      return false;
    }

    if (binding instanceof BasePrimitiveBinding) {
      Binding referencedBinding = ((BasePrimitiveBinding)binding).myBinding;
      if (referencedBinding instanceof BeanBinding) {
        BeanBinding classBinding = (BeanBinding)referencedBinding;
        ThreeState compareByFields = classBinding.hasEqualMethod;
        if (compareByFields == ThreeState.UNSURE) {
          try {
            classBinding.myBeanClass.getDeclaredMethod("equals", Object.class);
            compareByFields = ThreeState.NO;
          }
          catch (NoSuchMethodException ignored) {
            compareByFields = ThreeState.YES;
          }
          catch (Exception e) {
            Binding.LOG.warn(e);
          }

          classBinding.hasEqualMethod = compareByFields;
        }

        if (compareByFields == ThreeState.YES) {
          return classBinding.equalByFields(currentValue, defaultValue, this);
        }
      }
    }

    return Comparing.equal(currentValue, defaultValue);
  }
}
 
Example 11
Source File: XBreakpointManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean statesAreDifferent(BreakpointState state1, BreakpointState state2) {
  Element elem1 = XmlSerializer.serialize(state1, SERIALIZATION_FILTER);
  Element elem2 = XmlSerializer.serialize(state2, SERIALIZATION_FILTER);
  return !JDOMUtil.areElementsEqual(elem1, elem2);
}