Load/Save for old Intellij formatting settings (KT-22252)
#KT-22252 In Progress
This commit is contained in:
+12
-2
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.WriteExternalException;
|
|||||||
import com.intellij.psi.codeStyle.*;
|
import com.intellij.psi.codeStyle.*;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.kotlin.idea.formatter.KotlinObsoleteCodeStyle;
|
||||||
import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle;
|
import org.jetbrains.kotlin.idea.formatter.KotlinStyleGuideCodeStyle;
|
||||||
import org.jetbrains.kotlin.idea.util.ReflectionUtil;
|
import org.jetbrains.kotlin.idea.util.ReflectionUtil;
|
||||||
|
|
||||||
@@ -105,9 +106,16 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeExternal(Element parentElement, @NotNull CustomCodeStyleSettings parentSettings) throws WriteExternalException {
|
public void writeExternal(Element parentElement, @NotNull CustomCodeStyleSettings parentSettings) throws WriteExternalException {
|
||||||
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
if (CODE_STYLE_DEFAULTS != null) {
|
||||||
KotlinCodeStyleSettings defaultKotlinCodeStyle = (KotlinCodeStyleSettings) parentSettings.clone();
|
KotlinCodeStyleSettings defaultKotlinCodeStyle = (KotlinCodeStyleSettings) parentSettings.clone();
|
||||||
KotlinStyleGuideCodeStyle.Companion.applyToKotlinCustomSettings(defaultKotlinCodeStyle, false);
|
|
||||||
|
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinStyleGuideCodeStyle.Companion.applyToKotlinCustomSettings(defaultKotlinCodeStyle, false);
|
||||||
|
}
|
||||||
|
else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinObsoleteCodeStyle.Companion.applyToKotlinCustomSettings(defaultKotlinCodeStyle, false);
|
||||||
|
}
|
||||||
|
|
||||||
parentSettings = defaultKotlinCodeStyle;
|
parentSettings = defaultKotlinCodeStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +132,8 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
|
|||||||
KotlinCodeStyleSettings tempSettings = readExternalToTemp(parentElement);
|
KotlinCodeStyleSettings tempSettings = readExternalToTemp(parentElement);
|
||||||
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempSettings.CODE_STYLE_DEFAULTS)) {
|
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempSettings.CODE_STYLE_DEFAULTS)) {
|
||||||
KotlinStyleGuideCodeStyle.Companion.applyToKotlinCustomSettings(this, true);
|
KotlinStyleGuideCodeStyle.Companion.applyToKotlinCustomSettings(this, true);
|
||||||
|
} else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(tempSettings.CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinObsoleteCodeStyle.Companion.applyToKotlinCustomSettings(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actual read
|
// Actual read
|
||||||
|
|||||||
+8
-2
@@ -61,6 +61,8 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
|||||||
|
|
||||||
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
|
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
|
||||||
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(this, true);
|
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(this, true);
|
||||||
|
} else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinObsoleteCodeStyle.Companion.applyToCommonSettings(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
readExternalBase(element);
|
readExternalBase(element);
|
||||||
@@ -70,8 +72,12 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
|||||||
public void writeExternal(Element element) throws WriteExternalException {
|
public void writeExternal(Element element) throws WriteExternalException {
|
||||||
CommonCodeStyleSettings defaultSettings = getDefaultSettings();
|
CommonCodeStyleSettings defaultSettings = getDefaultSettings();
|
||||||
|
|
||||||
if (defaultSettings != null && KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
if (defaultSettings != null) {
|
||||||
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(defaultSettings, false);
|
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(defaultSettings, false);
|
||||||
|
} else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinObsoleteCodeStyle.Companion.applyToCommonSettings(defaultSettings, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeExternalBase(element, defaultSettings);
|
writeExternalBase(element, defaultSettings);
|
||||||
|
|||||||
+10
-2
@@ -34,6 +34,8 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
|||||||
@ReflectionUtil.SkipInEquals
|
@ReflectionUtil.SkipInEquals
|
||||||
public String CODE_STYLE_DEFAULTS = null;
|
public String CODE_STYLE_DEFAULTS = null;
|
||||||
|
|
||||||
|
private final KotlinCommonCodeStyleSettings oldDefaultSettings = null;
|
||||||
|
|
||||||
private final boolean isTempForDeserialize;
|
private final boolean isTempForDeserialize;
|
||||||
|
|
||||||
public KotlinCommonCodeStyleSettings() {
|
public KotlinCommonCodeStyleSettings() {
|
||||||
@@ -61,6 +63,8 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
|||||||
|
|
||||||
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
|
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
|
||||||
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(this, true);
|
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(this, true);
|
||||||
|
} else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(tempDeserialize.CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinObsoleteCodeStyle.Companion.applyToCommonSettings(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
readExternalBase(element);
|
readExternalBase(element);
|
||||||
@@ -70,8 +74,12 @@ public class KotlinCommonCodeStyleSettings extends CommonCodeStyleSettings {
|
|||||||
public void writeExternal(Element element) throws WriteExternalException {
|
public void writeExternal(Element element) throws WriteExternalException {
|
||||||
CommonCodeStyleSettings defaultSettings = getDefaultSettings();
|
CommonCodeStyleSettings defaultSettings = getDefaultSettings();
|
||||||
|
|
||||||
if (defaultSettings != null && KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
if (defaultSettings != null) {
|
||||||
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(defaultSettings, false);
|
if (KotlinStyleGuideCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinStyleGuideCodeStyle.Companion.applyToCommonSettings(defaultSettings, false);
|
||||||
|
} else if (KotlinObsoleteCodeStyle.CODE_STYLE_ID.equals(CODE_STYLE_DEFAULTS)) {
|
||||||
|
KotlinObsoleteCodeStyle.Companion.applyToCommonSettings(defaultSettings, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeExternalBase(element, defaultSettings);
|
writeExternalBase(element, defaultSettings);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class KotlinObsoleteCodeStyle : PredefinedCodeStyle(CODE_STYLE_TITLE, KotlinLang
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val CODE_STYLE_ID = "KOTLIN_OBSOLETE"
|
const val CODE_STYLE_ID = "KOTLIN_OLD_DEFAULTS"
|
||||||
const val CODE_STYLE_TITLE = "Kotlin obsolete IntelliJ IDEA codestyle"
|
const val CODE_STYLE_TITLE = "Kotlin obsolete IntelliJ IDEA codestyle"
|
||||||
|
|
||||||
fun apply(settings: CodeStyleSettings) {
|
fun apply(settings: CodeStyleSettings) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class KotlinSaveStylePanel(settings: CodeStyleSettings) : CodeStyleAbstractPanel
|
|||||||
private val saveDefaultsComboBox = ComboBox<SaveItem>()
|
private val saveDefaultsComboBox = ComboBox<SaveItem>()
|
||||||
private val saveDefaultsItems = listOf(
|
private val saveDefaultsItems = listOf(
|
||||||
SaveItem("<ide defaults>", null),
|
SaveItem("<ide defaults>", null),
|
||||||
SaveItem("Current set of defaults", "KOTLIN_OLD_DEFAULTS"),
|
SaveItem(KotlinObsoleteCodeStyle.CODE_STYLE_TITLE, KotlinObsoleteCodeStyle.CODE_STYLE_ID),
|
||||||
SaveItem(KotlinStyleGuideCodeStyle.CODE_STYLE_TITLE, KotlinStyleGuideCodeStyle.CODE_STYLE_ID)
|
SaveItem(KotlinStyleGuideCodeStyle.CODE_STYLE_TITLE, KotlinStyleGuideCodeStyle.CODE_STYLE_ID)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user