J2K: Convert BaseKotlinCompilerSettings and its inheritors
This commit is contained in:
+26
-53
@@ -14,67 +14,40 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration;
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import org.jetbrains.kotlin.config.SettingConstants;
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.StoragePathMacros.PROJECT_CONFIG_DIR
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
|
||||
import com.intellij.util.xmlb.XmlSerializer
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.config.SettingConstants
|
||||
|
||||
import static com.intellij.openapi.components.StoragePathMacros.PROJECT_CONFIG_DIR;
|
||||
abstract class BaseKotlinCompilerSettings<T : Any> protected constructor() : PersistentStateComponent<Element>, Cloneable {
|
||||
@Suppress("LeakingThis")
|
||||
var settings: T = createSettings()
|
||||
private set
|
||||
|
||||
public abstract class BaseKotlinCompilerSettings<T> implements PersistentStateComponent<Element> {
|
||||
public static final String KOTLIN_COMPILER_SETTINGS_PATH = PROJECT_CONFIG_DIR + "/" + SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE;
|
||||
protected abstract fun createSettings(): T
|
||||
|
||||
private static final SkipDefaultValuesSerializationFilters SKIP_DEFAULT_VALUES = new SkipDefaultValuesSerializationFilters(
|
||||
CommonCompilerArguments.createDefaultInstance(),
|
||||
K2JVMCompilerArguments.createDefaultInstance(),
|
||||
K2JSCompilerArguments.createDefaultInstance()
|
||||
);
|
||||
@NotNull
|
||||
private T settings;
|
||||
override fun getState() = XmlSerializer.serialize(settings, SKIP_DEFAULT_VALUES)
|
||||
|
||||
protected BaseKotlinCompilerSettings() {
|
||||
//noinspection AbstractMethodCallInConstructor
|
||||
this.settings = createSettings();
|
||||
override fun loadState(state: Element) {
|
||||
settings = XmlSerializer.deserialize(state, settings.javaClass) ?: createSettings()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public T getSettings() {
|
||||
return settings;
|
||||
}
|
||||
public override fun clone(): Any = super.clone()
|
||||
|
||||
@NotNull
|
||||
protected abstract T createSettings();
|
||||
companion object {
|
||||
const val KOTLIN_COMPILER_SETTINGS_PATH = PROJECT_CONFIG_DIR + "/" + SettingConstants.KOTLIN_COMPILER_SETTINGS_FILE
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
return XmlSerializer.serialize(settings, SKIP_DEFAULT_VALUES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
//noinspection unchecked
|
||||
T newSettings = (T) XmlSerializer.deserialize(state, settings.getClass());
|
||||
if (newSettings == null)
|
||||
newSettings = createSettings();
|
||||
|
||||
settings = newSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
private val SKIP_DEFAULT_VALUES = SkipDefaultValuesSerializationFilters(
|
||||
CommonCompilerArguments.createDefaultInstance(),
|
||||
K2JVMCompilerArguments.createDefaultInstance(),
|
||||
K2JSCompilerArguments.createDefaultInstance()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+32
-50
@@ -14,70 +14,52 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration;
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.text.VersionComparatorUtil;
|
||||
import org.jdom.Attribute;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.kotlin.config.FacetSerializationKt;
|
||||
import org.jetbrains.kotlin.config.LanguageVersion;
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION
|
||||
import org.jetbrains.kotlin.config.getOption
|
||||
|
||||
import static org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION;
|
||||
|
||||
@State(
|
||||
name = KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION,
|
||||
storages = {
|
||||
@Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(file = BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class KotlinCommonCompilerArgumentsHolder extends BaseKotlinCompilerSettings<CommonCompilerArguments> {
|
||||
private static String DEFAULT_LANGUAGE_VERSION = LanguageVersion.LATEST.getVersionString();
|
||||
|
||||
public static KotlinCommonCompilerArgumentsHolder getInstance(Project project) {
|
||||
return ServiceManager.getService(project, KotlinCommonCompilerArgumentsHolder.class);
|
||||
}
|
||||
|
||||
private static void dropElementIfDefault(@Nullable Element element) {
|
||||
if (element == null) return;
|
||||
|
||||
Attribute versionAttribute = element.getAttribute("value");
|
||||
String version = versionAttribute != null ? versionAttribute.getValue() : null;
|
||||
if (DEFAULT_LANGUAGE_VERSION.equals(version)) {
|
||||
element.detach();
|
||||
@State(name = KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION,
|
||||
storages = arrayOf(Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
Storage(file = BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH,
|
||||
scheme = StorageScheme.DIRECTORY_BASED)))
|
||||
class KotlinCommonCompilerArgumentsHolder : BaseKotlinCompilerSettings<CommonCompilerArguments>() {
|
||||
private fun Element.dropElementIfDefault() {
|
||||
if (DEFAULT_LANGUAGE_VERSION == getAttribute("value")?.value) {
|
||||
detach()
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element element = super.getState();
|
||||
if (element != null) {
|
||||
override fun getState(): Element {
|
||||
return super.getState().apply {
|
||||
// Do not serialize language/api version if they correspond to the default language version
|
||||
dropElementIfDefault(FacetSerializationKt.getOption(element, "languageVersion"));
|
||||
dropElementIfDefault(FacetSerializationKt.getOption(element, "apiVersion"));
|
||||
getOption("languageVersion")?.dropElementIfDefault()
|
||||
getOption("apiVersion")?.dropElementIfDefault()
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
super.loadState(state);
|
||||
override fun loadState(state: Element) {
|
||||
super.loadState(state)
|
||||
|
||||
// To fix earlier configurations with incorrect combination of language and API version
|
||||
CommonCompilerArguments settings = getSettings();
|
||||
val settings = settings
|
||||
if (VersionComparatorUtil.compare(settings.languageVersion, settings.apiVersion) < 0) {
|
||||
settings.apiVersion = settings.languageVersion;
|
||||
settings.apiVersion = settings.languageVersion
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected CommonCompilerArguments createSettings() {
|
||||
return CommonCompilerArguments.createDefaultInstance();
|
||||
override fun createSettings() = CommonCompilerArguments.createDefaultInstance()
|
||||
|
||||
companion object {
|
||||
private val DEFAULT_LANGUAGE_VERSION = LanguageVersion.LATEST.versionString
|
||||
|
||||
fun getInstance(project: Project) =
|
||||
ServiceManager.getService<KotlinCommonCompilerArgumentsHolder>(project, KotlinCommonCompilerArgumentsHolder::class.java)!!
|
||||
}
|
||||
}
|
||||
|
||||
+12
-24
@@ -14,32 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration;
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.config.CompilerSettings;
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.config.CompilerSettings
|
||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMPILER_SETTINGS_SECTION
|
||||
|
||||
import static org.jetbrains.kotlin.idea.compiler.configuration.BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH;
|
||||
import static org.jetbrains.kotlin.config.SettingConstants.KOTLIN_COMPILER_SETTINGS_SECTION;
|
||||
@State(name = KOTLIN_COMPILER_SETTINGS_SECTION,
|
||||
storages = arrayOf(Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
Storage(file = BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)))
|
||||
class KotlinCompilerSettings : BaseKotlinCompilerSettings<CompilerSettings>() {
|
||||
override fun createSettings() = CompilerSettings()
|
||||
|
||||
@State(
|
||||
name = KOTLIN_COMPILER_SETTINGS_SECTION,
|
||||
storages = {
|
||||
@Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class KotlinCompilerSettings extends BaseKotlinCompilerSettings<CompilerSettings> {
|
||||
|
||||
public static KotlinCompilerSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, KotlinCompilerSettings.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected CompilerSettings createSettings() {
|
||||
return new CompilerSettings();
|
||||
companion object {
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, KotlinCompilerSettings::class.java)!!
|
||||
}
|
||||
}
|
||||
|
||||
+13
-24
@@ -14,32 +14,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration;
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.BaseKotlinCompilerSettings.Companion.KOTLIN_COMPILER_SETTINGS_PATH
|
||||
|
||||
import static org.jetbrains.kotlin.idea.compiler.configuration.BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH;
|
||||
import static org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION;
|
||||
@State(name = KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION,
|
||||
storages = arrayOf(Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)))
|
||||
class Kotlin2JsCompilerArgumentsHolder : BaseKotlinCompilerSettings<K2JSCompilerArguments>() {
|
||||
override fun createSettings() = K2JSCompilerArguments.createDefaultInstance()
|
||||
|
||||
@State(
|
||||
name = KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION,
|
||||
storages = {
|
||||
@Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class Kotlin2JsCompilerArgumentsHolder extends BaseKotlinCompilerSettings<K2JSCompilerArguments> {
|
||||
|
||||
public static Kotlin2JsCompilerArgumentsHolder getInstance(Project project) {
|
||||
return ServiceManager.getService(project, Kotlin2JsCompilerArgumentsHolder.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JSCompilerArguments createSettings() {
|
||||
return K2JSCompilerArguments.createDefaultInstance();
|
||||
companion object {
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, Kotlin2JsCompilerArgumentsHolder::class.java)!!
|
||||
}
|
||||
}
|
||||
|
||||
+13
-23
@@ -14,32 +14,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration;
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
|
||||
import static org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION;
|
||||
import static org.jetbrains.kotlin.idea.compiler.configuration.BaseKotlinCompilerSettings.KOTLIN_COMPILER_SETTINGS_PATH;
|
||||
import org.jetbrains.kotlin.config.SettingConstants.KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION
|
||||
import org.jetbrains.kotlin.idea.compiler.configuration.BaseKotlinCompilerSettings.Companion.KOTLIN_COMPILER_SETTINGS_PATH
|
||||
|
||||
@State(
|
||||
name = KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION,
|
||||
storages = {
|
||||
@Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class Kotlin2JvmCompilerArgumentsHolder extends BaseKotlinCompilerSettings<K2JVMCompilerArguments> {
|
||||
@State(name = KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION,
|
||||
storages = arrayOf(Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
Storage(file = KOTLIN_COMPILER_SETTINGS_PATH, scheme = StorageScheme.DIRECTORY_BASED)))
|
||||
class Kotlin2JvmCompilerArgumentsHolder : BaseKotlinCompilerSettings<K2JVMCompilerArguments>() {
|
||||
override fun createSettings() = K2JVMCompilerArguments.createDefaultInstance()
|
||||
|
||||
public static Kotlin2JvmCompilerArgumentsHolder getInstance(Project project) {
|
||||
return ServiceManager.getService(project, Kotlin2JvmCompilerArgumentsHolder.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected K2JVMCompilerArguments createSettings() {
|
||||
return K2JVMCompilerArguments.createDefaultInstance();
|
||||
companion object {
|
||||
fun getInstance(project: Project) = ServiceManager.getService(project, Kotlin2JvmCompilerArgumentsHolder::class.java)!!
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -175,10 +175,10 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
||||
@SuppressWarnings("unused")
|
||||
public KotlinCompilerConfigurableTab(Project project) {
|
||||
this(project,
|
||||
KotlinCommonCompilerArgumentsHolder.getInstance(project).getSettings(),
|
||||
Kotlin2JsCompilerArgumentsHolder.getInstance(project).getSettings(),
|
||||
Kotlin2JvmCompilerArgumentsHolder.getInstance(project).getSettings(),
|
||||
KotlinCompilerSettings.getInstance(project).getSettings(),
|
||||
KotlinCommonCompilerArgumentsHolder.Companion.getInstance(project).getSettings(),
|
||||
Kotlin2JsCompilerArgumentsHolder.Companion.getInstance(project).getSettings(),
|
||||
Kotlin2JvmCompilerArgumentsHolder.Companion.getInstance(project).getSettings(),
|
||||
KotlinCompilerSettings.Companion.getInstance(project).getSettings(),
|
||||
ServiceManager.getService(project, KotlinCompilerWorkspaceSettings.class),
|
||||
true,
|
||||
false);
|
||||
|
||||
Reference in New Issue
Block a user