Configuration: Do not save default values of sourceMapEmbedSources
This commit is contained in:
+38
-13
@@ -19,15 +19,51 @@ package org.jetbrains.kotlin.idea.compiler.configuration
|
|||||||
import com.intellij.openapi.components.PersistentStateComponent
|
import com.intellij.openapi.components.PersistentStateComponent
|
||||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil
|
import com.intellij.openapi.progress.util.BackgroundTaskUtil
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Comparing
|
||||||
|
import com.intellij.openapi.util.JDOMUtil
|
||||||
import com.intellij.util.ReflectionUtil
|
import com.intellij.util.ReflectionUtil
|
||||||
import com.intellij.util.messages.Topic
|
import com.intellij.util.messages.Topic
|
||||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
|
import com.intellij.util.xmlb.Accessor
|
||||||
|
import com.intellij.util.xmlb.SerializationFilterBase
|
||||||
import com.intellij.util.xmlb.XmlSerializer
|
import com.intellij.util.xmlb.XmlSerializer
|
||||||
|
import gnu.trove.THashMap
|
||||||
import org.jdom.Element
|
import org.jdom.Element
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(private val project: Project) : PersistentStateComponent<Element>, Cloneable {
|
abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(private val project: Project) : PersistentStateComponent<Element>, Cloneable {
|
||||||
|
// Based on com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
|
||||||
|
private object DefaultValuesFilter : SerializationFilterBase() {
|
||||||
|
private val defaultBeans = THashMap<Class<*>, Any>()
|
||||||
|
|
||||||
|
private fun createDefaultBean(beanClass: Class<Any>): Any {
|
||||||
|
return ReflectionUtil.newInstance<Any>(beanClass).apply {
|
||||||
|
if (this is K2JSCompilerArguments) {
|
||||||
|
sourceMapPrefix = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getDefaultValue(accessor: Accessor, bean: Any): Any? {
|
||||||
|
if (bean is K2JSCompilerArguments && accessor.name == K2JSCompilerArguments::sourceMapEmbedSources.name) {
|
||||||
|
return if (bean.sourceMap) K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING else null
|
||||||
|
}
|
||||||
|
|
||||||
|
val beanClass = bean.javaClass
|
||||||
|
val defaultBean = defaultBeans.getOrPut(beanClass) { createDefaultBean(beanClass) }
|
||||||
|
return accessor.read(defaultBean)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun accepts(accessor: Accessor, bean: Any, beanValue: Any?): Boolean {
|
||||||
|
val defValue = getDefaultValue(accessor, bean)
|
||||||
|
return if (defValue is Element && beanValue is Element) {
|
||||||
|
!JDOMUtil.areElementsEqual(beanValue, defValue)
|
||||||
|
} else {
|
||||||
|
!Comparing.equal(beanValue, defValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("LeakingThis", "UNCHECKED_CAST")
|
@Suppress("LeakingThis", "UNCHECKED_CAST")
|
||||||
private var _settings: T = createSettings().frozen() as T
|
private var _settings: T = createSettings().frozen() as T
|
||||||
private set(value) {
|
private set(value) {
|
||||||
@@ -64,7 +100,7 @@ abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(p
|
|||||||
|
|
||||||
protected abstract fun createSettings(): T
|
protected abstract fun createSettings(): T
|
||||||
|
|
||||||
override fun getState() = XmlSerializer.serialize(_settings, SKIP_DEFAULT_VALUES)
|
override fun getState() = XmlSerializer.serialize(_settings, DefaultValuesFilter)
|
||||||
|
|
||||||
override fun loadState(state: Element) {
|
override fun loadState(state: Element) {
|
||||||
_settings = ReflectionUtil.newInstance(_settings.javaClass).apply {
|
_settings = ReflectionUtil.newInstance(_settings.javaClass).apply {
|
||||||
@@ -78,17 +114,6 @@ abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(p
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override fun clone(): Any = super.clone()
|
public override fun clone(): Any = super.clone()
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val SKIP_DEFAULT_VALUES = SkipDefaultValuesSerializationFilters(
|
|
||||||
CommonCompilerArguments.DummyImpl(),
|
|
||||||
K2JVMCompilerArguments(),
|
|
||||||
K2JSCompilerArguments().apply {
|
|
||||||
sourceMapPrefix = ""
|
|
||||||
sourceMapEmbedSources = K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinCompilerSettingsListener {
|
interface KotlinCompilerSettingsListener {
|
||||||
|
|||||||
+38
-11
@@ -20,16 +20,52 @@ import com.intellij.openapi.components.PersistentStateComponent
|
|||||||
import com.intellij.openapi.components.StoragePathMacros.PROJECT_CONFIG_DIR
|
import com.intellij.openapi.components.StoragePathMacros.PROJECT_CONFIG_DIR
|
||||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil
|
import com.intellij.openapi.progress.util.BackgroundTaskUtil
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Comparing
|
||||||
|
import com.intellij.openapi.util.JDOMUtil
|
||||||
import com.intellij.util.ReflectionUtil
|
import com.intellij.util.ReflectionUtil
|
||||||
import com.intellij.util.messages.Topic
|
import com.intellij.util.messages.Topic
|
||||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
|
import com.intellij.util.xmlb.Accessor
|
||||||
|
import com.intellij.util.xmlb.SerializationFilterBase
|
||||||
import com.intellij.util.xmlb.XmlSerializer
|
import com.intellij.util.xmlb.XmlSerializer
|
||||||
|
import gnu.trove.THashMap
|
||||||
import org.jdom.Element
|
import org.jdom.Element
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||||
import org.jetbrains.kotlin.config.SettingConstants
|
import org.jetbrains.kotlin.config.SettingConstants
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(private val project: Project) : PersistentStateComponent<Element>, Cloneable {
|
abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(private val project: Project) : PersistentStateComponent<Element>, Cloneable {
|
||||||
|
// Based on com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
|
||||||
|
private object DefaultValuesFilter : SerializationFilterBase() {
|
||||||
|
private val defaultBeans = THashMap<Class<*>, Any>()
|
||||||
|
|
||||||
|
private fun createDefaultBean(beanClass: Class<Any>): Any {
|
||||||
|
return ReflectionUtil.newInstance<Any>(beanClass).apply {
|
||||||
|
if (this is K2JSCompilerArguments) {
|
||||||
|
sourceMapPrefix = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getDefaultValue(accessor: Accessor, bean: Any): Any? {
|
||||||
|
if (bean is K2JSCompilerArguments && accessor.name == K2JSCompilerArguments::sourceMapEmbedSources.name) {
|
||||||
|
return if (bean.sourceMap) K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING else null
|
||||||
|
}
|
||||||
|
|
||||||
|
val beanClass = bean.javaClass
|
||||||
|
val defaultBean = defaultBeans.getOrPut(beanClass) { createDefaultBean(beanClass) }
|
||||||
|
return accessor.read(defaultBean)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun accepts(accessor: Accessor, bean: Any, beanValue: Any?): Boolean {
|
||||||
|
val defValue = getDefaultValue(accessor, bean)
|
||||||
|
return if (defValue is Element && beanValue is Element) {
|
||||||
|
!JDOMUtil.areElementsEqual(beanValue, defValue)
|
||||||
|
} else {
|
||||||
|
!Comparing.equal(beanValue, defValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("LeakingThis", "UNCHECKED_CAST")
|
@Suppress("LeakingThis", "UNCHECKED_CAST")
|
||||||
private var _settings: T = createSettings().frozen() as T
|
private var _settings: T = createSettings().frozen() as T
|
||||||
private set(value) {
|
private set(value) {
|
||||||
@@ -66,7 +102,7 @@ abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(p
|
|||||||
|
|
||||||
protected abstract fun createSettings(): T
|
protected abstract fun createSettings(): T
|
||||||
|
|
||||||
override fun getState() = XmlSerializer.serialize(_settings, SKIP_DEFAULT_VALUES)
|
override fun getState() = XmlSerializer.serialize(_settings, DefaultValuesFilter)
|
||||||
|
|
||||||
override fun loadState(state: Element) {
|
override fun loadState(state: Element) {
|
||||||
_settings = ReflectionUtil.newInstance(_settings.javaClass).apply {
|
_settings = ReflectionUtil.newInstance(_settings.javaClass).apply {
|
||||||
@@ -83,15 +119,6 @@ abstract class BaseKotlinCompilerSettings<T : Freezable> protected constructor(p
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val KOTLIN_COMPILER_SETTINGS_PATH = PROJECT_CONFIG_DIR + "/" + SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE
|
const val KOTLIN_COMPILER_SETTINGS_PATH = PROJECT_CONFIG_DIR + "/" + SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE
|
||||||
|
|
||||||
private val SKIP_DEFAULT_VALUES = SkipDefaultValuesSerializationFilters(
|
|
||||||
CommonCompilerArguments.DummyImpl(),
|
|
||||||
K2JVMCompilerArguments(),
|
|
||||||
K2JSCompilerArguments().apply {
|
|
||||||
sourceMapPrefix = ""
|
|
||||||
sourceMapEmbedSources = K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -563,7 +563,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
|||||||
k2jsCompilerArguments.setModuleKind(getSelectedModuleKind());
|
k2jsCompilerArguments.setModuleKind(getSelectedModuleKind());
|
||||||
|
|
||||||
k2jsCompilerArguments.setSourceMapPrefix(sourceMapPrefix.getText());
|
k2jsCompilerArguments.setSourceMapPrefix(sourceMapPrefix.getText());
|
||||||
k2jsCompilerArguments.setSourceMapEmbedSources(getSelectedSourceMapSourceEmbedding());
|
k2jsCompilerArguments.setSourceMapEmbedSources(generateSourceMapsCheckBox.isSelected() ? getSelectedSourceMapSourceEmbedding() : null);
|
||||||
|
|
||||||
k2jvmCompilerArguments.setJvmTarget(getSelectedJvmVersion());
|
k2jvmCompilerArguments.setJvmTarget(getSelectedJvmVersion());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user