Kapt: Remove artificial KaptError exception on errors from annotation processor (KT-21262)

This commit is contained in:
Yan Zhulanow
2017-11-16 19:18:57 +09:00
parent 0a0de8da29
commit 3d1ca61f9f
5 changed files with 34 additions and 14 deletions
@@ -22,6 +22,7 @@ import kotlin.collections.ArraysKt;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector;
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
@@ -127,6 +128,9 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLI
}
return exitCode;
}
catch (AnalysisResult.CompilationErrorException e) {
return COMPILATION_ERROR;
}
catch (Throwable t) {
MessageCollectorUtil.reportException(groupingCollector, t);
return INTERNAL_ERROR;
@@ -26,7 +26,6 @@ open class AnalysisResult protected constructor(
val moduleDescriptor: ModuleDescriptor,
val shouldGenerateCode: Boolean = true
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
return (other is AnalysisResult && bindingContext == other.bindingContext &&
@@ -48,17 +47,25 @@ open class AnalysisResult protected constructor(
operator fun component3() = shouldGenerateCode
val error: Throwable
get() = if (this is Error) this.exception else throw IllegalStateException("Should only be called for error analysis result")
get() = if (this is InternalError) this.exception else throw IllegalStateException("Should only be called for error analysis result")
fun isError(): Boolean = this is Error
fun isError(): Boolean = this is InternalError || this is CompilationError
fun throwIfError() {
if (isError()) {
throw IllegalStateException("failed to analyze: " + error, error)
when {
this is InternalError -> throw IllegalStateException("failed to analyze: " + error, error)
this is CompilationError -> throw CompilationErrorException()
}
}
private class Error(bindingContext: BindingContext, val exception: Throwable) : AnalysisResult(bindingContext, ErrorUtils.getErrorModule())
class CompilationErrorException : RuntimeException()
private class CompilationError(bindingContext: BindingContext) : AnalysisResult(bindingContext, ErrorUtils.getErrorModule())
private class InternalError(
bindingContext: BindingContext,
val exception: Throwable
) : AnalysisResult(bindingContext, ErrorUtils.getErrorModule())
class RetryWithAdditionalJavaRoots(
bindingContext: BindingContext,
@@ -78,8 +85,12 @@ open class AnalysisResult protected constructor(
return AnalysisResult(bindingContext, module, shouldGenerateCode)
}
@JvmStatic fun error(bindingContext: BindingContext, error: Throwable): AnalysisResult {
return Error(bindingContext, error)
@JvmStatic fun internalError(bindingContext: BindingContext, error: Throwable): AnalysisResult {
return InternalError(bindingContext, error)
}
@JvmStatic fun compilationError(bindingContext: BindingContext): AnalysisResult {
return CompilationError(bindingContext)
}
}
}