diff --git a/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt b/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt index 9f8307f70a91..fefc84ccb4d1 100644 --- a/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt +++ b/platform/configuration-store-impl/src/ExternalStorageConfigurationManagerImpl.kt @@ -2,9 +2,8 @@ package com.intellij.openapi.project import com.intellij.openapi.components.BaseState -import com.intellij.openapi.components.PersistentStateComponent +import com.intellij.openapi.components.SimplePersistentStateComponent import com.intellij.openapi.components.State -import com.intellij.openapi.util.ModificationTracker import com.intellij.util.xmlb.annotations.Property @Property(style = Property.Style.ATTRIBUTE) @@ -13,19 +12,7 @@ class ExternalStorageConfiguration : BaseState() { } @State(name = "ExternalStorageConfigurationManager") -internal class ExternalStorageConfigurationManagerImpl : PersistentStateComponent, ModificationTracker, ExternalStorageConfigurationManager { - private var state = ExternalStorageConfiguration() - - override fun getModificationCount(): Long = state.modificationCount - - override fun getState(): ExternalStorageConfiguration { - return state - } - - override fun loadState(state: ExternalStorageConfiguration) { - this.state = state - } - +internal class ExternalStorageConfigurationManagerImpl : SimplePersistentStateComponent(ExternalStorageConfiguration()), ExternalStorageConfigurationManager { override fun isEnabled(): Boolean = state.enabled /** diff --git a/platform/configuration-store-impl/src/ProjectIdManager.kt b/platform/configuration-store-impl/src/ProjectIdManager.kt index 8a7300204c5c..9616a1a04b1a 100644 --- a/platform/configuration-store-impl/src/ProjectIdManager.kt +++ b/platform/configuration-store-impl/src/ProjectIdManager.kt @@ -3,24 +3,13 @@ package com.intellij.configurationStore import com.intellij.openapi.components.* import com.intellij.openapi.project.Project -import com.intellij.openapi.util.ModificationTracker import com.intellij.util.xmlb.annotations.Attribute @State(name = "ProjectId", storages = [(Storage(StoragePathMacros.WORKSPACE_FILE))]) -internal class ProjectIdManager : PersistentStateComponent, ModificationTracker { +internal class ProjectIdManager : SimplePersistentStateComponent(ProjectIdState()) { companion object { fun getInstance(project: Project) = project.service() } - - private var state = ProjectIdState() - - override fun getState() = state - - override fun loadState(state: ProjectIdState) { - this.state = state - } - - override fun getModificationCount() = state.modificationCount } internal class ProjectIdState : BaseState() { diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/BaseState.kt b/platform/projectModel-api/src/com/intellij/openapi/components/BaseState.kt index d4e01bc37a6b..c7e476651c5a 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/BaseState.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/BaseState.kt @@ -1,7 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.components -import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.util.ModificationTracker import com.intellij.serialization.PropertyAccessor import com.intellij.util.xmlb.Accessor @@ -14,9 +14,9 @@ import java.util.concurrent.atomic.AtomicLongFieldUpdater import kotlin.collections.ArrayList import kotlin.collections.LinkedHashMap -private val LOG = Logger.getInstance(BaseState::class.java) +private val LOG = logger() -private val factory: StatePropertyFactory = ServiceLoader.load(StatePropertyFactory::class.java).first() +private val factory: StatePropertyFactory = ServiceLoader.load(StatePropertyFactory::class.java).first() abstract class BaseState : SerializationFilter, ModificationTracker { companion object { @@ -37,6 +37,7 @@ abstract class BaseState : SerializationFilter, ModificationTracker { return p } + @Suppress("RemoveExplicitTypeArguments") protected fun property(): StoredPropertyBase = addProperty(factory.stateObject(null)) /** diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/SimplePersistentStateComponent.kt b/platform/projectModel-api/src/com/intellij/openapi/components/SimplePersistentStateComponent.kt new file mode 100644 index 000000000000..6885aed7084a --- /dev/null +++ b/platform/projectModel-api/src/com/intellij/openapi/components/SimplePersistentStateComponent.kt @@ -0,0 +1,15 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.components + +abstract class SimplePersistentStateComponent(initialState: T) : PersistentStateComponentWithModificationTracker { + @Volatile + private var state: T = initialState + + final override fun getState() = state + + final override fun getStateModificationCount() = state.modificationCount + + override fun loadState(state: T) { + this.state = state + } +} \ No newline at end of file diff --git a/plugins/configuration-script/src/ConfigurationFileManager.kt b/plugins/configuration-script/src/ConfigurationFileManager.kt index 97849d6d2da7..185e597a4fd9 100644 --- a/plugins/configuration-script/src/ConfigurationFileManager.kt +++ b/plugins/configuration-script/src/ConfigurationFileManager.kt @@ -22,7 +22,6 @@ import java.io.Reader import java.nio.file.Path import java.nio.file.Paths - // we cannot use the same approach as we generate JSON scheme because we should load option classes only in a lazy manner // that's why we don't use snakeyaml TypeDescription approach to load internal class ConfigurationFileManager(project: Project) { diff --git a/plugins/git4idea/src/git4idea/config/GitVcsSettings.java b/plugins/git4idea/src/git4idea/config/GitVcsSettings.java index 453e9b5f6070..fefea4cf6dd7 100644 --- a/plugins/git4idea/src/git4idea/config/GitVcsSettings.java +++ b/plugins/git4idea/src/git4idea/config/GitVcsSettings.java @@ -7,7 +7,6 @@ import com.intellij.dvcs.branch.DvcsCompareSettings; import com.intellij.dvcs.branch.DvcsSyncSettings; import com.intellij.openapi.components.*; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.ModificationTracker; import com.intellij.util.ArrayUtilRt; import com.intellij.util.xmlb.annotations.Attribute; import com.intellij.util.xmlb.annotations.Tag; @@ -26,11 +25,10 @@ import static git4idea.config.GitIncomingCheckStrategy.Never; * Git VCS settings */ @State(name = "Git.Settings", storages = @Storage(StoragePathMacros.WORKSPACE_FILE)) -public class GitVcsSettings implements PersistentStateComponent, DvcsSyncSettings, DvcsCompareSettings, ModificationTracker { +public class GitVcsSettings extends SimplePersistentStateComponent implements DvcsSyncSettings, DvcsCompareSettings { private static final int PREVIOUS_COMMIT_AUTHORS_LIMIT = 16; // Limit for previous commit authors private final GitVcsApplicationSettings myAppSettings; - private GitVcsOptions myState = new GitVcsOptions(); /** * The way the local changes are saved before update if user has selected auto-stash @@ -41,6 +39,8 @@ public class GitVcsSettings implements PersistentStateComponent, } public GitVcsSettings(GitVcsApplicationSettings appSettings) { + super(new GitVcsOptions()); + myAppSettings = appSettings; } @@ -54,20 +54,20 @@ public class GitVcsSettings implements PersistentStateComponent, @NotNull public UpdateMethod getUpdateMethod() { - return myState.getUpdateMethod(); + return getState().getUpdateMethod(); } public void setUpdateMethod(UpdateMethod updateType) { - myState.setUpdateMethod(updateType); + getState().setUpdateMethod(updateType); } @NotNull public UpdateChangesPolicy updateChangesPolicy() { - return myState.getUpdateChangesPolicy(); + return getState().getUpdateChangesPolicy(); } public void setUpdateChangesPolicy(UpdateChangesPolicy value) { - myState.setUpdateChangesPolicy(value); + getState().setUpdateChangesPolicy(value); } /** @@ -76,7 +76,7 @@ public class GitVcsSettings implements PersistentStateComponent, * @param author an author to save */ public void saveCommitAuthor(String author) { - List previousCommitAuthors = myState.getPreviousCommitAuthors(); + List previousCommitAuthors = getState().getPreviousCommitAuthors(); previousCommitAuthors.remove(author); while (previousCommitAuthors.size() >= PREVIOUS_COMMIT_AUTHORS_LIMIT) { previousCommitAuthors.remove(previousCommitAuthors.size() - 1); @@ -85,208 +85,198 @@ public class GitVcsSettings implements PersistentStateComponent, } public String[] getCommitAuthors() { - return ArrayUtilRt.toStringArray(myState.getPreviousCommitAuthors()); - } - - @Override - public long getModificationCount() { - return myState.getModificationCount(); - } - - @Override - public GitVcsOptions getState() { - return myState; + return ArrayUtilRt.toStringArray(getState().getPreviousCommitAuthors()); } @Override public void loadState(@NotNull GitVcsOptions state) { - myState = state; + super.loadState(state); migrateUpdateIncomingBranchInfo(state); } - private void migrateUpdateIncomingBranchInfo(@NotNull GitVcsOptions state) { + private static void migrateUpdateIncomingBranchInfo(@NotNull GitVcsOptions state) { if (!state.isUpdateBranchesInfo()) { - myState.setIncomingCheckStrategy(Never); + state.setIncomingCheckStrategy(Never); //set default value - myState.setUpdateBranchesInfo(true); + state.setUpdateBranchesInfo(true); } } @Nullable public String getPathToGit() { - return myState.getPathToGit(); + return getState().getPathToGit(); } public void setPathToGit(@Nullable String value) { - myState.setPathToGit(value); + getState().setPathToGit(value); } public boolean autoUpdateIfPushRejected() { - return myState.isPushAutoUpdate(); + return getState().isPushAutoUpdate(); } public void setAutoUpdateIfPushRejected(boolean value) { - myState.setPushAutoUpdate(value); + getState().setPushAutoUpdate(value); } public boolean shouldUpdateAllRootsIfPushRejected() { - return myState.isPushUpdateAllRoots(); + return getState().isPushUpdateAllRoots(); } public void setUpdateAllRootsIfPushRejected(boolean value) { - myState.setPushUpdateAllRoots(value); + getState().setPushUpdateAllRoots(value); } @Override @NotNull public Value getSyncSetting() { - return myState.getRootSync(); + return getState().getRootSync(); } @Override public void setSyncSetting(@NotNull Value value) { - myState.setRootSync(value); + getState().setRootSync(value); } @Nullable public String getRecentRootPath() { - return myState.getRecentGitRootPath(); + return getState().getRecentGitRootPath(); } public void setRecentRoot(@NotNull String value) { - myState.setRecentGitRootPath(value); + getState().setRecentGitRootPath(value); } @NotNull public Map getRecentBranchesByRepository() { - return myState.getRecentBranchByRepository(); + return getState().getRecentBranchByRepository(); } public void setRecentBranchOfRepository(@NotNull String repositoryPath, @NotNull String branch) { - myState.getRecentBranchByRepository().put(repositoryPath, branch); + getState().getRecentBranchByRepository().put(repositoryPath, branch); } @Nullable public String getRecentCommonBranch() { - return myState.getRecentCommonBranch(); + return getState().getRecentCommonBranch(); } public void setRecentCommonBranch(@NotNull String value) { - myState.setRecentCommonBranch(value); + getState().setRecentCommonBranch(value); } public void setAutoCommitOnRevert(boolean value) { - myState.setAutoCommitOnRevert(value); + getState().setAutoCommitOnRevert(value); } public boolean isAutoCommitOnRevert() { - return myState.isAutoCommitOnRevert(); + return getState().isAutoCommitOnRevert(); } public boolean warnAboutCrlf() { - return myState.getWarnAboutCrlf(); + return getState().getWarnAboutCrlf(); } public void setWarnAboutCrlf(boolean value) { - myState.setWarnAboutCrlf(value); + getState().setWarnAboutCrlf(value); } public boolean warnAboutDetachedHead() { - return myState.isWarnAboutDetachedHead(); + return getState().isWarnAboutDetachedHead(); } public void setWarnAboutDetachedHead(boolean value) { - myState.setWarnAboutDetachedHead(value); + getState().setWarnAboutDetachedHead(value); } @Nullable public GitResetMode getResetMode() { - return myState.getResetMode(); + return getState().getResetMode(); } public void setResetMode(@NotNull GitResetMode mode) { - myState.setResetMode(mode); + getState().setResetMode(mode); } @Nullable public GitPushTagMode getPushTagMode() { - return myState.getPushTags(); + return getState().getPushTags(); } public void setPushTagMode(@Nullable GitPushTagMode value) { - myState.setPushTags(value); + getState().setPushTags(value); } public boolean shouldSignOffCommit() { - return myState.isSignOffCommit(); + return getState().isSignOffCommit(); } public void setSignOffCommit(boolean value) { - myState.setSignOffCommit(value); + getState().setSignOffCommit(value); } @NotNull public GitIncomingCheckStrategy getIncomingCheckStrategy() { - return myState.getIncomingCheckStrategy(); + return getState().getIncomingCheckStrategy(); } public void setIncomingCheckStrategy(@NotNull GitIncomingCheckStrategy strategy) { - myState.setIncomingCheckStrategy(strategy); + getState().setIncomingCheckStrategy(strategy); } public boolean shouldPreviewPushOnCommitAndPush() { - return myState.isPreviewPushOnCommitAndPush(); + return getState().isPreviewPushOnCommitAndPush(); } public void setPreviewPushOnCommitAndPush(boolean value) { - myState.setPreviewPushOnCommitAndPush(value); + getState().setPreviewPushOnCommitAndPush(value); } public boolean isPreviewPushProtectedOnly() { - return myState.isPreviewPushProtectedOnly(); + return getState().isPreviewPushProtectedOnly(); } public void setPreviewPushProtectedOnly(boolean value) { - myState.setPreviewPushProtectedOnly(value); + getState().setPreviewPushProtectedOnly(value); } public boolean isCommitRenamesSeparately() { - return myState.isCommitRenamesSeparately(); + return getState().isCommitRenamesSeparately(); } public void setCommitRenamesSeparately(boolean value) { - myState.setCommitRenamesSeparately(value); + getState().setCommitRenamesSeparately(value); } @NotNull public DvcsBranchSettings getFavoriteBranchSettings() { - return myState.getFavoriteBranchSettings(); + return getState().getFavoriteBranchSettings(); } public boolean shouldSetUserNameGlobally() { - return myState.isSetUserNameGlobally(); + return getState().isSetUserNameGlobally(); } public void setUserNameGlobally(boolean value) { - myState.setSetUserNameGlobally(value); + getState().setSetUserNameGlobally(value); } @Override public boolean shouldSwapSidesInCompareBranches() { - return myState.isSwapSidesInCompareBranches(); + return getState().isSwapSidesInCompareBranches(); } @Override public void setSwapSidesInCompareBranches(boolean value) { - myState.setSwapSidesInCompareBranches(value); + getState().setSwapSidesInCompareBranches(value); } public boolean shouldAddSuffixToCherryPicksOfPublishedCommits() { - return myState.isAddSuffixToCherryPicksOfPublishedCommits(); + return getState().isAddSuffixToCherryPicksOfPublishedCommits(); } public void setAddSuffixToCherryPicks(boolean value) { - myState.setAddSuffixToCherryPicksOfPublishedCommits(value); + getState().setAddSuffixToCherryPicksOfPublishedCommits(value); } @Tag("push-target-info")