Get rid of coroutinesWarn/coroutinesEnable/coroutinesError

Use a single coroutinesState instead. Change the coroutines state in
some tests from "warn" to "enable"/"error" to test that deserialization
of older config files works ("warn" is the default value, so it wasn't
testing anything here)
This commit is contained in:
Alexander Udalov
2017-04-05 19:00:53 +03:00
parent f4b6db4dc0
commit be54e4b93b
20 changed files with 194 additions and 164 deletions
@@ -63,13 +63,13 @@ fun JvmBuildMetaInfo(args: CommonCompilerArguments): JvmBuildMetaInfo =
compilerBuildVersion = KotlinCompilerVersion.VERSION,
languageVersionString = args.languageVersion ?: LanguageVersion.LATEST_STABLE.versionString,
apiVersionString = args.apiVersion ?: ApiVersion.LATEST_STABLE.versionString,
coroutinesEnable = args.coroutinesEnable,
coroutinesWarn = args.coroutinesWarn,
coroutinesError = args.coroutinesError,
coroutinesEnable = args.coroutinesState == CommonCompilerArguments.ENABLE,
coroutinesWarn = args.coroutinesState == CommonCompilerArguments.WARN,
coroutinesError = args.coroutinesState == CommonCompilerArguments.ERROR,
multiplatformEnable = args.multiPlatform,
metadataVersionMajor = JvmMetadataVersion.INSTANCE.major,
metadataVersionMinor = JvmMetadataVersion.INSTANCE.minor,
metadataVersionPatch = JvmMetadataVersion.INSTANCE.patch,
bytecodeVersionMajor = JvmBytecodeBinaryVersion.INSTANCE.major,
bytecodeVersionMinor = JvmBytecodeBinaryVersion.INSTANCE.minor,
bytecodeVersionPatch = JvmBytecodeBinaryVersion.INSTANCE.patch)
bytecodeVersionPatch = JvmBytecodeBinaryVersion.INSTANCE.patch)
@@ -17,10 +17,8 @@
package org.jetbrains.kotlin.build
import junit.framework.TestCase
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
import org.junit.Assert.assertNotEquals
import org.junit.Test
@@ -64,14 +62,14 @@ class JvmBuildMetaInfoTest : TestCase() {
@Test
fun testEquals() {
val args1 = K2JVMCompilerArguments()
args1.coroutinesEnable = true
args1.coroutinesState = CommonCompilerArguments.ENABLE
val info1 = JvmBuildMetaInfo(args1)
val args2 = K2JVMCompilerArguments()
args2.coroutinesEnable = false
args2.coroutinesState = CommonCompilerArguments.WARN
val info2 = JvmBuildMetaInfo(args2)
assertNotEquals(info1, info2)
assertEquals(info1, info2.copy(coroutinesEnable = true))
assertEquals(info1, info2.copy(coroutinesEnable = true, coroutinesWarn = false))
}
}
}
@@ -91,14 +91,12 @@ public abstract class CommonCompilerArguments implements Serializable {
@Argument(value = "-Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects")
public boolean noCheckImpl;
@Argument(value = "-Xcoroutines=warn", description = "")
public boolean coroutinesWarn;
@Argument(value = "-Xcoroutines=error", description = "")
public boolean coroutinesError;
@Argument(value = "-Xcoroutines=enable", description = "")
public boolean coroutinesEnable;
@Argument(
value = "-Xcoroutines",
valueDescription = "{enable|warn|error}",
description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier"
)
public String coroutinesState = WARN;
public List<String> freeArgs = new SmartList<>();
@@ -109,11 +107,7 @@ public abstract class CommonCompilerArguments implements Serializable {
@NotNull
public static CommonCompilerArguments createDefaultInstance() {
DummyImpl arguments = new DummyImpl();
arguments.coroutinesEnable = false;
arguments.coroutinesWarn = true;
arguments.coroutinesError = false;
return arguments;
return new DummyImpl();
}
@NotNull
@@ -121,6 +115,10 @@ public abstract class CommonCompilerArguments implements Serializable {
return "kotlinc";
}
public static final String WARN = "warn";
public static final String ERROR = "error";
public static final String ENABLE = "enable";
// Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments {}
}
@@ -275,19 +275,17 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull CompilerConfiguration configuration,
@NotNull CommonCompilerArguments arguments
) {
if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) {
return LanguageFeature.State.ENABLED_WITH_ERROR;
}
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) {
return LanguageFeature.State.ENABLED;
}
else if (!arguments.coroutinesEnable && !arguments.coroutinesError) {
return null;
}
else {
String message = "The -Xcoroutines can only have one value";
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
return null;
switch (arguments.coroutinesState) {
case CommonCompilerArguments.ERROR:
return LanguageFeature.State.ENABLED_WITH_ERROR;
case CommonCompilerArguments.ENABLE:
return LanguageFeature.State.ENABLED;
case CommonCompilerArguments.WARN:
return null;
default:
String message = "Invalid value of -Xcoroutines (should be: enable, warn or error): " + arguments.coroutinesState;
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
return null;
}
}
@@ -29,20 +29,13 @@ class Usage {
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
private static final int OPTION_NAME_PADDING_WIDTH = 29;
private static final String coroutinesKeyDescription = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier";
public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments, boolean extraHelp) {
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
target.println("where " + (extraHelp ? "advanced" : "possible") + " options include:");
boolean coroutinesUsagePrinted = false;
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
for (Field field : clazz.getDeclaredFields()) {
String usage = fieldUsage(field, extraHelp);
if (usage != null) {
if (usage.contains("Xcoroutines")) {
if (coroutinesUsagePrinted) continue;
coroutinesUsagePrinted = true;
}
target.println(usage);
}
}
@@ -59,14 +52,10 @@ class Usage {
Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null;
String argumentValue = argument.value();
// TODO: this is a dirty hack, provide better mechanism for keys that can have several values
boolean isXCoroutinesKey = argumentValue.contains("Xcoroutines");
String value = isXCoroutinesKey ? "-Xcoroutines={enable|warn|error}" : argumentValue;
if (extraHelp != ParseCommandLineArgumentsKt.isAdvanced(argument)) return null;
StringBuilder sb = new StringBuilder(" ");
sb.append(value);
sb.append(argument.value());
if (!argument.shortName().isEmpty()) {
sb.append(" (");
@@ -79,12 +68,6 @@ class Usage {
sb.append(argument.valueDescription());
}
if (isXCoroutinesKey) {
sb.append(" ");
sb.append(coroutinesKeyDescription);
return sb.toString();
}
int width = OPTION_NAME_PADDING_WIDTH - 1;
if (sb.length() >= width + 5) { // Break the line if it's too long
sb.append("\n");
+2 -1
View File
@@ -8,7 +8,8 @@ where advanced options include:
-Xplugin=<path> Load plugins from the given classpath
-Xmulti-platform Enable experimental language support for multi-platform projects
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
-Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
-Xcoroutines={enable|warn|error}
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
Advanced options are non-standard and may be changed or removed without any notice.
OK
+2 -1
View File
@@ -20,7 +20,8 @@ where advanced options include:
-Xplugin=<path> Load plugins from the given classpath
-Xmulti-platform Enable experimental language support for multi-platform projects
-Xno-check-impl Do not check presence of 'impl' modifier in multi-platform projects
-Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
-Xcoroutines={enable|warn|error}
Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier
Advanced options are non-standard and may be changed or removed without any notice.
OK
@@ -55,11 +55,10 @@ object CoroutineSupport {
fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State =
byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when {
arguments == null -> null
arguments.coroutinesEnable -> LanguageFeature.State.ENABLED
arguments.coroutinesWarn -> LanguageFeature.State.ENABLED_WITH_WARNING
arguments.coroutinesError -> LanguageFeature.State.ENABLED_WITH_ERROR
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when (arguments?.coroutinesState) {
CommonCompilerArguments.ENABLE -> LanguageFeature.State.ENABLED
CommonCompilerArguments.WARN -> LanguageFeature.State.ENABLED_WITH_WARNING
CommonCompilerArguments.ERROR -> LanguageFeature.State.ENABLED_WITH_ERROR
else -> null
}
@@ -77,7 +76,7 @@ object CoroutineSupport {
class KotlinFacetSettings {
companion object {
// Increment this when making serialization-incompatible changes to configuration data
val CURRENT_VERSION = 2
val CURRENT_VERSION = 3
val DEFAULT_VERSION = 0
}
@@ -118,10 +117,10 @@ class KotlinFacetSettings {
return CoroutineSupport.byCompilerArguments(compilerArguments)
}
set(value) {
with(compilerArguments!!) {
coroutinesEnable = value == LanguageFeature.State.ENABLED
coroutinesWarn = value == LanguageFeature.State.ENABLED_WITH_WARNING
coroutinesError = value == LanguageFeature.State.ENABLED_WITH_ERROR || value == LanguageFeature.State.DISABLED
compilerArguments!!.coroutinesState = when (value) {
LanguageFeature.State.ENABLED -> CommonCompilerArguments.ENABLE
LanguageFeature.State.ENABLED_WITH_WARNING -> CommonCompilerArguments.WARN
LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> CommonCompilerArguments.ERROR
}
}
@@ -85,7 +85,7 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
}
}
private fun readV2Config(element: Element): KotlinFacetSettings {
private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
return KotlinFacetSettings().apply {
element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() }
val platformName = element.getAttributeValue("platform")
@@ -101,6 +101,25 @@ private fun readV2Config(element: Element): KotlinFacetSettings {
}
}
private fun readV2Config(element: Element): KotlinFacetSettings {
return readV2AndLaterConfig(element).apply {
element.getChild("compilerArguments")?.children?.let { args ->
when {
args.any { arg -> arg.attributes[0].value == "coroutinesEnable" && arg.attributes[1].booleanValue } ->
compilerArguments!!.coroutinesState = CommonCompilerArguments.ENABLE
args.any { arg -> arg.attributes[0].value == "coroutinesWarn" && arg.attributes[1].booleanValue } ->
compilerArguments!!.coroutinesState = CommonCompilerArguments.WARN
args.any { arg -> arg.attributes[0].value == "coroutinesError" && arg.attributes[1].booleanValue } ->
compilerArguments!!.coroutinesState = CommonCompilerArguments.ERROR
}
}
}
}
private fun readLatestConfig(element: Element): KotlinFacetSettings {
return readV2AndLaterConfig(element)
}
fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
val version =
try {
@@ -112,6 +131,7 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
return when (version) {
1 -> readV1Config(element)
2 -> readV2Config(element)
KotlinFacetSettings.CURRENT_VERSION -> readLatestConfig(element)
else -> KotlinFacetSettings() // Reset facet configuration if versions don't match
}
}
@@ -461,11 +461,20 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
commonCompilerArguments.suppressWarnings = !reportWarningsCheckBox.isSelected();
commonCompilerArguments.languageVersion = getSelectedLanguageVersion().getVersionString();
commonCompilerArguments.apiVersion = getSelectedAPIVersion().getVersionString();
LanguageFeature.State coroutineSupport = (LanguageFeature.State) coroutineSupportComboBox.getSelectedItem();
commonCompilerArguments.coroutinesEnable = coroutineSupport == LanguageFeature.State.ENABLED;
commonCompilerArguments.coroutinesWarn = coroutineSupport == LanguageFeature.State.ENABLED_WITH_WARNING;
commonCompilerArguments.coroutinesError = coroutineSupport == LanguageFeature.State.ENABLED_WITH_ERROR ||
coroutineSupport == LanguageFeature.State.DISABLED;
switch ((LanguageFeature.State) coroutineSupportComboBox.getSelectedItem()) {
case ENABLED:
commonCompilerArguments.coroutinesState = CommonCompilerArguments.ENABLE;
break;
case ENABLED_WITH_WARNING:
commonCompilerArguments.coroutinesState = CommonCompilerArguments.WARN;
break;
case ENABLED_WITH_ERROR:
case DISABLED:
commonCompilerArguments.coroutinesState = CommonCompilerArguments.ERROR;
break;
}
compilerSettings.additionalArguments = additionalArgsOptionsField.getText();
compilerSettings.scriptTemplates = scriptTemplatesField.getText();
compilerSettings.scriptTemplatesClasspath = scriptTemplatesClasspathField.getText();
@@ -140,26 +140,24 @@ fun KotlinFacet.configureFacet(
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
// Update these lists when facet/project settings UI changes
val commonUIExposedFields = listOf("languageVersion",
"apiVersion",
"suppressWarnings",
"coroutinesEnable",
"coroutinesWarn",
"coroutinesError")
private val commonUIHiddenFields = listOf("pluginClasspaths",
"pluginOptions")
val commonUIExposedFields = listOf(CommonCompilerArguments::languageVersion.name,
CommonCompilerArguments::apiVersion.name,
CommonCompilerArguments::suppressWarnings.name,
CommonCompilerArguments::coroutinesState.name)
private val commonUIHiddenFields = listOf(CommonCompilerArguments::pluginClasspaths.name,
CommonCompilerArguments::pluginOptions.name)
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
private val jvmSpecificUIExposedFields = listOf("jvmTarget",
"destination",
"classpath")
private val jvmSpecificUIExposedFields = listOf(K2JVMCompilerArguments::jvmTarget.name,
K2JVMCompilerArguments::destination.name,
K2JVMCompilerArguments::classpath.name)
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
private val jsSpecificUIExposedFields = listOf("sourceMap",
"outputPrefix",
"outputPostfix",
"moduleKind")
private val jsSpecificUIExposedFields = listOf(K2JSCompilerArguments::sourceMap.name,
K2JSCompilerArguments::outputPrefix.name,
K2JSCompilerArguments::outputPostfix.name,
K2JSCompilerArguments::moduleKind.name)
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
@@ -180,18 +178,10 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
parseArguments(defaultArguments.toTypedArray(), defaultCompilerArguments, true)
defaultCompilerArguments.convertPathsToSystemIndependent()
val oldCoroutineSupport = CoroutineSupport.byCompilerArguments(compilerArguments)
compilerArguments.coroutinesEnable = false
compilerArguments.coroutinesWarn = false
compilerArguments.coroutinesError = false
parseArguments(argumentArray, compilerArguments, true)
compilerArguments.convertPathsToSystemIndependent()
val restoreCoroutineSupport =
!compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError
// Retain only fields exposed in facet configuration editor.
// The rest is combined into string and stored in CompilerSettings.additionalArguments
@@ -213,9 +203,5 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(this, compilerArguments, ::exposeAsAdditionalArgument)
}
if (restoreCoroutineSupport) {
coroutineSupport = oldCoroutineSupport
}
}
}
}
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.ex.ProjectRootManagerEx
import com.intellij.openapi.ui.Messages
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.CoroutineSupport
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.LanguageFeature
@@ -95,10 +96,11 @@ sealed class ChangeCoroutineSupportFix(
}
KotlinCommonCompilerArgumentsHolder.getInstance(project).update {
coroutinesEnable = coroutineSupport == LanguageFeature.State.ENABLED
coroutinesWarn = coroutineSupport == LanguageFeature.State.ENABLED_WITH_WARNING
coroutinesError = coroutineSupport == LanguageFeature.State.ENABLED_WITH_ERROR ||
coroutineSupport == LanguageFeature.State.DISABLED
coroutinesState = when (coroutineSupport) {
LanguageFeature.State.ENABLED -> CommonCompilerArguments.ENABLE
LanguageFeature.State.ENABLED_WITH_WARNING -> CommonCompilerArguments.WARN
LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> CommonCompilerArguments.ERROR
}
}
ProjectRootManagerEx.getInstanceEx(project).makeRootsChange({}, false, true)
}
@@ -17,8 +17,9 @@
<compilerArguments>
<option name="moduleKind" value="amd" />
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.0" />
<option name="coroutinesWarn" value="true" />
<option name="apiVersion" value="1.0" />
<option name="coroutinesWarn" value="false" />
<option name="coroutinesError" value="true" />
</compilerArguments>
</configuration>
</facet>
@@ -19,7 +19,7 @@
<option name="jvmTarget" value="1.7" />
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.0" />
<option name="coroutinesWarn" value="true" />
<option name="coroutinesEnable" value="true" />
</compilerArguments>
</configuration>
</facet>
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
</component>
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="3" platform="JVM 1.8" useProjectSettings="false">
<compilerSettings>
<option name="additionalArguments" value="-version -Xallow-kotlin-package -Xskip-metadata-version-check" />
</compilerSettings>
<compilerArguments>
<option name="jvmTarget" value="1.7" />
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.0" />
<option name="coroutinesState" value="enable" />
</compilerArguments>
</configuration>
</facet>
</component>
</module>
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
<component name="CopyrightManager" default="" />
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/module.iml" filepath="$PROJECT_DIR$/module.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="libraryTable">
<library name="KotlinJavaRuntime (2)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../mockRuntime11/kotlin-runtime.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
</SOURCES>
</library>
</component>
</project>
@@ -197,54 +197,6 @@ class GradleFacetImportTest : GradleImportingTestCase() {
}
}
@Test
fun testFixCorruptedCoroutines() {
createProjectSubFile("build.gradle", """
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1'
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
}
}
apply plugin: 'kotlin'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0"
}
kotlin {
experimental {
coroutines 'enable'
}
}
""")
importProject()
with (facetSettings) {
compilerArguments!!.coroutinesEnable = true
compilerArguments!!.coroutinesWarn = true
compilerArguments!!.coroutinesError = true
importProject()
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals(true, compilerArguments!!.coroutinesEnable)
Assert.assertEquals(false, compilerArguments!!.coroutinesWarn)
Assert.assertEquals(false, compilerArguments!!.coroutinesError)
}
}
@Test
fun testCoroutineImportByProperties() {
createProjectSubFile("gradle.properties", "kotlin.coroutines=enable")
@@ -195,7 +195,7 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind());
assertEquals("1.1", arguments.languageVersion);
assertEquals("1.0", arguments.apiVersion);
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.jvmTarget);
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().additionalArguments);
}
@@ -210,11 +210,26 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
assertEquals(TargetPlatformKind.JavaScript.INSTANCE, settings.getTargetPlatformKind());
assertEquals("1.1", arguments.languageVersion);
assertEquals("1.0", arguments.apiVersion);
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, CoroutineSupport.byCompilerArguments(arguments));
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("amd", arguments.moduleKind);
assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments);
}
@SuppressWarnings("ConstantConditions")
public void testJvmProjectWithV3FacetConfig() {
KotlinFacetSettings settings = KotlinFacetSettingsProvider.Companion.getInstance(myProject).getInitializedSettings(getModule());
K2JVMCompilerArguments arguments = (K2JVMCompilerArguments) settings.getCompilerArguments();
assertEquals(false, settings.getUseProjectSettings());
assertEquals("1.1", settings.getLanguageLevel().getDescription());
assertEquals("1.0", settings.getApiLevel().getDescription());
assertEquals(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind());
assertEquals("1.1", arguments.languageVersion);
assertEquals("1.0", arguments.apiVersion);
assertEquals(LanguageFeature.State.ENABLED, CoroutineSupport.byCompilerArguments(arguments));
assertEquals("1.7", arguments.jvmTarget);
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().additionalArguments);
}
private void configureFacetAndCheckJvm(JvmTarget jvmTarget) {
IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
try {
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
@@ -43,7 +44,7 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
resetProjectSettings(LanguageVersion.KOTLIN_1_1)
myFixture.configureByText("foo.kt", "suspend fun foo()")
assertFalse(KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.coroutinesEnable)
assertEquals(CommonCompilerArguments.WARN, KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.coroutinesState)
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, coroutineSupport)
myFixture.launchAction(myFixture.findSingleIntention("Enable coroutine support in the project"))
assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
@@ -54,7 +55,7 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
resetProjectSettings(LanguageVersion.KOTLIN_1_1)
myFixture.configureByText("foo.kt", "suspend fun foo()")
assertFalse(KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.coroutinesEnable)
assertEquals(CommonCompilerArguments.WARN, KotlinCommonCompilerArgumentsHolder.getInstance(project).settings.coroutinesState)
assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, coroutineSupport)
myFixture.launchAction(myFixture.findSingleIntention("Disable coroutine support in the project"))
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, coroutineSupport)
@@ -161,15 +162,13 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
ConfigLibraryUtil.addLibrary(editor, model)
}
}
}
private fun resetProjectSettings(version: LanguageVersion) {
KotlinCommonCompilerArgumentsHolder.getInstance(project).update {
languageVersion = version.versionString
apiVersion = version.versionString
coroutinesEnable = false
coroutinesWarn = true
coroutinesError = false
coroutinesState = CommonCompilerArguments.WARN
}
}