From 446b2b18bf2dcb67d2507f9dcf4fdd871ad263bb Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 16 Jan 2017 16:32:31 +0100 Subject: [PATCH] =?UTF-8?q?BaseState=20=E2=80=94=20reset=20modification=20?= =?UTF-8?q?count=20on=20load=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Module root model modification count cannot be computed on time of loading. Because library model is not yet loaded (and we must avoid using it during load. But reason of changed state is not library model, but language level model — BaseState increments counter during load. And after load modification count is greater than 0. To avoid this issue, we should reset modification count after deserialization --- .../LanguageLevelModuleExtensionImpl.java | 1 - .../openapi/components/StoredProperty.kt | 5 ++++ .../configurationStore/serializationUtil.kt | 29 +++++++++++++++++++ .../ComponentSerializationUtil.java | 2 +- .../openapi/roots/impl/RootModelImpl.java | 10 +++---- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 platform/projectModel-impl/src/com/intellij/configurationStore/serializationUtil.kt rename platform/{core-impl => projectModel-impl}/src/com/intellij/openapi/components/ComponentSerializationUtil.java (97%) diff --git a/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelModuleExtensionImpl.java b/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelModuleExtensionImpl.java index ad6539c44c7f..c12802205313 100644 --- a/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelModuleExtensionImpl.java +++ b/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelModuleExtensionImpl.java @@ -24,7 +24,6 @@ import com.intellij.openapi.components.PersistentStateComponentWithModificationT import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.pom.java.LanguageLevel; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class LanguageLevelModuleExtensionImpl extends ModuleExtension implements LanguageLevelModuleExtension, diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt index 5cd999ed9c2c..0237de225655 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt @@ -28,6 +28,11 @@ abstract class BaseState : SerializationFilter, ModificationTracker { @Volatile internal var modificationCount: Long = 0 + // reset on load state + fun resetModificationCount() { + modificationCount = 0 + } + override fun accepts(accessor: Accessor, bean: Any): Boolean { for (property in properties) { if (property.name == accessor.name) { diff --git a/platform/projectModel-impl/src/com/intellij/configurationStore/serializationUtil.kt b/platform/projectModel-impl/src/com/intellij/configurationStore/serializationUtil.kt new file mode 100644 index 000000000000..2068eb58580d --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/configurationStore/serializationUtil.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.configurationStore + +import com.intellij.openapi.components.BaseState +import com.intellij.openapi.components.ComponentSerializationUtil +import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.util.xmlb.XmlSerializer +import org.jdom.Element + +fun deserializeAndLoadState(component: PersistentStateComponent<*>, element: Element) { + val state = XmlSerializer.deserialize(element, ComponentSerializationUtil.getStateClass(component.javaClass)) + (state as? BaseState)?.resetModificationCount() + @Suppress("UNCHECKED_CAST") + (component as PersistentStateComponent).loadState(state) +} diff --git a/platform/core-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java b/platform/projectModel-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java similarity index 97% rename from platform/core-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java rename to platform/projectModel-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java index 75bb037f375a..1e85e1402513 100644 --- a/platform/core-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/ComponentSerializationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java index 71f51e0f724f..90b15121e6e6 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelImpl.java @@ -15,9 +15,9 @@ */ package com.intellij.openapi.roots.impl; +import com.intellij.configurationStore.SerializationUtilKt; import com.intellij.openapi.CompositeDisposable; import com.intellij.openapi.Disposable; -import com.intellij.openapi.components.ComponentSerializationUtil; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.PersistentStateComponentWithModificationTracker; import com.intellij.openapi.diagnostic.Logger; @@ -129,10 +129,10 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel ModuleExtension model = extension.getModifiableModel(false); if (model instanceof PersistentStateComponent) { - PersistentStateComponent component = (PersistentStateComponent)model; - component.loadState(XmlSerializer.deserialize(element, ComponentSerializationUtil.getStateClass((component.getClass())))); + SerializationUtilKt.deserializeAndLoadState((PersistentStateComponent)model, element); } else { + //noinspection deprecation model.readExternal(element); } @@ -167,8 +167,7 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel myWritable = writable; myConfigurationAccessor = rootConfigurationAccessor; - final Set thatContent = rootModel.myContent; - for (ContentEntry contentEntry : thatContent) { + for (ContentEntry contentEntry : rootModel.myContent) { if (contentEntry instanceof ClonableContentEntry) { ContentEntry cloned = ((ClonableContentEntry)contentEntry).cloneEntry(this); myContent.add(cloned); @@ -436,6 +435,7 @@ public class RootModelImpl extends RootModelBase implements ModifiableRootModel XmlSerializer.serializeInto(((PersistentStateComponent)extension).getState(), element); } else { + //noinspection deprecation extension.writeExternal(element); } }