diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 405985ccc6a..4ffa0c7ec13 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.cli.common.arguments +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.AnalysisFlag import java.util.* @@ -105,7 +106,7 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var coroutinesState: String? by FreezableVar(WARN) - open fun configureAnalysisFlags(): MutableMap, Any> { + open fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { return HashMap, Any>().apply { put(AnalysisFlag.skipMetadataVersionCheck, skipMetadataVersionCheck) put(AnalysisFlag.multiPlatformDoNotCheckImpl, noCheckImpl) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 0e4e47854bf..e5cdd88c0dc 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -16,6 +16,8 @@ package org.jetbrains.kotlin.cli.common.arguments +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.AnalysisFlag import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.utils.Jsr305State @@ -162,6 +164,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @Argument( value = "-Xjsr305", + deprecatedName = "-Xjsr305-annotations", valueDescription = "{ignore|strict|warn}", description = "Specify global behavior for JSR-305 nullability annotations: ignore, treat as other supported nullability annotations, or report a warning" ) @@ -176,11 +179,22 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { // Paths to output directories for friend modules. var friendPaths: Array? by FreezableVar(null) - override fun configureAnalysisFlags(): MutableMap, Any> { - val result = super.configureAnalysisFlags() - Jsr305State.findByDescription(jsr305)?.let { - result.put(AnalysisFlag.jsr305, it) + override fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { + val result = super.configureAnalysisFlags(collector) + + if (jsr305 == "enable") { + collector.report( + CompilerMessageSeverity.STRONG_WARNING, + "Option 'enable' for -Xjsr305 flag is deprecated. Please use 'strict' instead" + ) + result.put(AnalysisFlag.jsr305, Jsr305State.STRICT) } + else { + Jsr305State.findByDescription(jsr305)?.let { + result.put(AnalysisFlag.jsr305, it) + } + } + return result } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java index 503a57be778..ae946c6fefe 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/CLICompiler.java @@ -202,7 +202,7 @@ public abstract class CLICompiler extends CLI CommonConfigurationKeysKt.setLanguageVersionSettings(configuration, new LanguageVersionSettingsImpl( languageVersion, ApiVersion.createByLanguageVersion(apiVersion), - arguments.configureAnalysisFlags(), + arguments.configureAnalysisFlags(configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)), extraLanguageFeatures )); } diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedEnable.args b/compiler/testData/cli/jvm/jsr305DeprecatedEnable.args new file mode 100644 index 00000000000..2b15582951a --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DeprecatedEnable.args @@ -0,0 +1,5 @@ +-Xjsr305-annotations=enable +$TESTDATA_DIR$/jsr305Usage.kt +$TESTDATA_DIR$/jsr305 +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedEnable.out b/compiler/testData/cli/jvm/jsr305DeprecatedEnable.out new file mode 100644 index 00000000000..92e0065ef5b --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DeprecatedEnable.out @@ -0,0 +1,6 @@ +warning: argument -Xjsr305-annotations is deprecated. Please use -Xjsr305 instead +warning: option 'enable' for -Xjsr305 flag is deprecated. Please use 'strict' instead +compiler/testData/cli/jvm/jsr305Usage.kt:2:11: error: null can not be a value of a non-null type String + a.foo(null) + ^ +COMPILATION_ERROR diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedIgnore.args b/compiler/testData/cli/jvm/jsr305DeprecatedIgnore.args new file mode 100644 index 00000000000..b28e65bea4a --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DeprecatedIgnore.args @@ -0,0 +1,5 @@ +-Xjsr305-annotations=ignore +$TESTDATA_DIR$/jsr305Usage.kt +$TESTDATA_DIR$/jsr305 +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedIgnore.out b/compiler/testData/cli/jvm/jsr305DeprecatedIgnore.out new file mode 100644 index 00000000000..585f9b69881 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DeprecatedIgnore.out @@ -0,0 +1,2 @@ +warning: argument -Xjsr305-annotations is deprecated. Please use -Xjsr305 instead +OK diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedWarn.args b/compiler/testData/cli/jvm/jsr305DeprecatedWarn.args new file mode 100644 index 00000000000..534f4c6b8ef --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DeprecatedWarn.args @@ -0,0 +1,5 @@ +-Xjsr305-annotations=warn +$TESTDATA_DIR$/jsr305Usage.kt +$TESTDATA_DIR$/jsr305 +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out b/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out new file mode 100644 index 00000000000..d0956f6dc72 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out @@ -0,0 +1,5 @@ +warning: argument -Xjsr305-annotations is deprecated. Please use -Xjsr305 instead +compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin + a.foo(null) + ^ +OK diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 09e39f26771..07a2786ecd3 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -218,6 +218,24 @@ public class CliTestGenerated extends AbstractCliTest { doJvmTest(fileName); } + @TestMetadata("jsr305DeprecatedEnable.args") + public void testJsr305DeprecatedEnable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305DeprecatedEnable.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305DeprecatedIgnore.args") + public void testJsr305DeprecatedIgnore() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305DeprecatedIgnore.args"); + doJvmTest(fileName); + } + + @TestMetadata("jsr305DeprecatedWarn.args") + public void testJsr305DeprecatedWarn() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305DeprecatedWarn.args"); + doJvmTest(fileName); + } + @TestMetadata("jsr305Ignore.args") public void testJsr305Ignore() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jsr305Ignore.args"); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt index b5ed94666b1..8e140ee3518 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/Platform.kt @@ -25,6 +25,7 @@ import com.intellij.openapi.roots.ProjectFileIndex import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.cli.common.arguments.Argument import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.compiler.configuration.Kotlin2JvmCompilerArgumentsHolder @@ -90,7 +91,7 @@ fun Project.getLanguageVersionSettings(contextModule: Module? = null, null ) return LanguageVersionSettingsImpl(languageVersion, apiVersion, - arguments.configureAnalysisFlags() + extraAnalysisFlags, + arguments.configureAnalysisFlags(MessageCollector.NONE) + extraAnalysisFlags, extraLanguageFeatures) } @@ -113,7 +114,7 @@ val Module.languageVersionSettings: LanguageVersionSettings return LanguageVersionSettingsImpl( languageVersion, ApiVersion.createByLanguageVersion(apiVersion), - facetSettings.mergedCompilerArguments?.configureAnalysisFlags().orEmpty(), + facetSettings.mergedCompilerArguments?.configureAnalysisFlags(MessageCollector.NONE).orEmpty(), extraLanguageFeatures ) }