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