diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffSettingsHolder.java b/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffSettingsHolder.java index a583068b2668..f73a10053abe 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffSettingsHolder.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/base/TextDiffSettingsHolder.java @@ -31,15 +31,15 @@ import java.util.Map; @State( name = "TextDiffSettings", - storages = {@Storage( - file = DiffUtil.DIFF_CONFIG)}) + storages = @Storage(file = DiffUtil.DIFF_CONFIG) +) public class TextDiffSettingsHolder implements PersistentStateComponent { public static final Key KEY = Key.create("TextDiffSettings"); public static final int[] CONTEXT_RANGE_MODES = {1, 2, 4, 8, -1}; public static final String[] CONTEXT_RANGE_MODE_LABELS = {"1", "2", "4", "8", "Disable"}; - private static class SharedSettings { + private final static class SharedSettings { // Fragments settings public int CONTEXT_RANGE = 4; } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java index fef8f4f8bac6..8e15a8f61f78 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ComponentStoreImpl.java @@ -22,7 +22,6 @@ import com.intellij.openapi.components.StateStorage.SaveSession; import com.intellij.openapi.components.impl.ComponentManagerImpl; import com.intellij.openapi.components.impl.stores.StateStorageManager.ExternalizationSession; import com.intellij.openapi.components.store.ReadOnlyModificationException; -import com.intellij.openapi.components.store.StateStorageBase; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java index 199d70123ca9..373d9c38f9a5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/DirectoryBasedStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -18,14 +18,15 @@ package com.intellij.openapi.components.impl.stores; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.*; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.StateSplitter; +import com.intellij.openapi.components.StateStorageException; +import com.intellij.openapi.components.TrackingPathMacroSubstitutor; import com.intellij.openapi.components.store.ReadOnlyModificationException; -import com.intellij.openapi.components.store.StateStorageBase; import com.intellij.openapi.editor.DocumentRunnable; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -178,7 +179,7 @@ public class DirectoryBasedStorage extends StateStorageBase pair : storage.mySplitter.splitState(compositeState)) { + for (Pair pair : storage.mySplitter.splitState(element)) { removedFileNames.remove(pair.second); doSetState(componentName, pair.second, pair.first); } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java index 53ac35c58ee3..6142c0823986 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/FileBasedStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -106,7 +106,7 @@ public class FileBasedStorage extends XmlElementStorage { } } - private class FileSaveSession extends XmlElementStorageSaveSession { + private class FileSaveSession extends XmlElementStorageSaveSession { protected FileSaveSession(@NotNull StorageData storageData) { super(storageData); } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/SaveSessionBase.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/SaveSessionBase.java new file mode 100644 index 000000000000..b46d88ea346b --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/SaveSessionBase.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2015 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.openapi.components.impl.stores; + +import com.intellij.openapi.components.StateStorage; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.util.JDOMExternalizable; +import com.intellij.openapi.util.WriteExternalException; +import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; +import com.intellij.util.xmlb.XmlSerializer; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +abstract class SaveSessionBase implements StateStorage.SaveSession, StateStorage.ExternalizationSession { + private SkipDefaultValuesSerializationFilters serializationFilter; + + @SuppressWarnings("deprecation") + @Override + public final void setState(@NotNull Object component, @NotNull String componentName, @NotNull Object state, Storage storageSpec) { + Element element; + try { + if (state instanceof Element) { + element = (Element)state; + } + else if (state instanceof JDOMExternalizable) { + element = new Element("temp_element"); + ((JDOMExternalizable)state).writeExternal(element); + } + else { + if (serializationFilter == null) { + serializationFilter = new SkipDefaultValuesSerializationFilters(); + } + element = XmlSerializer.serializeIfNotDefault(state, serializationFilter); + } + } + catch (WriteExternalException e) { + StateStorageBase.LOG.debug(e); + return; + } + catch (Throwable e) { + StateStorageBase.LOG.error("Unable to serialize " + componentName + " state", e); + return; + } + + setSerializedState(component, componentName, element); + } + + protected abstract void setSerializedState(@NotNull Object component, @NotNull String componentName, @Nullable Element element); +} diff --git a/platform/platform-impl/src/com/intellij/openapi/components/store/StateStorageBase.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageBase.java similarity index 91% rename from platform/platform-impl/src/com/intellij/openapi/components/store/StateStorageBase.java rename to platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageBase.java index da38c311e134..fb02c973e240 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/store/StateStorageBase.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.components.store; +package com.intellij.openapi.components.impl.stores; import com.intellij.openapi.components.StateStorage; import com.intellij.openapi.components.TrackingPathMacroSubstitutor; -import com.intellij.openapi.components.impl.stores.DefaultStateSerializer; -import com.intellij.openapi.components.impl.stores.StorageDataBase; import com.intellij.openapi.diagnostic.Logger; import org.jdom.Element; import org.jetbrains.annotations.NotNull; diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java index 4b6624d6cad0..78b624949979 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -17,11 +17,8 @@ package com.intellij.openapi.components.impl.stores; import com.intellij.openapi.components.RoamingType; import com.intellij.openapi.components.StateStorageException; -import com.intellij.openapi.components.Storage; import com.intellij.openapi.components.TrackingPathMacroSubstitutor; -import com.intellij.openapi.components.store.StateStorageBase; import com.intellij.openapi.util.JDOMUtil; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtil; @@ -175,7 +172,7 @@ public abstract class XmlElementStorage extends StateStorageBase { } } - protected abstract class XmlElementStorageSaveSession implements SaveSession, ExternalizationSession { + protected abstract class XmlElementStorageSaveSession extends SaveSessionBase { private final StorageData myOriginalStorageData; private StorageData myCopiedStorageData; @@ -192,20 +189,7 @@ public abstract class XmlElementStorage extends StateStorageBase { } @Override - public final void setState(@NotNull Object component, @NotNull String componentName, @NotNull Object state, @Nullable Storage storageSpec) { - Element element; - try { - element = DefaultStateSerializer.serializeState(state, storageSpec); - } - catch (WriteExternalException e) { - LOG.debug(e); - return; - } - catch (Throwable e) { - LOG.error("Unable to serialize " + componentName + " state", e); - return; - } - + protected void setSerializedState(@NotNull Object component, @NotNull String componentName, @Nullable Element element) { if (myCopiedStorageData == null) { myCopiedStorageData = StorageData.setStateAndCloneIfNeed(componentName, element, myOriginalStorageData, myNewLiveStates); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java index f12e25ba113d..401d3e5f9c09 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.java @@ -29,12 +29,8 @@ import com.intellij.openapi.application.*; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.application.impl.ApplicationImpl; import com.intellij.openapi.components.*; -import com.intellij.openapi.components.impl.stores.ComponentStoreImpl; +import com.intellij.openapi.components.impl.stores.*; import com.intellij.openapi.components.impl.stores.ComponentStoreImpl.ReloadComponentStoreStatus; -import com.intellij.openapi.components.impl.stores.FileBasedStorage; -import com.intellij.openapi.components.impl.stores.StateStorageManager; -import com.intellij.openapi.components.impl.stores.StorageUtil; -import com.intellij.openapi.components.store.StateStorageBase; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.*; diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/Storage.java b/platform/projectModel-api/src/com/intellij/openapi/components/Storage.java index 152cc036347c..0bdcbbfa6f28 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/Storage.java +++ b/platform/projectModel-api/src/com/intellij/openapi/components/Storage.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -24,8 +24,12 @@ import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) public @interface Storage { @NonNls String id() default "default"; + + @Deprecated boolean isDefault() default true; + @NonNls String file() default ""; + StorageScheme scheme() default StorageScheme.DEFAULT; /** @@ -39,5 +43,6 @@ public @interface Storage { RoamingType roamingType() default RoamingType.PER_USER; Class storageClass() default StateStorage.class; + Class stateSplitter() default StateSplitterEx.class; } diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StorageId.java b/platform/projectModel-api/src/com/intellij/openapi/components/StorageId.java index 0baf9e6ebd05..d00e69aae56e 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StorageId.java +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StorageId.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.openapi.components; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) +@Deprecated public @interface StorageId { String value(); } \ No newline at end of file diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java index d882ca15be83..3d1bb2240528 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/DefaultStateSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,20 +16,14 @@ package com.intellij.openapi.components.impl.stores; import com.intellij.openapi.components.StateStorageException; -import com.intellij.openapi.components.Storage; -import com.intellij.openapi.components.StorageId; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizable; import com.intellij.openapi.util.JDOMUtil; -import com.intellij.openapi.util.WriteExternalException; import com.intellij.util.ReflectionUtil; -import com.intellij.util.xmlb.Accessor; -import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters; import com.intellij.util.xmlb.XmlSerializationException; import com.intellij.util.xmlb.XmlSerializer; import org.jdom.Element; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @SuppressWarnings({"deprecation"}) @@ -39,37 +33,6 @@ public class DefaultStateSerializer { private DefaultStateSerializer() { } - @Nullable - static Element serializeState(@NotNull 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() { - @Override - protected boolean accepts(@NotNull Accessor accessor, @NotNull Object bean, @Nullable Object beanValue) { - if (!super.accepts(accessor, bean, beanValue)) { - return false; - } - - if (storage != null) { - StorageId storageId = accessor.getAnnotation(StorageId.class); - if (storageId != null && !storageId.value().equals(storage.id())) { - return false; - } - return storage.isDefault(); - } - return true; - } - }); - } - } - @SuppressWarnings({"unchecked"}) @Nullable public static T deserializeState(@Nullable Element stateElement, Class stateClass, @Nullable T mergeInto) throws XmlSerializationException { diff --git a/platform/util/src/com/intellij/util/xmlb/SkipDefaultValuesSerializationFilters.java b/platform/util/src/com/intellij/util/xmlb/SkipDefaultValuesSerializationFilters.java index f44785f6991c..db5819a9cc01 100644 --- a/platform/util/src/com/intellij/util/xmlb/SkipDefaultValuesSerializationFilters.java +++ b/platform/util/src/com/intellij/util/xmlb/SkipDefaultValuesSerializationFilters.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.util.xmlb; import com.intellij.openapi.util.Comparing; @@ -31,7 +30,7 @@ public class SkipDefaultValuesSerializationFilters extends SerializationFilterBa @Override protected boolean accepts(@NotNull Accessor accessor, @NotNull Object bean, @Nullable Object beanValue) { - final Object defValue = accessor.read(getDefaultBean(bean)); + Object defValue = accessor.read(getDefaultBean(bean)); if (defValue instanceof Element && beanValue instanceof Element) { return !JDOMUtil.areElementsEqual((Element)beanValue, (Element)defValue); }