Change -Xload-jsr305-annotations argument to -Xjsr305-annotations={ignore|enable}
See https://youtrack.jetbrains.com/issue/KT-19229 for a complete explanation #KT-19229 Fixed #KT-10942
This commit is contained in:
+13
-3
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.cli.common.arguments;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.config.AnalysisFlag;
|
import org.jetbrains.kotlin.config.AnalysisFlag;
|
||||||
|
import org.jetbrains.kotlin.config.Jsr305State;
|
||||||
import org.jetbrains.kotlin.config.JvmTarget;
|
import org.jetbrains.kotlin.config.JvmTarget;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -162,8 +163,12 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
|||||||
description = "Java compiler arguments")
|
description = "Java compiler arguments")
|
||||||
public String[] javacArguments;
|
public String[] javacArguments;
|
||||||
|
|
||||||
@Argument(value = "-Xload-jsr305-annotations", description = "Load JSR-305 nullability annotations")
|
@Argument(
|
||||||
public boolean loadJsr305annotations;
|
value = "-Xjsr305-annotations",
|
||||||
|
valueDescription = "{ignore|enable}",
|
||||||
|
description = "Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations"
|
||||||
|
)
|
||||||
|
public String jsr305GlobalReportLevel = Jsr305State.DEFAULT.getDescription();
|
||||||
|
|
||||||
// Paths to output directories for friend modules.
|
// Paths to output directories for friend modules.
|
||||||
public String[] friendPaths;
|
public String[] friendPaths;
|
||||||
@@ -172,7 +177,12 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public Map<AnalysisFlag<?>, Object> configureAnalysisFlags() {
|
public Map<AnalysisFlag<?>, Object> configureAnalysisFlags() {
|
||||||
Map<AnalysisFlag<?>, Object> result = super.configureAnalysisFlags();
|
Map<AnalysisFlag<?>, Object> result = super.configureAnalysisFlags();
|
||||||
result.put(AnalysisFlag.getLoadJsr305Annotations(), loadJsr305annotations);
|
for (Jsr305State state : Jsr305State.values()) {
|
||||||
|
if (state.getDescription().equals(jsr305GlobalReportLevel)) {
|
||||||
|
result.put(AnalysisFlag.getLoadJsr305Annotations(), state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ fun createContainerForLazyResolveWithJava(
|
|||||||
|
|
||||||
useInstance(languageVersionSettings)
|
useInstance(languageVersionSettings)
|
||||||
|
|
||||||
if (languageVersionSettings.getFlag(AnalysisFlag.loadJsr305Annotations)) {
|
if (languageVersionSettings.getFlag(AnalysisFlag.loadJsr305Annotations).shouldReportError) {
|
||||||
useImpl<AnnotationTypeQualifierResolverImpl>()
|
useImpl<AnnotationTypeQualifierResolverImpl>()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@ where advanced options include:
|
|||||||
Script resolver environment in key-value pairs (the value could be quoted and escaped)
|
Script resolver environment in key-value pairs (the value could be quoted and escaped)
|
||||||
-Xuse-javac Use javac for Java source and class files analysis
|
-Xuse-javac Use javac for Java source and class files analysis
|
||||||
-Xjavac-arguments=<option[,]> Java compiler arguments
|
-Xjavac-arguments=<option[,]> Java compiler arguments
|
||||||
-Xload-jsr305-annotations Load JSR-305 nullability annotations
|
-Xjsr305-annotations={ignore|enable}
|
||||||
|
Specify global behavior for JSR-305 nullability annotations: ignore, or treat as other supported nullability annotations
|
||||||
-Xno-inline Disable method inlining
|
-Xno-inline Disable method inlining
|
||||||
-Xrepeat=<count> Repeat compilation (for performance analysis)
|
-Xrepeat=<count> Repeat compilation (for performance analysis)
|
||||||
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
|
-Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes)
|
||||||
|
|||||||
@@ -31,5 +31,5 @@ abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsWithFullJdkTe
|
|||||||
|
|
||||||
override fun loadLanguageVersionSettings(module: List<TestFile>): LanguageVersionSettings =
|
override fun loadLanguageVersionSettings(module: List<TestFile>): LanguageVersionSettings =
|
||||||
LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE,
|
LanguageVersionSettingsImpl(LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE,
|
||||||
mapOf(AnalysisFlag.loadJsr305Annotations to true))
|
mapOf(AnalysisFlag.loadJsr305Annotations to Jsr305State.ENABLE))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class LoadJavaPackageAnnotationsTest : KtUsefulTestCase() {
|
|||||||
put(JVMConfigurationKeys.USE_JAVAC, true)
|
put(JVMConfigurationKeys.USE_JAVAC, true)
|
||||||
}
|
}
|
||||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||||
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlag.loadJsr305Annotations to true)
|
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlag.loadJsr305Annotations to Jsr305State.ENABLE)
|
||||||
)
|
)
|
||||||
configurator(this)
|
configurator(this)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -95,7 +95,7 @@ class TypeQualifierAnnotationResolverTest : KtUsefulTestCase() {
|
|||||||
listOf(File(TEST_DATA_PATH))
|
listOf(File(TEST_DATA_PATH))
|
||||||
).apply {
|
).apply {
|
||||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||||
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlag.loadJsr305Annotations to true)
|
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(AnalysisFlag.loadJsr305Annotations to Jsr305State.ENABLE)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class AnalysisFlag<out T> internal constructor(
|
|||||||
object Boolean {
|
object Boolean {
|
||||||
operator fun provideDelegate(instance: Any?, property: KProperty<*>) = Flag(property.name, false)
|
operator fun provideDelegate(instance: Any?, property: KProperty<*>) = Flag(property.name, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Jsr305StateIgnoreByDefault {
|
||||||
|
operator fun provideDelegate(instance: Any?, property: KProperty<*>) = Flag(property.name, Jsr305State.IGNORE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object Flags {
|
companion object Flags {
|
||||||
@@ -47,6 +51,22 @@ class AnalysisFlag<out T> internal constructor(
|
|||||||
val multiPlatformDoNotCheckImpl by Flag.Boolean
|
val multiPlatformDoNotCheckImpl by Flag.Boolean
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val loadJsr305Annotations by Flag.Boolean
|
val loadJsr305Annotations by Flag.Jsr305StateIgnoreByDefault
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Jsr305State(
|
||||||
|
val description: String,
|
||||||
|
val shouldReportWarning: Boolean = false,
|
||||||
|
val shouldReportError: Boolean = false
|
||||||
|
) {
|
||||||
|
IGNORE("ignore"),
|
||||||
|
WARN("warn", shouldReportWarning = true),
|
||||||
|
ENABLE("enable", shouldReportError = true),
|
||||||
|
;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmField
|
||||||
|
val DEFAULT: Jsr305State = IGNORE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user