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:
@@ -68,14 +68,20 @@ public class GenerationState {
|
||||
@NotNull
|
||||
private final JetTypeMapper typeMapper;
|
||||
|
||||
private final boolean generateNotNullAssertions;
|
||||
|
||||
public GenerationState(Project project, ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List<JetFile> files) {
|
||||
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED);
|
||||
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED, true);
|
||||
}
|
||||
|
||||
public GenerationState(
|
||||
@NotNull Project project,
|
||||
ClassBuilderFactory builderFactory, Progress progress,
|
||||
@NotNull AnalyzeExhaust exhaust, @NotNull List<JetFile> files, @NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping
|
||||
ClassBuilderFactory builderFactory,
|
||||
@NotNull Progress progress,
|
||||
@NotNull AnalyzeExhaust exhaust,
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping,
|
||||
boolean generateNotNullAssertions
|
||||
) {
|
||||
this.project = project;
|
||||
this.progress = progress;
|
||||
@@ -94,6 +100,8 @@ public class GenerationState {
|
||||
this.scriptCodegen = injector.getScriptCodegen();
|
||||
this.intrinsics = injector.getIntrinsics();
|
||||
this.classFileFactory = injector.getClassFileFactory();
|
||||
|
||||
this.generateNotNullAssertions = generateNotNullAssertions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -146,6 +154,10 @@ public class GenerationState {
|
||||
return intrinsics;
|
||||
}
|
||||
|
||||
public boolean isGenerateNotNullAssertions() {
|
||||
return generateNotNullAssertions;
|
||||
}
|
||||
|
||||
public void beforeCompile() {
|
||||
markUsed();
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -7,6 +7,7 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
-noJdk [flag] don't include Java runtime into classpath
|
||||
-noStdlib [flag] don't include Kotlin runtime into classpath
|
||||
-noJdkAnnotations [flag] don't include JDK external annotations into classpath
|
||||
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
|
||||
-builtins [flag] compile builtin classes (internal)
|
||||
-output [String] output directory
|
||||
-module [String] module to compile
|
||||
|
||||
@@ -8,6 +8,7 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
-noJdk [flag] don't include Java runtime into classpath
|
||||
-noStdlib [flag] don't include Kotlin runtime into classpath
|
||||
-noJdkAnnotations [flag] don't include JDK external annotations into classpath
|
||||
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
|
||||
-builtins [flag] compile builtin classes (internal)
|
||||
-output [String] output directory
|
||||
-module [String] module to compile
|
||||
|
||||
Reference in New Issue
Block a user