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, compilerBuildVersion = KotlinCompilerVersion.VERSION,
languageVersionString = args.languageVersion ?: LanguageVersion.LATEST_STABLE.versionString, languageVersionString = args.languageVersion ?: LanguageVersion.LATEST_STABLE.versionString,
apiVersionString = args.apiVersion ?: ApiVersion.LATEST_STABLE.versionString, apiVersionString = args.apiVersion ?: ApiVersion.LATEST_STABLE.versionString,
coroutinesEnable = args.coroutinesEnable, coroutinesEnable = args.coroutinesState == CommonCompilerArguments.ENABLE,
coroutinesWarn = args.coroutinesWarn, coroutinesWarn = args.coroutinesState == CommonCompilerArguments.WARN,
coroutinesError = args.coroutinesError, coroutinesError = args.coroutinesState == CommonCompilerArguments.ERROR,
multiplatformEnable = args.multiPlatform, multiplatformEnable = args.multiPlatform,
metadataVersionMajor = JvmMetadataVersion.INSTANCE.major, metadataVersionMajor = JvmMetadataVersion.INSTANCE.major,
metadataVersionMinor = JvmMetadataVersion.INSTANCE.minor, metadataVersionMinor = JvmMetadataVersion.INSTANCE.minor,
metadataVersionPatch = JvmMetadataVersion.INSTANCE.patch, metadataVersionPatch = JvmMetadataVersion.INSTANCE.patch,
bytecodeVersionMajor = JvmBytecodeBinaryVersion.INSTANCE.major, bytecodeVersionMajor = JvmBytecodeBinaryVersion.INSTANCE.major,
bytecodeVersionMinor = JvmBytecodeBinaryVersion.INSTANCE.minor, bytecodeVersionMinor = JvmBytecodeBinaryVersion.INSTANCE.minor,
bytecodeVersionPatch = JvmBytecodeBinaryVersion.INSTANCE.patch) bytecodeVersionPatch = JvmBytecodeBinaryVersion.INSTANCE.patch)
@@ -17,10 +17,8 @@
package org.jetbrains.kotlin.build package org.jetbrains.kotlin.build
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments 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.Assert.assertNotEquals
import org.junit.Test import org.junit.Test
@@ -64,14 +62,14 @@ class JvmBuildMetaInfoTest : TestCase() {
@Test @Test
fun testEquals() { fun testEquals() {
val args1 = K2JVMCompilerArguments() val args1 = K2JVMCompilerArguments()
args1.coroutinesEnable = true args1.coroutinesState = CommonCompilerArguments.ENABLE
val info1 = JvmBuildMetaInfo(args1) val info1 = JvmBuildMetaInfo(args1)
val args2 = K2JVMCompilerArguments() val args2 = K2JVMCompilerArguments()
args2.coroutinesEnable = false args2.coroutinesState = CommonCompilerArguments.WARN
val info2 = JvmBuildMetaInfo(args2) val info2 = JvmBuildMetaInfo(args2)
assertNotEquals(info1, info2) 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") @Argument(value = "-Xno-check-impl", description = "Do not check presence of 'impl' modifier in multi-platform projects")
public boolean noCheckImpl; public boolean noCheckImpl;
@Argument(value = "-Xcoroutines=warn", description = "") @Argument(
public boolean coroutinesWarn; value = "-Xcoroutines",
valueDescription = "{enable|warn|error}",
@Argument(value = "-Xcoroutines=error", description = "") description = "Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier"
public boolean coroutinesError; )
public String coroutinesState = WARN;
@Argument(value = "-Xcoroutines=enable", description = "")
public boolean coroutinesEnable;
public List<String> freeArgs = new SmartList<>(); public List<String> freeArgs = new SmartList<>();
@@ -109,11 +107,7 @@ public abstract class CommonCompilerArguments implements Serializable {
@NotNull @NotNull
public static CommonCompilerArguments createDefaultInstance() { public static CommonCompilerArguments createDefaultInstance() {
DummyImpl arguments = new DummyImpl(); return new DummyImpl();
arguments.coroutinesEnable = false;
arguments.coroutinesWarn = true;
arguments.coroutinesError = false;
return arguments;
} }
@NotNull @NotNull
@@ -121,6 +115,10 @@ public abstract class CommonCompilerArguments implements Serializable {
return "kotlinc"; 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! // Used only for serialize and deserialize settings. Don't use in other places!
public static final class DummyImpl extends CommonCompilerArguments {} public static final class DummyImpl extends CommonCompilerArguments {}
} }
@@ -275,19 +275,17 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull CompilerConfiguration configuration, @NotNull CompilerConfiguration configuration,
@NotNull CommonCompilerArguments arguments @NotNull CommonCompilerArguments arguments
) { ) {
if (arguments.coroutinesError && !arguments.coroutinesWarn && !arguments.coroutinesEnable) { switch (arguments.coroutinesState) {
return LanguageFeature.State.ENABLED_WITH_ERROR; case CommonCompilerArguments.ERROR:
} return LanguageFeature.State.ENABLED_WITH_ERROR;
else if (arguments.coroutinesEnable && !arguments.coroutinesWarn && !arguments.coroutinesError) { case CommonCompilerArguments.ENABLE:
return LanguageFeature.State.ENABLED; return LanguageFeature.State.ENABLED;
} case CommonCompilerArguments.WARN:
else if (!arguments.coroutinesEnable && !arguments.coroutinesError) { return null;
return null; default:
} String message = "Invalid value of -Xcoroutines (should be: enable, warn or error): " + arguments.coroutinesState;
else { configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
String message = "The -Xcoroutines can only have one value"; return null;
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 // 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 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) { public static void print(@NotNull PrintStream target, @NotNull CommonCompilerArguments arguments, boolean extraHelp) {
target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>"); target.println("Usage: " + arguments.executableScriptFileName() + " <options> <source files>");
target.println("where " + (extraHelp ? "advanced" : "possible") + " options include:"); target.println("where " + (extraHelp ? "advanced" : "possible") + " options include:");
boolean coroutinesUsagePrinted = false;
for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) { for (Class<?> clazz = arguments.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
for (Field field : clazz.getDeclaredFields()) { for (Field field : clazz.getDeclaredFields()) {
String usage = fieldUsage(field, extraHelp); String usage = fieldUsage(field, extraHelp);
if (usage != null) { if (usage != null) {
if (usage.contains("Xcoroutines")) {
if (coroutinesUsagePrinted) continue;
coroutinesUsagePrinted = true;
}
target.println(usage); target.println(usage);
} }
} }
@@ -59,14 +52,10 @@ class Usage {
Argument argument = field.getAnnotation(Argument.class); Argument argument = field.getAnnotation(Argument.class);
if (argument == null) return null; 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; if (extraHelp != ParseCommandLineArgumentsKt.isAdvanced(argument)) return null;
StringBuilder sb = new StringBuilder(" "); StringBuilder sb = new StringBuilder(" ");
sb.append(value); sb.append(argument.value());
if (!argument.shortName().isEmpty()) { if (!argument.shortName().isEmpty()) {
sb.append(" ("); sb.append(" (");
@@ -79,12 +68,6 @@ class Usage {
sb.append(argument.valueDescription()); sb.append(argument.valueDescription());
} }
if (isXCoroutinesKey) {
sb.append(" ");
sb.append(coroutinesKeyDescription);
return sb.toString();
}
int width = OPTION_NAME_PADDING_WIDTH - 1; int width = OPTION_NAME_PADDING_WIDTH - 1;
if (sb.length() >= width + 5) { // Break the line if it's too long if (sb.length() >= width + 5) { // Break the line if it's too long
sb.append("\n"); sb.append("\n");
+2 -1
View File
@@ -8,7 +8,8 @@ where advanced options include:
-Xplugin=<path> Load plugins from the given classpath -Xplugin=<path> Load plugins from the given classpath
-Xmulti-platform Enable experimental language support for multi-platform projects -Xmulti-platform Enable experimental language support for multi-platform projects
-Xno-check-impl Do not check presence of 'impl' modifier in 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. Advanced options are non-standard and may be changed or removed without any notice.
OK OK
+2 -1
View File
@@ -20,7 +20,8 @@ where advanced options include:
-Xplugin=<path> Load plugins from the given classpath -Xplugin=<path> Load plugins from the given classpath
-Xmulti-platform Enable experimental language support for multi-platform projects -Xmulti-platform Enable experimental language support for multi-platform projects
-Xno-check-impl Do not check presence of 'impl' modifier in 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. Advanced options are non-standard and may be changed or removed without any notice.
OK OK
@@ -55,11 +55,10 @@ object CoroutineSupport {
fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State = fun byCompilerArguments(arguments: CommonCompilerArguments?): LanguageFeature.State =
byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState byCompilerArgumentsOrNull(arguments) ?: LanguageFeature.Coroutines.defaultState
fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when { fun byCompilerArgumentsOrNull(arguments: CommonCompilerArguments?): LanguageFeature.State? = when (arguments?.coroutinesState) {
arguments == null -> null CommonCompilerArguments.ENABLE -> LanguageFeature.State.ENABLED
arguments.coroutinesEnable -> LanguageFeature.State.ENABLED CommonCompilerArguments.WARN -> LanguageFeature.State.ENABLED_WITH_WARNING
arguments.coroutinesWarn -> LanguageFeature.State.ENABLED_WITH_WARNING CommonCompilerArguments.ERROR -> LanguageFeature.State.ENABLED_WITH_ERROR
arguments.coroutinesError -> LanguageFeature.State.ENABLED_WITH_ERROR
else -> null else -> null
} }
@@ -77,7 +76,7 @@ object CoroutineSupport {
class KotlinFacetSettings { class KotlinFacetSettings {
companion object { companion object {
// Increment this when making serialization-incompatible changes to configuration data // Increment this when making serialization-incompatible changes to configuration data
val CURRENT_VERSION = 2 val CURRENT_VERSION = 3
val DEFAULT_VERSION = 0 val DEFAULT_VERSION = 0
} }
@@ -118,10 +117,10 @@ class KotlinFacetSettings {
return CoroutineSupport.byCompilerArguments(compilerArguments) return CoroutineSupport.byCompilerArguments(compilerArguments)
} }
set(value) { set(value) {
with(compilerArguments!!) { compilerArguments!!.coroutinesState = when (value) {
coroutinesEnable = value == LanguageFeature.State.ENABLED LanguageFeature.State.ENABLED -> CommonCompilerArguments.ENABLE
coroutinesWarn = value == LanguageFeature.State.ENABLED_WITH_WARNING LanguageFeature.State.ENABLED_WITH_WARNING -> CommonCompilerArguments.WARN
coroutinesError = value == LanguageFeature.State.ENABLED_WITH_ERROR || value == LanguageFeature.State.DISABLED 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 { return KotlinFacetSettings().apply {
element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() } element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() }
val platformName = element.getAttributeValue("platform") 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 { fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
val version = val version =
try { try {
@@ -112,6 +131,7 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
return when (version) { return when (version) {
1 -> readV1Config(element) 1 -> readV1Config(element)
2 -> readV2Config(element) 2 -> readV2Config(element)
KotlinFacetSettings.CURRENT_VERSION -> readLatestConfig(element)
else -> KotlinFacetSettings() // Reset facet configuration if versions don't match 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.suppressWarnings = !reportWarningsCheckBox.isSelected();
commonCompilerArguments.languageVersion = getSelectedLanguageVersion().getVersionString(); commonCompilerArguments.languageVersion = getSelectedLanguageVersion().getVersionString();
commonCompilerArguments.apiVersion = getSelectedAPIVersion().getVersionString(); commonCompilerArguments.apiVersion = getSelectedAPIVersion().getVersionString();
LanguageFeature.State coroutineSupport = (LanguageFeature.State) coroutineSupportComboBox.getSelectedItem();
commonCompilerArguments.coroutinesEnable = coroutineSupport == LanguageFeature.State.ENABLED; switch ((LanguageFeature.State) coroutineSupportComboBox.getSelectedItem()) {
commonCompilerArguments.coroutinesWarn = coroutineSupport == LanguageFeature.State.ENABLED_WITH_WARNING; case ENABLED:
commonCompilerArguments.coroutinesError = coroutineSupport == LanguageFeature.State.ENABLED_WITH_ERROR || commonCompilerArguments.coroutinesState = CommonCompilerArguments.ENABLE;
coroutineSupport == LanguageFeature.State.DISABLED; 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.additionalArguments = additionalArgsOptionsField.getText();
compilerSettings.scriptTemplates = scriptTemplatesField.getText(); compilerSettings.scriptTemplates = scriptTemplatesField.getText();
compilerSettings.scriptTemplatesClasspath = scriptTemplatesClasspathField.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 // "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 // Update these lists when facet/project settings UI changes
val commonUIExposedFields = listOf("languageVersion", val commonUIExposedFields = listOf(CommonCompilerArguments::languageVersion.name,
"apiVersion", CommonCompilerArguments::apiVersion.name,
"suppressWarnings", CommonCompilerArguments::suppressWarnings.name,
"coroutinesEnable", CommonCompilerArguments::coroutinesState.name)
"coroutinesWarn", private val commonUIHiddenFields = listOf(CommonCompilerArguments::pluginClasspaths.name,
"coroutinesError") CommonCompilerArguments::pluginOptions.name)
private val commonUIHiddenFields = listOf("pluginClasspaths",
"pluginOptions")
private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields private val commonPrimaryFields = commonUIExposedFields + commonUIHiddenFields
private val jvmSpecificUIExposedFields = listOf("jvmTarget", private val jvmSpecificUIExposedFields = listOf(K2JVMCompilerArguments::jvmTarget.name,
"destination", K2JVMCompilerArguments::destination.name,
"classpath") K2JVMCompilerArguments::classpath.name)
val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields val jvmUIExposedFields = commonUIExposedFields + jvmSpecificUIExposedFields
private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields private val jvmPrimaryFields = commonPrimaryFields + jvmSpecificUIExposedFields
private val jsSpecificUIExposedFields = listOf("sourceMap", private val jsSpecificUIExposedFields = listOf(K2JSCompilerArguments::sourceMap.name,
"outputPrefix", K2JSCompilerArguments::outputPrefix.name,
"outputPostfix", K2JSCompilerArguments::outputPostfix.name,
"moduleKind") K2JSCompilerArguments::moduleKind.name)
val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields val jsUIExposedFields = commonUIExposedFields + jsSpecificUIExposedFields
private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields private val jsPrimaryFields = commonPrimaryFields + jsSpecificUIExposedFields
@@ -180,18 +178,10 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
parseArguments(defaultArguments.toTypedArray(), defaultCompilerArguments, true) parseArguments(defaultArguments.toTypedArray(), defaultCompilerArguments, true)
defaultCompilerArguments.convertPathsToSystemIndependent() defaultCompilerArguments.convertPathsToSystemIndependent()
val oldCoroutineSupport = CoroutineSupport.byCompilerArguments(compilerArguments)
compilerArguments.coroutinesEnable = false
compilerArguments.coroutinesWarn = false
compilerArguments.coroutinesError = false
parseArguments(argumentArray, compilerArguments, true) parseArguments(argumentArray, compilerArguments, true)
compilerArguments.convertPathsToSystemIndependent() compilerArguments.convertPathsToSystemIndependent()
val restoreCoroutineSupport =
!compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError
// Retain only fields exposed in facet configuration editor. // Retain only fields exposed in facet configuration editor.
// The rest is combined into string and stored in CompilerSettings.additionalArguments // 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()) { with(compilerArguments::class.java.newInstance()) {
copyFieldsSatisfying(this, compilerArguments, ::exposeAsAdditionalArgument) 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.roots.ex.ProjectRootManagerEx
import com.intellij.openapi.ui.Messages import com.intellij.openapi.ui.Messages
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.config.CoroutineSupport import org.jetbrains.kotlin.config.CoroutineSupport
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageFeature
@@ -95,10 +96,11 @@ sealed class ChangeCoroutineSupportFix(
} }
KotlinCommonCompilerArgumentsHolder.getInstance(project).update { KotlinCommonCompilerArgumentsHolder.getInstance(project).update {
coroutinesEnable = coroutineSupport == LanguageFeature.State.ENABLED coroutinesState = when (coroutineSupport) {
coroutinesWarn = coroutineSupport == LanguageFeature.State.ENABLED_WITH_WARNING LanguageFeature.State.ENABLED -> CommonCompilerArguments.ENABLE
coroutinesError = coroutineSupport == LanguageFeature.State.ENABLED_WITH_ERROR || LanguageFeature.State.ENABLED_WITH_WARNING -> CommonCompilerArguments.WARN
coroutineSupport == LanguageFeature.State.DISABLED LanguageFeature.State.ENABLED_WITH_ERROR, LanguageFeature.State.DISABLED -> CommonCompilerArguments.ERROR
}
} }
ProjectRootManagerEx.getInstanceEx(project).makeRootsChange({}, false, true) ProjectRootManagerEx.getInstanceEx(project).makeRootsChange({}, false, true)
} }
@@ -17,8 +17,9 @@
<compilerArguments> <compilerArguments>
<option name="moduleKind" value="amd" /> <option name="moduleKind" value="amd" />
<option name="languageVersion" value="1.1" /> <option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.0" /> <option name="apiVersion" value="1.0" />
<option name="coroutinesWarn" value="true" /> <option name="coroutinesWarn" value="false" />
<option name="coroutinesError" value="true" />
</compilerArguments> </compilerArguments>
</configuration> </configuration>
</facet> </facet>
@@ -19,7 +19,7 @@
<option name="jvmTarget" value="1.7" /> <option name="jvmTarget" value="1.7" />
<option name="languageVersion" value="1.1" /> <option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.0" /> <option name="apiVersion" value="1.0" />
<option name="coroutinesWarn" value="true" /> <option name="coroutinesEnable" value="true" />
</compilerArguments> </compilerArguments>
</configuration> </configuration>
</facet> </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 @Test
fun testCoroutineImportByProperties() { fun testCoroutineImportByProperties() {
createProjectSubFile("gradle.properties", "kotlin.coroutines=enable") 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(TargetPlatformKind.Jvm.Companion.get(JvmTarget.JVM_1_8), settings.getTargetPlatformKind());
assertEquals("1.1", arguments.languageVersion); assertEquals("1.1", arguments.languageVersion);
assertEquals("1.0", arguments.apiVersion); 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("1.7", arguments.jvmTarget);
assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.getCompilerSettings().additionalArguments); 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(TargetPlatformKind.JavaScript.INSTANCE, settings.getTargetPlatformKind());
assertEquals("1.1", arguments.languageVersion); assertEquals("1.1", arguments.languageVersion);
assertEquals("1.0", arguments.apiVersion); 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("amd", arguments.moduleKind);
assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments); 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) { private void configureFacetAndCheckJvm(JvmTarget jvmTarget) {
IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject()); IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
try { try {
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.JarFileSystem import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase 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.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersion import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder import org.jetbrains.kotlin.idea.compiler.configuration.KotlinCommonCompilerArgumentsHolder
@@ -43,7 +44,7 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
resetProjectSettings(LanguageVersion.KOTLIN_1_1) resetProjectSettings(LanguageVersion.KOTLIN_1_1)
myFixture.configureByText("foo.kt", "suspend fun foo()") 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) assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, coroutineSupport)
myFixture.launchAction(myFixture.findSingleIntention("Enable coroutine support in the project")) myFixture.launchAction(myFixture.findSingleIntention("Enable coroutine support in the project"))
assertEquals(LanguageFeature.State.ENABLED, coroutineSupport) assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
@@ -54,7 +55,7 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
resetProjectSettings(LanguageVersion.KOTLIN_1_1) resetProjectSettings(LanguageVersion.KOTLIN_1_1)
myFixture.configureByText("foo.kt", "suspend fun foo()") 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) assertEquals(LanguageFeature.State.ENABLED_WITH_WARNING, coroutineSupport)
myFixture.launchAction(myFixture.findSingleIntention("Disable coroutine support in the project")) myFixture.launchAction(myFixture.findSingleIntention("Disable coroutine support in the project"))
assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, coroutineSupport) assertEquals(LanguageFeature.State.ENABLED_WITH_ERROR, coroutineSupport)
@@ -161,15 +162,13 @@ class LanguageFeatureQuickFixTest : LightPlatformCodeInsightFixtureTestCase() {
ConfigLibraryUtil.addLibrary(editor, model) ConfigLibraryUtil.addLibrary(editor, model)
} }
} }
private fun resetProjectSettings(version: LanguageVersion) { private fun resetProjectSettings(version: LanguageVersion) {
KotlinCommonCompilerArgumentsHolder.getInstance(project).update { KotlinCommonCompilerArgumentsHolder.getInstance(project).update {
languageVersion = version.versionString languageVersion = version.versionString
apiVersion = version.versionString apiVersion = version.versionString
coroutinesEnable = false coroutinesState = CommonCompilerArguments.WARN
coroutinesWarn = true
coroutinesError = false
} }
} }