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
|
@NotNull
|
||||||
private final JetTypeMapper typeMapper;
|
private final JetTypeMapper typeMapper;
|
||||||
|
|
||||||
|
private final boolean generateNotNullAssertions;
|
||||||
|
|
||||||
public GenerationState(Project project, ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List<JetFile> files) {
|
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(
|
public GenerationState(
|
||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
ClassBuilderFactory builderFactory, Progress progress,
|
ClassBuilderFactory builderFactory,
|
||||||
@NotNull AnalyzeExhaust exhaust, @NotNull List<JetFile> files, @NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping
|
@NotNull Progress progress,
|
||||||
|
@NotNull AnalyzeExhaust exhaust,
|
||||||
|
@NotNull List<JetFile> files,
|
||||||
|
@NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping,
|
||||||
|
boolean generateNotNullAssertions
|
||||||
) {
|
) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
@@ -94,6 +100,8 @@ public class GenerationState {
|
|||||||
this.scriptCodegen = injector.getScriptCodegen();
|
this.scriptCodegen = injector.getScriptCodegen();
|
||||||
this.intrinsics = injector.getIntrinsics();
|
this.intrinsics = injector.getIntrinsics();
|
||||||
this.classFileFactory = injector.getClassFileFactory();
|
this.classFileFactory = injector.getClassFileFactory();
|
||||||
|
|
||||||
|
this.generateNotNullAssertions = generateNotNullAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -146,6 +154,10 @@ public class GenerationState {
|
|||||||
return intrinsics;
|
return intrinsics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGenerateNotNullAssertions() {
|
||||||
|
return generateNotNullAssertions;
|
||||||
|
}
|
||||||
|
|
||||||
public void beforeCompile() {
|
public void beforeCompile() {
|
||||||
markUsed();
|
markUsed();
|
||||||
|
|
||||||
|
|||||||
@@ -41,4 +41,7 @@ public class JVMConfigurationKeys {
|
|||||||
public static final CompilerConfigurationKey<Boolean> STUBS = CompilerConfigurationKey.create("stubs");
|
public static final CompilerConfigurationKey<Boolean> STUBS = CompilerConfigurationKey.create("stubs");
|
||||||
public static final CompilerConfigurationKey<BuiltinToJavaTypesMapping> BUILTIN_TO_JAVA_TYPES_MAPPING_KEY =
|
public static final CompilerConfigurationKey<BuiltinToJavaTypesMapping> BUILTIN_TO_JAVA_TYPES_MAPPING_KEY =
|
||||||
CompilerConfigurationKey.create("builtin to java types mapping");
|
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,
|
configuration.put(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY,
|
||||||
builtins ? BuiltinToJavaTypesMapping.DISABLED : BuiltinToJavaTypesMapping.ENABLED);
|
builtins ? BuiltinToJavaTypesMapping.DISABLED : BuiltinToJavaTypesMapping.ENABLED);
|
||||||
|
|
||||||
|
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
|
||||||
|
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
|
||||||
|
|
||||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Command line arguments for the {@link K2JVMCompiler}
|
* Command line arguments for the {@link K2JVMCompiler}
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
public class K2JVMCompilerArguments extends CompilerArguments {
|
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")
|
@Argument(value = "noJdkAnnotations", description = "don't include JDK external annotations into classpath")
|
||||||
public boolean noJdkAnnotations;
|
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)")
|
@Argument(value = "builtins", description = "compile builtin classes (internal)")
|
||||||
public boolean builtins;
|
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);
|
environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
GenerationState generationState = new GenerationState(
|
||||||
exhaust, environment.getSourceFiles(),
|
project, ClassBuilderFactories.binaries(stubs), backendProgress, exhaust, environment.getSourceFiles(),
|
||||||
environment.getConfiguration().get(
|
environment.getConfiguration().get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||||
JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY,
|
environment.getConfiguration().get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false)
|
||||||
BuiltinToJavaTypesMapping.ENABLED));
|
);
|
||||||
GenerationStrategy.STANDARD.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
GenerationStrategy.STANDARD.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
|
|
||||||
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
|
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
|
-noJdk [flag] don't include Java runtime into classpath
|
||||||
-noStdlib [flag] don't include Kotlin runtime into classpath
|
-noStdlib [flag] don't include Kotlin runtime into classpath
|
||||||
-noJdkAnnotations [flag] don't include JDK external annotations 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)
|
-builtins [flag] compile builtin classes (internal)
|
||||||
-output [String] output directory
|
-output [String] output directory
|
||||||
-module [String] module to compile
|
-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
|
-noJdk [flag] don't include Java runtime into classpath
|
||||||
-noStdlib [flag] don't include Kotlin runtime into classpath
|
-noStdlib [flag] don't include Kotlin runtime into classpath
|
||||||
-noJdkAnnotations [flag] don't include JDK external annotations 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)
|
-builtins [flag] compile builtin classes (internal)
|
||||||
-output [String] output directory
|
-output [String] output directory
|
||||||
-module [String] module to compile
|
-module [String] module to compile
|
||||||
|
|||||||
Reference in New Issue
Block a user