deprecate unused StorageId, Storage#isDefault

This commit is contained in:
Vladimir Krivosheev
2015-02-24 06:42:21 +01:00
parent 4238e9aedb
commit 849c94433b
12 changed files with 94 additions and 99 deletions
@@ -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<TextDiffSettingsHolder.State> {
public static final Key<TextDiffSettings> 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;
}
@@ -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;
@@ -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<DirectoryStorageData
}
}
private static class MySaveSession implements SaveSession, ExternalizationSession {
private static class MySaveSession extends SaveSessionBase {
private final DirectoryBasedStorage storage;
private final DirectoryStorageData originalStorageData;
private DirectoryStorageData copiedStorageData;
@@ -192,26 +193,13 @@ public class DirectoryBasedStorage extends StateStorageBase<DirectoryStorageData
}
@Override
public void setState(@NotNull Object component, @NotNull String componentName, @NotNull Object state, Storage storageSpec) {
Element compositeState;
try {
compositeState = 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) {
removedFileNames.addAll(originalStorageData.getFileNames(componentName));
if (JDOMUtil.isEmpty(compositeState)) {
if (JDOMUtil.isEmpty(element)) {
doSetState(componentName, null, null);
}
else {
for (Pair<Element, String> pair : storage.mySplitter.splitState(compositeState)) {
for (Pair<Element, String> pair : storage.mySplitter.splitState(element)) {
removedFileNames.remove(pair.second);
doSetState(componentName, pair.second, pair.first);
}
@@ -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);
}
@@ -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);
}
@@ -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;
@@ -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<StorageData> {
}
}
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<StorageData> {
}
@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);
}
@@ -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.*;
@@ -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<? extends StateStorage> storageClass() default StateStorage.class;
Class<? extends StateSplitter> stateSplitter() default StateSplitterEx.class;
}
@@ -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();
}
@@ -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> T deserializeState(@Nullable Element stateElement, Class <T> stateClass, @Nullable T mergeInto) throws XmlSerializationException {
@@ -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);
}