Make KDoc generate documentation on red code

KDoc is not a compiler, so it should not care whether or not the code is valid.
Therefore suppress the compiler's exit code, errors and warnings in KDoc plugin
This commit is contained in:
Alexander Udalov
2014-03-14 18:18:48 +04:00
parent b1d76d6ab0
commit 0dfacd8b20
4 changed files with 43 additions and 9 deletions
@@ -288,26 +288,29 @@ public class KotlinToJVMBytecodeCompiler {
}, environment.getSourceFiles()
);
return analyzerWithCompilerReport.hasErrors() ? null : analyzerWithCompilerReport.getAnalyzeExhaust();
AnalyzeExhaust exhaust = analyzerWithCompilerReport.getAnalyzeExhaust();
assert exhaust != null : "AnalyzeExhaust should be non-null, compiling: " + environment.getSourceFiles();
CompilerPluginContext context = new CompilerPluginContext(environment.getProject(), exhaust.getBindingContext(),
environment.getSourceFiles());
for (CompilerPlugin plugin : environment.getConfiguration().getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
plugin.processFiles(context);
}
return analyzerWithCompilerReport.hasErrors() ? null : exhaust;
}
@NotNull
private static GenerationState generate(@NotNull JetCoreEnvironment environment, @NotNull AnalyzeExhaust exhaust) {
Project project = environment.getProject();
CompilerConfiguration configuration = environment.getConfiguration();
GenerationState generationState = new GenerationState(
project, ClassBuilderFactories.BINARIES, Progress.DEAF, exhaust.getBindingContext(), environment.getSourceFiles(),
environment.getProject(), ClassBuilderFactories.BINARIES, Progress.DEAF, exhaust.getBindingContext(), environment.getSourceFiles(),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, false),
configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, false),
GenerationState.GenerateClassFilter.GENERATE_ALL,
configuration.get(JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG)
);
KotlinCodegenFacade.compileCorrectFiles(generationState, CompilationErrorHandler.THROW_EXCEPTION);
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
for (CompilerPlugin plugin : configuration.getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
plugin.processFiles(context);
}
return generationState;
}
}
@@ -17,8 +17,11 @@
package org.jetbrains.kotlin.maven.doc;
import org.apache.maven.plugin.MojoExecutionException;
import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.doc.KDocArguments;
import org.jetbrains.kotlin.doc.KDocCompiler;
@@ -183,6 +186,21 @@ public class KDocMojo extends KotlinCompileMojoBase {
return new KDocArguments();
}
@Override
protected ExitCode executeCompiler(
CLICompiler compiler,
CommonCompilerArguments arguments,
MessageCollector messageCollector
) {
ExitCode exitCode = super.executeCompiler(compiler, arguments, messageCollector);
if (exitCode == ExitCode.COMPILATION_ERROR) {
// KDoc should ignore compilation errors, since it's not supposed to compile code.
// KDoc is supposed to generate documentation by the code that may be correct or not
return ExitCode.OK;
}
return exitCode;
}
@Override
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
if (arguments instanceof K2JVMCompilerArguments) {
@@ -6,6 +6,7 @@ import org.jetbrains.jet.cli.common.CLIConfigurationKeys
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler
import org.jetbrains.jet.config.CompilerConfiguration
import org.jetbrains.jet.cli.common.messages.MessageCollector
/**
* Main for running the KDocCompiler
@@ -23,6 +24,9 @@ class KDocCompiler() : K2JVMCompiler() {
protected override fun configureEnvironment(configuration : CompilerConfiguration, arguments : K2JVMCompilerArguments) {
super.configureEnvironment(configuration, arguments)
configuration.add(CLIConfigurationKeys.COMPILER_PLUGINS, KDoc(arguments as KDocArguments))
// Suppress all messages from the compiler, because KDoc is not a compiler
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
}
protected override fun createArguments() : K2JVMCompilerArguments {
@@ -206,7 +206,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
}
};
final ExitCode exitCode = compiler.exec(messageCollector, arguments);
final ExitCode exitCode = executeCompiler(compiler, arguments, messageCollector);
switch (exitCode) {
case COMPILATION_ERROR:
@@ -258,6 +258,15 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
return new K2JVMCompilerArguments();
}
@NotNull
protected ExitCode executeCompiler(
@NotNull CLICompiler compiler,
@NotNull CommonCompilerArguments arguments,
@NotNull MessageCollector messageCollector
) {
return compiler.exec(messageCollector, arguments);
}
/**
* Derived classes can register custom plugins or configurations
*/