diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml
index 3fdb0646e31..b00ca857451 100644
--- a/.idea/inspectionProfiles/idea_default.xml
+++ b/.idea/inspectionProfiles/idea_default.xml
@@ -55,9 +55,6 @@
-
-
-
@@ -106,6 +103,8 @@
+
+
diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java b/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java
index 2b293ff3ddf..d7a40c154e7 100644
--- a/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java
+++ b/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/KotlinCodeStyleSettings.java
@@ -23,8 +23,10 @@ import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.codeStyle.*;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.formatter.KotlinObsoleteCodeStyle;
import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle;
+import org.jetbrains.kotlin.idea.util.FormatterUtilKt;
import org.jetbrains.kotlin.idea.util.ReflectionUtil;
import static com.intellij.util.ReflectionUtil.copyFields;
@@ -63,6 +65,12 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
@ReflectionUtil.SkipInEquals
public String CODE_STYLE_DEFAULTS = null;
+ /**
+ * Load settings with previous IDEA defaults to have an ability to restore them.
+ */
+ @Nullable
+ private KotlinCodeStyleSettings settingsAgainstPreviousDefaults = null;
+
private final boolean isTempForDeserialize;
public KotlinCodeStyleSettings(CodeStyleSettings container) {
@@ -95,6 +103,7 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
public KotlinCodeStyleSettings cloneSettings() {
KotlinCodeStyleSettings clone = new KotlinCodeStyleSettings(getContainer());
clone.copyFrom(this);
+ clone.settingsAgainstPreviousDefaults = this.settingsAgainstPreviousDefaults;
return clone;
}
@@ -136,10 +145,17 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
}
KotlinCodeStyleSettings tempSettings = readExternalToTemp(parentElement);
- if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempSettings.CODE_STYLE_DEFAULTS)) {
+ String customDefaults = tempSettings.CODE_STYLE_DEFAULTS;
+
+ if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(customDefaults)) {
KotlinStyleGuideCodeStyle.Companion.applyToKotlinCustomSettings(this, true);
- } else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(tempSettings.CODE_STYLE_DEFAULTS)) {
+ } else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(customDefaults)) {
KotlinObsoleteCodeStyle.Companion.applyToKotlinCustomSettings(this, true);
+ } else if (customDefaults == null && FormatterUtilKt.isDefaultOfficialCodeStyle()) {
+ // Temporary load settings against previous defaults
+ settingsAgainstPreviousDefaults = new KotlinCodeStyleSettings(null, true);
+ KotlinObsoleteCodeStyle.Companion.applyToKotlinCustomSettings(settingsAgainstPreviousDefaults, true);
+ settingsAgainstPreviousDefaults.readExternal(parentElement);
}
// Actual read
@@ -153,4 +169,10 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
return tempSettings;
}
+
+ public void restore() {
+ if (settingsAgainstPreviousDefaults != null) {
+ copyFrom(settingsAgainstPreviousDefaults);
+ }
+ }
}
diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/compatibility.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/compatibility.kt
new file mode 100644
index 00000000000..4aa2ce8845f
--- /dev/null
+++ b/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/compatibility.kt
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package org.jetbrains.kotlin.idea.core.formatter
+
+import com.intellij.psi.codeStyle.CommonCodeStyleSettings
+
+/**
+ * Method copyFrom is absent in 173.
+ * BUNCH: 181
+ */
+fun CommonCodeStyleSettings.copyFromEx(source: CommonCodeStyleSettings) {
+ @Suppress("IncompatibleAPI")
+ copyFrom(source)
+}
\ No newline at end of file
diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/compatibility.kt.173 b/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/compatibility.kt.173
new file mode 100644
index 00000000000..bb0f27982f9
--- /dev/null
+++ b/idea/formatter/src/org/jetbrains/kotlin/idea/core/formatter/compatibility.kt.173
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package org.jetbrains.kotlin.idea.core.formatter
+
+import com.intellij.psi.codeStyle.CommonCodeStyleSettings
+import com.intellij.psi.codeStyle.CommonCodeStyleSettingsManager
+
+/**
+ * Method copyFrom is absent in 173.
+ * BUNCH: 181
+ */
+fun CommonCodeStyleSettings.copyFromEx(source: CommonCodeStyleSettings) {
+ @Suppress("IncompatibleAPI")
+ CommonCodeStyleSettingsManager.copy(source, this)
+}
\ No newline at end of file
diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonCodeStyleSettings.java b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonCodeStyleSettings.java
index 3466b4a5b0e..92ceb633323 100644
--- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonCodeStyleSettings.java
+++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonCodeStyleSettings.java
@@ -21,6 +21,8 @@ import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.KotlinLanguage;
+import org.jetbrains.kotlin.idea.core.formatter.CompatibilityKt;
+import org.jetbrains.kotlin.idea.util.FormatterUtilKt;
import org.jetbrains.kotlin.idea.util.ReflectionUtil;
import java.lang.reflect.Field;
@@ -34,6 +36,12 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
@ReflectionUtil.SkipInEquals
public String CODE_STYLE_DEFAULTS = null;
+ /**
+ * Load settings with previous IDEA defaults to have an ability to restore them.
+ */
+ @Nullable
+ private KotlinCommonCodeStyleSettings settingsAgainstPreviousDefaults = null;
+
private final boolean isTempForDeserialize;
public KotlinCommonCodeStyleSettings() {
@@ -59,10 +67,16 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
KotlinCommonCodeStyleSettings tempDeserialize = createForTempDeserialize();
tempDeserialize.readExternal(element);
- if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
+ String customDefaults = tempDeserialize.CODE_STYLE_DEFAULTS;
+ if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(customDefaults)) {
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(this, true);
- } else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
+ } else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(customDefaults)) {
KotlinObsoleteCodeStyle.Companion.applyToCommonSettings(this, true);
+ } else if (customDefaults == null && FormatterUtilKt.isDefaultOfficialCodeStyle()) {
+ // Temporary load settings against previous defaults
+ settingsAgainstPreviousDefaults = createForTempDeserialize();
+ KotlinObsoleteCodeStyle.Companion.applyToCommonSettings(settingsAgainstPreviousDefaults, true);
+ settingsAgainstPreviousDefaults.readExternal(element);
}
readExternalBase(element);
@@ -121,7 +135,10 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
@Override
public CommonCodeStyleSettings clone(@NotNull CodeStyleSettings rootSettings) {
- CommonCodeStyleSettings commonSettings = new KotlinCommonCodeStyleSettings();
+ KotlinCommonCodeStyleSettings commonSettings = new KotlinCommonCodeStyleSettings();
+
+ commonSettings.settingsAgainstPreviousDefaults = settingsAgainstPreviousDefaults;
+
copyPublicFieldsOwn(this, commonSettings);
try {
@@ -214,6 +231,12 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
return provider == null ? null : provider.getSupportedFields();
}
+ public void restore() {
+ if (settingsAgainstPreviousDefaults != null) {
+ CompatibilityKt.copyFromEx(this, settingsAgainstPreviousDefaults);
+ }
+ }
+
private static class SupportedFieldsDiffFilter extends DifferenceFilter {
private final Set mySupportedFieldNames;