From ef2e87d8c8113b48a96657844f8a4dc8d319c3bf Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 14 Dec 2017 11:22:56 +0100 Subject: [PATCH] =?UTF-8?q?ObjectStoredProperty=20=E2=80=94=20null=20equal?= =?UTF-8?q?s=20to=20bean=20with=20default=20values=20and=20vice=20versa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applet/AppletConfigurationOptions.kt | 8 +- .../openapi/roots/LanguageLevelState.kt | 16 +-- .../testSrc/StoredPropertyStateTest.kt | 36 ++++- .../com/intellij/ide/ui/AntialiasingType.java | 4 +- .../src/com/intellij/ide/ui/UISettings.kt | 132 ++++++++---------- .../configurations/LogFileOptions.kt | 17 +-- .../configurations/RunConfigurationOptions.kt | 8 +- .../openapi/wm/impl/ProjectFrameBounds.kt | 10 +- .../intellij/openapi/components/BaseState.kt | 18 ++- .../openapi/components/StoredProperty.kt | 9 +- .../src/com/intellij/xdebugger/impl/state.kt | 2 +- .../LaunchBrowserBeforeRunTaskProvider.kt | 18 +-- 12 files changed, 141 insertions(+), 137 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationOptions.kt b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationOptions.kt index 6af6583fa65b..d2a0353d8194 100644 --- a/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationOptions.kt +++ b/java/execution/impl/src/com/intellij/execution/applet/AppletConfigurationOptions.kt @@ -16,13 +16,13 @@ class AppletConfigurationOptions : ModuleBasedConfigurationOptions() { var htmlFileName by string() @get:OptionTag("HTML_USED") - var htmlUsed by storedProperty(false) + var htmlUsed by property(false) @get:OptionTag("WIDTH") - var width by storedProperty(400) + var width by property(400) @get:OptionTag("HEIGHT") - var height by storedProperty(300) + var height by property(300) @get:OptionTag("POLICY_FILE") var policyFile by string(ExternalizablePath.urlValue("${PathManager.getHomePath()}/bin/appletviewer.policy")) @@ -31,7 +31,7 @@ class AppletConfigurationOptions : ModuleBasedConfigurationOptions() { var vmParameters by string() @get:OptionTag("ALTERNATIVE_JRE_PATH_ENABLED") - var alternativeJrePathEnabled by storedProperty(false) + var alternativeJrePathEnabled by property(false) @get:OptionTag("ALTERNATIVE_JRE_PATH") var alternativeJrePath by string() diff --git a/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt b/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt index a86dd7a17f4c..b2d946a8fd49 100644 --- a/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt +++ b/java/java-analysis-api/src/com/intellij/openapi/roots/LanguageLevelState.kt @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2017 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.roots @@ -21,5 +9,5 @@ import com.intellij.util.xmlb.annotations.Attribute class LanguageLevelState : BaseState() { @get:Attribute("LANGUAGE_LEVEL") - var languageLevel by storedProperty() + var languageLevel by property() } \ No newline at end of file diff --git a/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt b/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt index bf537adc20cf..b4c0c3a0943b 100644 --- a/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt +++ b/platform/configuration-store-impl/testSrc/StoredPropertyStateTest.kt @@ -12,18 +12,46 @@ internal class AState(languageLevel: String? = null, nestedComplex: NestedState? var bar by string() - var property2 by storedProperty(0) + var property2 by property(0) - var floatProperty by storedProperty(0.3) + var floatProperty by property(0.3) - var nestedComplex by storedProperty(nestedComplex) + var nestedComplex by property(nestedComplex) } internal class NestedState : BaseState() { - var childProperty by storedProperty() + var childProperty by property() } class StoredPropertyStateTest { + private class Foo : BaseState() { + var bar by property() + } + + private class Foo2 : BaseState() { + var bar by property(AState()) + } + + @Test + fun `default null equals to bean with default property values`() { + val f1 = Foo() + val f2 = Foo() + f2.bar = AState() + + assertThat(f1.serialize()).isNull() + assertThat(f2.serialize()).isNull() + } + + @Test + fun `bean with default property values equals to default null`() { + val f1 = Foo2() + val f2 = Foo2() + f2.bar = null + + assertThat(f1.serialize()).isNull() + assertThat(f2.serialize()).isNull() + } + @Test fun test() { val state = AState() diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/AntialiasingType.java b/platform/editor-ui-api/src/com/intellij/ide/ui/AntialiasingType.java index d0509d3180b8..253a9ebf0038 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/AntialiasingType.java +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/AntialiasingType.java @@ -19,7 +19,7 @@ public enum AntialiasingType { UISettings uiSettings = ApplicationManager.getApplication() == null ? null : UISettings.getInstance(); if (uiSettings != null) { AntialiasingType type = uiSettings.getIdeAAType(); - if (type != null) return type.getTextInfo(); + return type.getTextInfo(); } return GREYSCALE.getTextInfo(); } @@ -28,7 +28,7 @@ public enum AntialiasingType { UISettings uiSettings = ApplicationManager.getApplication() == null ? null : UISettings.getInstance(); if (uiSettings != null) { AntialiasingType type = inEditor ? uiSettings.getEditorAAType() : uiSettings.getIdeAAType(); - if (type != null) return type.myHint; + return type.myHint; } return RenderingHints.VALUE_TEXT_ANTIALIAS_ON; } diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt index c7c11aa4e834..e5b1b36695e9 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.kt @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2017 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.ide.ui @@ -53,76 +41,76 @@ class UISettings : BaseState(), PersistentStateComponent { @get:Property(filter = FontFilter::class) @get:OptionTag("FONT_SIZE") - var fontSize by storedProperty(defFontSize) + var fontSize by property(defFontSize) @get:Property(filter = FontFilter::class) @get:OptionTag("FONT_SCALE") - var fontScale by storedProperty(0f) + var fontScale by property(0f) - @get:OptionTag("RECENT_FILES_LIMIT") var recentFilesLimit by storedProperty(50) - @get:OptionTag("CONSOLE_COMMAND_HISTORY_LIMIT") var consoleCommandHistoryLimit by storedProperty(300) - @get:OptionTag("OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE") var overrideConsoleCycleBufferSize by storedProperty(false) - @get:OptionTag("CONSOLE_CYCLE_BUFFER_SIZE_KB") var consoleCycleBufferSizeKb by storedProperty(1024) - @get:OptionTag("EDITOR_TAB_LIMIT") var editorTabLimit by storedProperty(10) + @get:OptionTag("RECENT_FILES_LIMIT") var recentFilesLimit by property(50) + @get:OptionTag("CONSOLE_COMMAND_HISTORY_LIMIT") var consoleCommandHistoryLimit by property(300) + @get:OptionTag("OVERRIDE_CONSOLE_CYCLE_BUFFER_SIZE") var overrideConsoleCycleBufferSize by property(false) + @get:OptionTag("CONSOLE_CYCLE_BUFFER_SIZE_KB") var consoleCycleBufferSizeKb by property(1024) + @get:OptionTag("EDITOR_TAB_LIMIT") var editorTabLimit by property(10) - @get:OptionTag("REUSE_NOT_MODIFIED_TABS") var reuseNotModifiedTabs by storedProperty(false) - @get:OptionTag("ANIMATE_WINDOWS") var animateWindows by storedProperty(true) - @get:OptionTag("SHOW_TOOL_WINDOW_NUMBERS") var showToolWindowsNumbers by storedProperty(true) - @get:OptionTag("HIDE_TOOL_STRIPES") var hideToolStripes by storedProperty(true) - @get:OptionTag("WIDESCREEN_SUPPORT") var wideScreenSupport by storedProperty(false) - @get:OptionTag("LEFT_HORIZONTAL_SPLIT") var leftHorizontalSplit by storedProperty(false) - @get:OptionTag("RIGHT_HORIZONTAL_SPLIT") var rightHorizontalSplit by storedProperty(false) - @get:OptionTag("SHOW_EDITOR_TOOLTIP") var showEditorToolTip by storedProperty(true) - @get:OptionTag("SHOW_MEMORY_INDICATOR") var showMemoryIndicator by storedProperty(false) - @get:OptionTag("ALLOW_MERGE_BUTTONS") var allowMergeButtons by storedProperty(true) - @get:OptionTag("SHOW_MAIN_TOOLBAR") var showMainToolbar by storedProperty(false) - @get:OptionTag("SHOW_STATUS_BAR") var showStatusBar by storedProperty(true) - @get:OptionTag("SHOW_NAVIGATION_BAR") var showNavigationBar by storedProperty(true) - @get:OptionTag("ALWAYS_SHOW_WINDOW_BUTTONS") var alwaysShowWindowsButton by storedProperty(false) - @get:OptionTag("CYCLE_SCROLLING") var cycleScrolling by storedProperty(true) - @get:OptionTag("SCROLL_TAB_LAYOUT_IN_EDITOR") var scrollTabLayoutInEditor by storedProperty(true) - @get:OptionTag("HIDE_TABS_IF_NEED") var hideTabsIfNeed by storedProperty(true) - @get:OptionTag("SHOW_CLOSE_BUTTON") var showCloseButton by storedProperty(true) - @get:OptionTag("EDITOR_TAB_PLACEMENT") var editorTabPlacement by storedProperty(SwingConstants.TOP) - @get:OptionTag("HIDE_KNOWN_EXTENSION_IN_TABS") var hideKnownExtensionInTabs by storedProperty(false) - @get:OptionTag("SHOW_ICONS_IN_QUICK_NAVIGATION") var showIconInQuickNavigation by storedProperty(true) + @get:OptionTag("REUSE_NOT_MODIFIED_TABS") var reuseNotModifiedTabs by property(false) + @get:OptionTag("ANIMATE_WINDOWS") var animateWindows by property(true) + @get:OptionTag("SHOW_TOOL_WINDOW_NUMBERS") var showToolWindowsNumbers by property(true) + @get:OptionTag("HIDE_TOOL_STRIPES") var hideToolStripes by property(true) + @get:OptionTag("WIDESCREEN_SUPPORT") var wideScreenSupport by property(false) + @get:OptionTag("LEFT_HORIZONTAL_SPLIT") var leftHorizontalSplit by property(false) + @get:OptionTag("RIGHT_HORIZONTAL_SPLIT") var rightHorizontalSplit by property(false) + @get:OptionTag("SHOW_EDITOR_TOOLTIP") var showEditorToolTip by property(true) + @get:OptionTag("SHOW_MEMORY_INDICATOR") var showMemoryIndicator by property(false) + @get:OptionTag("ALLOW_MERGE_BUTTONS") var allowMergeButtons by property(true) + @get:OptionTag("SHOW_MAIN_TOOLBAR") var showMainToolbar by property(false) + @get:OptionTag("SHOW_STATUS_BAR") var showStatusBar by property(true) + @get:OptionTag("SHOW_NAVIGATION_BAR") var showNavigationBar by property(true) + @get:OptionTag("ALWAYS_SHOW_WINDOW_BUTTONS") var alwaysShowWindowsButton by property(false) + @get:OptionTag("CYCLE_SCROLLING") var cycleScrolling by property(true) + @get:OptionTag("SCROLL_TAB_LAYOUT_IN_EDITOR") var scrollTabLayoutInEditor by property(true) + @get:OptionTag("HIDE_TABS_IF_NEED") var hideTabsIfNeed by property(true) + @get:OptionTag("SHOW_CLOSE_BUTTON") var showCloseButton by property(true) + @get:OptionTag("EDITOR_TAB_PLACEMENT") var editorTabPlacement by property(SwingConstants.TOP) + @get:OptionTag("HIDE_KNOWN_EXTENSION_IN_TABS") var hideKnownExtensionInTabs by property(false) + @get:OptionTag("SHOW_ICONS_IN_QUICK_NAVIGATION") var showIconInQuickNavigation by property(true) - @get:OptionTag("CLOSE_NON_MODIFIED_FILES_FIRST") var closeNonModifiedFilesFirst by storedProperty(false) - @get:OptionTag("ACTIVATE_MRU_EDITOR_ON_CLOSE") var activeMruEditorOnClose by storedProperty(false) + @get:OptionTag("CLOSE_NON_MODIFIED_FILES_FIRST") var closeNonModifiedFilesFirst by property(false) + @get:OptionTag("ACTIVATE_MRU_EDITOR_ON_CLOSE") var activeMruEditorOnClose by property(false) // TODO[anton] consider making all IDEs use the same settings - @get:OptionTag("ACTIVATE_RIGHT_EDITOR_ON_CLOSE") var activeRightEditorOnClose by storedProperty(PlatformUtils.isAppCode()) + @get:OptionTag("ACTIVATE_RIGHT_EDITOR_ON_CLOSE") var activeRightEditorOnClose by property(PlatformUtils.isAppCode()) - @get:OptionTag("IDE_AA_TYPE") var ideAAType by storedProperty(AntialiasingType.SUBPIXEL) - @get:OptionTag("EDITOR_AA_TYPE") var editorAAType by storedProperty(AntialiasingType.SUBPIXEL) - @get:OptionTag("COLOR_BLINDNESS") var colorBlindness by storedProperty() - @get:OptionTag("MOVE_MOUSE_ON_DEFAULT_BUTTON") var moveMouseOnDefaultButton by storedProperty(false) - @get:OptionTag("ENABLE_ALPHA_MODE") var enableAlphaMode by storedProperty(false) - @get:OptionTag("ALPHA_MODE_DELAY") var alphaModeDelay by storedProperty(1500) - @get:OptionTag("ALPHA_MODE_RATIO") var alphaModeRatio by storedProperty(0.5f) - @get:OptionTag("MAX_CLIPBOARD_CONTENTS") var maxClipboardContents by storedProperty(5) - @get:OptionTag("OVERRIDE_NONIDEA_LAF_FONTS") var overrideLafFonts by storedProperty(false) - @get:OptionTag("SHOW_ICONS_IN_MENUS") var showIconsInMenus by storedProperty(!PlatformUtils.isAppCode()) + @get:OptionTag("IDE_AA_TYPE") var ideAAType by property(AntialiasingType.SUBPIXEL) + @get:OptionTag("EDITOR_AA_TYPE") var editorAAType by property(AntialiasingType.SUBPIXEL) + @get:OptionTag("COLOR_BLINDNESS") var colorBlindness by property() + @get:OptionTag("MOVE_MOUSE_ON_DEFAULT_BUTTON") var moveMouseOnDefaultButton by property(false) + @get:OptionTag("ENABLE_ALPHA_MODE") var enableAlphaMode by property(false) + @get:OptionTag("ALPHA_MODE_DELAY") var alphaModeDelay by property(1500) + @get:OptionTag("ALPHA_MODE_RATIO") var alphaModeRatio by property(0.5f) + @get:OptionTag("MAX_CLIPBOARD_CONTENTS") var maxClipboardContents by property(5) + @get:OptionTag("OVERRIDE_NONIDEA_LAF_FONTS") var overrideLafFonts by property(false) + @get:OptionTag("SHOW_ICONS_IN_MENUS") var showIconsInMenus by property(!PlatformUtils.isAppCode()) // IDEADEV-33409, should be disabled by default on MacOS - @get:OptionTag("DISABLE_MNEMONICS") var disableMnemonics by storedProperty(SystemInfo.isMac) - @get:OptionTag("DISABLE_MNEMONICS_IN_CONTROLS") var disableMnemonicsInControls by storedProperty(false) - @get:OptionTag("USE_SMALL_LABELS_ON_TABS") var useSmallLabelsOnTabs by storedProperty(SystemInfo.isMac) - @get:OptionTag("MAX_LOOKUP_WIDTH2") var maxLookupWidth by storedProperty(500) - @get:OptionTag("MAX_LOOKUP_LIST_HEIGHT") var maxLookupListHeight by storedProperty(11) - @get:OptionTag("HIDE_NAVIGATION_ON_FOCUS_LOSS") var hideNavigationOnFocusLoss by storedProperty(true) - @get:OptionTag("DND_WITH_PRESSED_ALT_ONLY") var dndWithPressedAltOnly by storedProperty(false) - @get:OptionTag("DEFAULT_AUTOSCROLL_TO_SOURCE") var defaultAutoScrollToSource by storedProperty(false) + @get:OptionTag("DISABLE_MNEMONICS") var disableMnemonics by property(SystemInfo.isMac) + @get:OptionTag("DISABLE_MNEMONICS_IN_CONTROLS") var disableMnemonicsInControls by property(false) + @get:OptionTag("USE_SMALL_LABELS_ON_TABS") var useSmallLabelsOnTabs by property(SystemInfo.isMac) + @get:OptionTag("MAX_LOOKUP_WIDTH2") var maxLookupWidth by property(500) + @get:OptionTag("MAX_LOOKUP_LIST_HEIGHT") var maxLookupListHeight by property(11) + @get:OptionTag("HIDE_NAVIGATION_ON_FOCUS_LOSS") var hideNavigationOnFocusLoss by property(true) + @get:OptionTag("DND_WITH_PRESSED_ALT_ONLY") var dndWithPressedAltOnly by property(false) + @get:OptionTag("DEFAULT_AUTOSCROLL_TO_SOURCE") var defaultAutoScrollToSource by property(false) @Transient var presentationMode = false - @get:OptionTag("PRESENTATION_MODE_FONT_SIZE") var presentationModeFontSize by storedProperty(24) - @get:OptionTag("MARK_MODIFIED_TABS_WITH_ASTERISK") var markModifiedTabsWithAsterisk by storedProperty(false) - @get:OptionTag("SHOW_TABS_TOOLTIPS") var showTabsTooltips by storedProperty(true) - @get:OptionTag("SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES") var showDirectoryForNonUniqueFilenames by storedProperty(true) - var smoothScrolling by storedProperty(SystemInfo.isMac && (SystemInfo.isJetBrainsJvm || SystemInfo.isJavaVersionAtLeast("9"))) - @get:OptionTag("NAVIGATE_TO_PREVIEW") var navigateToPreview by storedProperty(false) + @get:OptionTag("PRESENTATION_MODE_FONT_SIZE") var presentationModeFontSize by property(24) + @get:OptionTag("MARK_MODIFIED_TABS_WITH_ASTERISK") var markModifiedTabsWithAsterisk by property(false) + @get:OptionTag("SHOW_TABS_TOOLTIPS") var showTabsTooltips by property(true) + @get:OptionTag("SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES") var showDirectoryForNonUniqueFilenames by property(true) + var smoothScrolling by property(SystemInfo.isMac && (SystemInfo.isJetBrainsJvm || SystemInfo.isJavaVersionAtLeast("9"))) + @get:OptionTag("NAVIGATE_TO_PREVIEW") var navigateToPreview by property(false) - @get:OptionTag("SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY") var sortLookupElementsLexicographically by storedProperty(false) - @get:OptionTag("MERGE_EQUAL_STACKTRACES") var mergeEqualStackTraces by storedProperty(true) - @get:OptionTag("SORT_BOOKMARKS") var sortBookmarks by storedProperty(false) - @get:OptionTag("PIN_FIND_IN_PATH_POPUP") var pinFindInPath by storedProperty(false) + @get:OptionTag("SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY") var sortLookupElementsLexicographically by property(false) + @get:OptionTag("MERGE_EQUAL_STACKTRACES") var mergeEqualStackTraces by property(true) + @get:OptionTag("SORT_BOOKMARKS") var sortBookmarks by property(false) + @get:OptionTag("PIN_FIND_IN_PATH_POPUP") var pinFindInPath by property(false) private val myTreeDispatcher = ComponentTreeEventDispatcher.create(UISettingsListener::class.java) diff --git a/platform/lang-api/src/com/intellij/execution/configurations/LogFileOptions.kt b/platform/lang-api/src/com/intellij/execution/configurations/LogFileOptions.kt index 4ff94b21b5e4..e1097b595d18 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/LogFileOptions.kt +++ b/platform/lang-api/src/com/intellij/execution/configurations/LogFileOptions.kt @@ -27,11 +27,7 @@ class LogFileOptions : BaseState { @JvmStatic fun collectMatchedFiles(root: File, pattern: Pattern, files: MutableList) { val dirs = root.listFiles() ?: return - for (dir in dirs) { - if (pattern.matcher(dir.name).matches() && dir.isFile) { - files.add(dir) - } - } + dirs.filterTo(files) { pattern.matcher(it.name).matches() && it.isFile } } @JvmStatic @@ -55,16 +51,16 @@ class LogFileOptions : BaseState { var pathPattern by string() @get:Attribute("checked") - var isEnabled by storedProperty(true) + var isEnabled by property(true) @get:Attribute("skipped") - var isSkipContent by storedProperty(true) + var isSkipContent by property(true) @get:Attribute("show_all") - var isShowAll by storedProperty(false) + var isShowAll by property(false) @get:Attribute(value = "charset", converter = CharsetConverter::class) - var charset by storedProperty(Charset.defaultCharset()) + var charset by property(Charset.defaultCharset()) fun getPaths(): Set { val logFile = File(pathPattern!!) @@ -108,8 +104,7 @@ class LogFileOptions : BaseState { } //read external - constructor() { - } + constructor() @JvmOverloads constructor(name: String?, path: String?, enabled: Boolean = true, skipContent: Boolean = true, showAll: Boolean = false) : this(name, path, null, enabled, skipContent, showAll) diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt index 8e671f84fa7e..e33ea3b65ad8 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationOptions.kt @@ -12,7 +12,7 @@ open class RunConfigurationOptions : BaseState() { @get:Attribute("path") var fileOutputPath by string() @get:Attribute("is_save") - var isSaveOutput by storedProperty(false) + var isSaveOutput by property(false) } // we use object instead of 2 fields because XML serializer cannot reuse tag for several fields @@ -20,9 +20,9 @@ open class RunConfigurationOptions : BaseState() { var fileOutput by bean(OutputFileOptions()) @get:Attribute("show_console_on_std_out") - var isShowConsoleOnStdOut by storedProperty(false) + var isShowConsoleOnStdOut by property(false) @get:Attribute("show_console_on_std_err") - var isShowConsoleOnStdErr by storedProperty(false) + var isShowConsoleOnStdErr by property(false) @get:Property(surroundWithTag = false) @get:XCollection @@ -30,7 +30,7 @@ open class RunConfigurationOptions : BaseState() { } open class LocatableRunConfigurationOptions : RunConfigurationOptions() { - @get:Attribute("nameIsGenerated") var isNameGenerated by storedProperty(false) + @get:Attribute("nameIsGenerated") var isNameGenerated by property(false) } open class ModuleBasedConfigurationOptions : LocatableRunConfigurationOptions() { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameBounds.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameBounds.kt index 8917af6a3a43..444f9abf5856 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameBounds.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameBounds.kt @@ -1,4 +1,6 @@ -// Copyright 2000-2017 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. +/* + * Copyright 2000-2017 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.wm.impl import com.intellij.openapi.components.* @@ -51,10 +53,10 @@ class ProjectFrameBounds(private val project: Project) : PersistentStateComponen class FrameInfo : BaseState() { // flat is used due to backward compatibility - @get:Property(flat = true) var bounds by storedProperty() - @get:Attribute var extendedState by storedProperty(Frame.NORMAL) + @get:Property(flat = true) var bounds by property() + @get:Attribute var extendedState by property(Frame.NORMAL) - @get:Attribute var fullScreen by storedProperty(false) + @get:Attribute var fullScreen by property(false) } fun WindowManagerImpl.getFrameInfoInDeviceSpace(project: Project): FrameInfo? { 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 4f9abd223a88..061f22bc4732 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/BaseState.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/BaseState.kt @@ -30,12 +30,18 @@ abstract class BaseState : SerializationFilter, ModificationTracker { ownModificationCount++ } - fun storedProperty(defaultValue: T? = null): StoredPropertyBase { + fun property(defaultValue: T): StoredPropertyBase { val result = ObjectStoredProperty(defaultValue) properties.add(result) return result } + fun property(): StoredPropertyBase { + val result = ObjectStoredProperty(null) + properties.add(result) + return result + } + /** * Not-null list. Initialized as SmartList. */ @@ -66,25 +72,25 @@ abstract class BaseState : SerializationFilter, ModificationTracker { return result } - fun storedProperty(defaultValue: Int = 0): StoredPropertyBase { + fun property(defaultValue: Int = 0): StoredPropertyBase { val result = IntStoredProperty(defaultValue) properties.add(result) return result } - fun storedProperty(defaultValue: Long = 0): StoredPropertyBase { + fun property(defaultValue: Long = 0): StoredPropertyBase { val result = LongStoredProperty(defaultValue) properties.add(result) return result } - fun storedProperty(defaultValue: Float = 0f): StoredPropertyBase { + fun property(defaultValue: Float = 0f): StoredPropertyBase { val result = FloatStoredProperty(defaultValue) properties.add(result) return result } - fun storedProperty(defaultValue: Boolean = false): StoredPropertyBase { + fun property(defaultValue: Boolean = false): StoredPropertyBase { val result = ObjectStoredProperty(defaultValue) properties.add(result) return result @@ -104,6 +110,8 @@ abstract class BaseState : SerializationFilter, ModificationTracker { return true } + internal fun isEqualToDefault() = properties.all { it.isEqualToDefault() } + @Transient override fun getModificationCount(): Long { var result = ownModificationCount 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 ffd227790c9d..96b97ccdae1a 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StoredProperty.kt @@ -18,7 +18,14 @@ internal class ObjectStoredProperty(private val defaultValue: T) : StoredProp } } - override fun isEqualToDefault() = defaultValue == value + override fun isEqualToDefault(): Boolean { + val value = value + return when { + defaultValue == value -> true + value == null -> defaultValue is BaseState && defaultValue.isEqualToDefault() + else -> defaultValue == null && value is BaseState && value.isEqualToDefault() + } + } override fun equals(other: Any?) = this === other || (other is ObjectStoredProperty<*> && value == other.value) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/state.kt b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/state.kt index cf54cd8873a8..b2832f6b58f3 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/state.kt +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/state.kt @@ -29,7 +29,7 @@ class BreakpointManagerState : BaseState() { @get:Tag("breakpoints-dialog") var breakpointsDialogProperties: XBreakpointsDialogState? = null - var time by storedProperty(0L) + var time by property(0L) var defaultGroup by string() } diff --git a/xml/impl/src/com/intellij/ide/browsers/LaunchBrowserBeforeRunTaskProvider.kt b/xml/impl/src/com/intellij/ide/browsers/LaunchBrowserBeforeRunTaskProvider.kt index 301cc0658d7c..39cfab88d6f0 100644 --- a/xml/impl/src/com/intellij/ide/browsers/LaunchBrowserBeforeRunTaskProvider.kt +++ b/xml/impl/src/com/intellij/ide/browsers/LaunchBrowserBeforeRunTaskProvider.kt @@ -1,17 +1,5 @@ /* - * 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. + * Copyright 2000-2017 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.ide.browsers @@ -125,11 +113,11 @@ internal class LaunchBrowserBeforeRunTaskProvider : BeforeRunTaskProvider() + var browser by property() @get:Attribute() var url by string() @get:Attribute() - var withDebugger by storedProperty(false) + var withDebugger by property(false) } internal class LaunchBrowserBeforeRunTask : BeforeRunTask(LaunchBrowserBeforeRunTaskProvider.ID), PersistentStateComponent {