Add a compiler parameter to generate not-null assertions on method call sites
It is off by default when invoking compiler directly, and on by default when compiling from IDE
This commit is contained in:
@@ -41,4 +41,7 @@ public class JVMConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<Boolean> STUBS = CompilerConfigurationKey.create("stubs");
|
||||
public static final CompilerConfigurationKey<BuiltinToJavaTypesMapping> BUILTIN_TO_JAVA_TYPES_MAPPING_KEY =
|
||||
CompilerConfigurationKey.create("builtin to java types mapping");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_ASSERTIONS =
|
||||
CompilerConfigurationKey.create("generate not-null assertions");
|
||||
}
|
||||
|
||||
@@ -110,6 +110,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
configuration.put(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY,
|
||||
builtins ? BuiltinToJavaTypesMapping.DISABLED : BuiltinToJavaTypesMapping.ENABLED);
|
||||
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
|
||||
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
/**
|
||||
* Command line arguments for the {@link K2JVMCompiler}
|
||||
*/
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public class K2JVMCompilerArguments extends CompilerArguments {
|
||||
|
||||
|
||||
@@ -63,6 +64,9 @@ public class K2JVMCompilerArguments extends CompilerArguments {
|
||||
@Argument(value = "noJdkAnnotations", description = "don't include JDK external annotations into classpath")
|
||||
public boolean noJdkAnnotations;
|
||||
|
||||
@Argument(value = "notNullAssertions", description = "generate not-null assertion after each invokation of method returning not-null")
|
||||
public boolean notNullAssertions;
|
||||
|
||||
@Argument(value = "builtins", description = "compile builtin classes (internal)")
|
||||
public boolean builtins;
|
||||
|
||||
|
||||
+5
-5
@@ -341,11 +341,11 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
||||
}
|
||||
};
|
||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
||||
exhaust, environment.getSourceFiles(),
|
||||
environment.getConfiguration().get(
|
||||
JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY,
|
||||
BuiltinToJavaTypesMapping.ENABLED));
|
||||
GenerationState generationState = new GenerationState(
|
||||
project, ClassBuilderFactories.binaries(stubs), backendProgress, exhaust, environment.getSourceFiles(),
|
||||
environment.getConfiguration().get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||
environment.getConfiguration().get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false)
|
||||
);
|
||||
GenerationStrategy.STANDARD.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
|
||||
|
||||
Reference in New Issue
Block a user