Add a compiler parameter to generate not-null parameter assertions
Enable/disable assertion generation on parameters in the beginning of methods accessible from Java
This commit is contained in:
@@ -44,4 +44,6 @@ public class JVMConfigurationKeys {
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_ASSERTIONS =
|
||||
CompilerConfigurationKey.create("generate not-null assertions");
|
||||
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_PARAMETER_ASSERTIONS =
|
||||
CompilerConfigurationKey.create("generate not-null parameter assertions");
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
builtins ? BuiltinToJavaTypesMapping.DISABLED : BuiltinToJavaTypesMapping.ENABLED);
|
||||
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
|
||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, arguments.notNullParamAssertions);
|
||||
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||
|
||||
|
||||
@@ -67,6 +67,9 @@ public class K2JVMCompilerArguments extends CompilerArguments {
|
||||
@Argument(value = "notNullAssertions", description = "generate not-null assertion after each invokation of method returning not-null")
|
||||
public boolean notNullAssertions;
|
||||
|
||||
@Argument(value = "notNullParamAssertions", description = "generate not-null assertions on parameters of methods accessible from Java")
|
||||
public boolean notNullParamAssertions;
|
||||
|
||||
@Argument(value = "builtins", description = "compile builtin classes (internal)")
|
||||
public boolean builtins;
|
||||
|
||||
|
||||
+6
-4
@@ -335,21 +335,23 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
AnalyzeExhaust exhaust,
|
||||
boolean stubs) {
|
||||
Project project = environment.getProject();
|
||||
final CompilerConfiguration configuration = environment.getConfiguration();
|
||||
Progress backendProgress = new Progress() {
|
||||
@Override
|
||||
public void log(String message) {
|
||||
environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
||||
configuration.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),
|
||||
environment.getConfiguration().get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false)
|
||||
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
|
||||
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false)
|
||||
);
|
||||
GenerationStrategy.STANDARD.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
|
||||
for (CompilerPlugin plugin : environment.getConfiguration().getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
|
||||
for (CompilerPlugin plugin : configuration.getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
|
||||
plugin.processFiles(context);
|
||||
}
|
||||
return generationState;
|
||||
|
||||
Reference in New Issue
Block a user