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:
@@ -70,8 +70,10 @@ public class GenerationState {
|
|||||||
|
|
||||||
private final boolean generateNotNullAssertions;
|
private final boolean generateNotNullAssertions;
|
||||||
|
|
||||||
|
private final boolean generateNotNullParamAssertions;
|
||||||
|
|
||||||
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, true);
|
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenerationState(
|
public GenerationState(
|
||||||
@@ -81,7 +83,8 @@ public class GenerationState {
|
|||||||
@NotNull AnalyzeExhaust exhaust,
|
@NotNull AnalyzeExhaust exhaust,
|
||||||
@NotNull List<JetFile> files,
|
@NotNull List<JetFile> files,
|
||||||
@NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping,
|
@NotNull BuiltinToJavaTypesMapping builtinToJavaTypesMapping,
|
||||||
boolean generateNotNullAssertions
|
boolean generateNotNullAssertions,
|
||||||
|
boolean generateNotNullParamAssertions
|
||||||
) {
|
) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
@@ -102,6 +105,7 @@ public class GenerationState {
|
|||||||
this.classFileFactory = injector.getClassFileFactory();
|
this.classFileFactory = injector.getClassFileFactory();
|
||||||
|
|
||||||
this.generateNotNullAssertions = generateNotNullAssertions;
|
this.generateNotNullAssertions = generateNotNullAssertions;
|
||||||
|
this.generateNotNullParamAssertions = generateNotNullParamAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -158,6 +162,10 @@ public class GenerationState {
|
|||||||
return generateNotNullAssertions;
|
return generateNotNullAssertions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGenerateNotNullParamAssertions() {
|
||||||
|
return generateNotNullParamAssertions;
|
||||||
|
}
|
||||||
|
|
||||||
public void beforeCompile() {
|
public void beforeCompile() {
|
||||||
markUsed();
|
markUsed();
|
||||||
|
|
||||||
|
|||||||
@@ -44,4 +44,6 @@ public class JVMConfigurationKeys {
|
|||||||
|
|
||||||
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_ASSERTIONS =
|
public static final CompilerConfigurationKey<Boolean> GENERATE_NOT_NULL_ASSERTIONS =
|
||||||
CompilerConfigurationKey.create("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);
|
builtins ? BuiltinToJavaTypesMapping.DISABLED : BuiltinToJavaTypesMapping.ENABLED);
|
||||||
|
|
||||||
configuration.put(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, arguments.notNullAssertions);
|
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);
|
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")
|
@Argument(value = "notNullAssertions", description = "generate not-null assertion after each invokation of method returning not-null")
|
||||||
public boolean notNullAssertions;
|
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)")
|
@Argument(value = "builtins", description = "compile builtin classes (internal)")
|
||||||
public boolean builtins;
|
public boolean builtins;
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -335,21 +335,23 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
AnalyzeExhaust exhaust,
|
AnalyzeExhaust exhaust,
|
||||||
boolean stubs) {
|
boolean stubs) {
|
||||||
Project project = environment.getProject();
|
Project project = environment.getProject();
|
||||||
|
final CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
Progress backendProgress = new Progress() {
|
Progress backendProgress = new Progress() {
|
||||||
@Override
|
@Override
|
||||||
public void log(String message) {
|
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(
|
GenerationState generationState = new GenerationState(
|
||||||
project, ClassBuilderFactories.binaries(stubs), backendProgress, exhaust, environment.getSourceFiles(),
|
project, ClassBuilderFactories.binaries(stubs), backendProgress, exhaust, environment.getSourceFiles(),
|
||||||
environment.getConfiguration().get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||||
environment.getConfiguration().get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false)
|
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
|
||||||
|
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false)
|
||||||
);
|
);
|
||||||
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());
|
||||||
for (CompilerPlugin plugin : environment.getConfiguration().getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
|
for (CompilerPlugin plugin : configuration.getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
|
||||||
plugin.processFiles(context);
|
plugin.processFiles(context);
|
||||||
}
|
}
|
||||||
return generationState;
|
return generationState;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
|||||||
-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
|
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
|
||||||
|
-notNullParamAssertions [flag] generate not-null assertions on parameters of methods accessible from Java
|
||||||
-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
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ Usage: org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
|||||||
-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
|
-notNullAssertions [flag] generate not-null assertion after each invokation of method returning not-null
|
||||||
|
-notNullParamAssertions [flag] generate not-null assertions on parameters of methods accessible from Java
|
||||||
-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
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
|||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationStrategy;
|
import org.jetbrains.jet.codegen.state.GenerationStrategy;
|
||||||
|
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
@@ -359,10 +360,12 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
BuiltinsScopeExtensionMode.ALL);
|
BuiltinsScopeExtensionMode.ALL);
|
||||||
analyzeExhaust.throwIfError();
|
analyzeExhaust.throwIfError();
|
||||||
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||||
|
CompilerConfiguration configuration = environment.getConfiguration();
|
||||||
GenerationState state = new GenerationState(
|
GenerationState state = new GenerationState(
|
||||||
environment.getProject(), classBuilderFactory, Progress.DEAF, analyzeExhaust, files.getPsiFiles(),
|
environment.getProject(), classBuilderFactory, Progress.DEAF, analyzeExhaust, files.getPsiFiles(),
|
||||||
environment.getConfiguration().get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
configuration.get(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY, BuiltinToJavaTypesMapping.ENABLED),
|
||||||
environment.getConfiguration().get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true)
|
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
|
||||||
|
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true)
|
||||||
);
|
);
|
||||||
GenerationStrategy.STANDARD.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
GenerationStrategy.STANDARD.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
Reference in New Issue
Block a user