mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
BaseState — reset modification count on load state
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
This commit is contained in:
-1
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Any>(component.javaClass))
|
||||
(state as? BaseState)?.resetModificationCount()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(component as PersistentStateComponent<Any>).loadState(state)
|
||||
}
|
||||
+1
-1
@@ -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.
|
||||
@@ -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<ContentEntry> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user