[Analysis API] Move 'allowedErrorFilter' to the 'compile()' parameters
This commit is contained in:
+9
-6
@@ -43,7 +43,12 @@ val STUB_UNBOUND_IR_SYMBOLS: CompilerConfigurationKey<Boolean> = CompilerConfigu
|
|||||||
internal class KtFe10CompilerFacility(
|
internal class KtFe10CompilerFacility(
|
||||||
override val analysisSession: KtFe10AnalysisSession
|
override val analysisSession: KtFe10AnalysisSession
|
||||||
) : KtCompilerFacility(), Fe10KtAnalysisSessionComponent {
|
) : KtCompilerFacility(), Fe10KtAnalysisSessionComponent {
|
||||||
override fun compile(file: KtFile, configuration: CompilerConfiguration, target: KtCompilerTarget): KtCompilationResult {
|
override fun compile(
|
||||||
|
file: KtFile,
|
||||||
|
configuration: CompilerConfiguration,
|
||||||
|
target: KtCompilerTarget,
|
||||||
|
allowedErrorFilter: (KtDiagnostic) -> Boolean
|
||||||
|
): KtCompilationResult {
|
||||||
if (file is KtCodeFragment) {
|
if (file is KtCodeFragment) {
|
||||||
throw UnsupportedOperationException("Code fragments are not supported in K1 implementation")
|
throw UnsupportedOperationException("Code fragments are not supported in K1 implementation")
|
||||||
}
|
}
|
||||||
@@ -71,7 +76,7 @@ internal class KtFe10CompilerFacility(
|
|||||||
val filesToCompile = inlineAnalyzer.allFiles()
|
val filesToCompile = inlineAnalyzer.allFiles()
|
||||||
val bindingContext = analysisContext.analyze(filesToCompile, AnalysisMode.ALL_COMPILER_CHECKS)
|
val bindingContext = analysisContext.analyze(filesToCompile, AnalysisMode.ALL_COMPILER_CHECKS)
|
||||||
|
|
||||||
val frontendErrors = computeErrors(bindingContext.diagnostics, effectiveConfiguration)
|
val frontendErrors = computeErrors(bindingContext.diagnostics, allowedErrorFilter)
|
||||||
if (frontendErrors.isNotEmpty()) {
|
if (frontendErrors.isNotEmpty()) {
|
||||||
return KtCompilationResult.Failure(frontendErrors)
|
return KtCompilationResult.Failure(frontendErrors)
|
||||||
}
|
}
|
||||||
@@ -127,7 +132,7 @@ internal class KtFe10CompilerFacility(
|
|||||||
try {
|
try {
|
||||||
KotlinCodegenFacade.compileCorrectFiles(state)
|
KotlinCodegenFacade.compileCorrectFiles(state)
|
||||||
|
|
||||||
val backendErrors = computeErrors(state.collectedExtraJvmDiagnostics, effectiveConfiguration)
|
val backendErrors = computeErrors(state.collectedExtraJvmDiagnostics, allowedErrorFilter)
|
||||||
if (backendErrors.isNotEmpty()) {
|
if (backendErrors.isNotEmpty()) {
|
||||||
return KtCompilationResult.Failure(backendErrors)
|
return KtCompilationResult.Failure(backendErrors)
|
||||||
}
|
}
|
||||||
@@ -139,9 +144,7 @@ internal class KtFe10CompilerFacility(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeErrors(diagnostics: Diagnostics, configuration: CompilerConfiguration): List<KtDiagnostic> {
|
private fun computeErrors(diagnostics: Diagnostics, allowedErrorFilter: (KtDiagnostic) -> Boolean): List<KtDiagnostic> {
|
||||||
val allowedErrorFilter = configuration[ALLOWED_ERROR_FILTER] ?: { true }
|
|
||||||
|
|
||||||
return buildList {
|
return buildList {
|
||||||
for (diagnostic in diagnostics.all()) {
|
for (diagnostic in diagnostics.all()) {
|
||||||
if (diagnostic.severity == Severity.ERROR) {
|
if (diagnostic.severity == Severity.ERROR) {
|
||||||
|
|||||||
+12
-6
@@ -47,7 +47,12 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
|
|||||||
internal class KtFirCompilerFacility(
|
internal class KtFirCompilerFacility(
|
||||||
override val analysisSession: KtFirAnalysisSession
|
override val analysisSession: KtFirAnalysisSession
|
||||||
) : KtCompilerFacility(), KtFirAnalysisSessionComponent {
|
) : KtCompilerFacility(), KtFirAnalysisSessionComponent {
|
||||||
override fun compile(file: KtFile, configuration: CompilerConfiguration, target: KtCompilerTarget): KtCompilationResult {
|
override fun compile(
|
||||||
|
file: KtFile,
|
||||||
|
configuration: CompilerConfiguration,
|
||||||
|
target: KtCompilerTarget,
|
||||||
|
allowedErrorFilter: (KtDiagnostic) -> Boolean
|
||||||
|
): KtCompilationResult {
|
||||||
val classBuilderFactory = when (target) {
|
val classBuilderFactory = when (target) {
|
||||||
is KtCompilerTarget.Jvm -> target.classBuilderFactory
|
is KtCompilerTarget.Jvm -> target.classBuilderFactory
|
||||||
}
|
}
|
||||||
@@ -61,7 +66,7 @@ internal class KtFirCompilerFacility(
|
|||||||
val mainFirFile = getFullyResolvedFirFile(file)
|
val mainFirFile = getFullyResolvedFirFile(file)
|
||||||
|
|
||||||
val frontendDiagnostics = file.collectDiagnosticsForFile(firResolveSession, DiagnosticCheckerFilter.ONLY_COMMON_CHECKERS)
|
val frontendDiagnostics = file.collectDiagnosticsForFile(firResolveSession, DiagnosticCheckerFilter.ONLY_COMMON_CHECKERS)
|
||||||
val frontendErrors = computeErrors(frontendDiagnostics, effectiveConfiguration)
|
val frontendErrors = computeErrors(frontendDiagnostics, allowedErrorFilter)
|
||||||
|
|
||||||
if (frontendErrors.isNotEmpty()) {
|
if (frontendErrors.isNotEmpty()) {
|
||||||
return KtCompilationResult.Failure(frontendErrors)
|
return KtCompilationResult.Failure(frontendErrors)
|
||||||
@@ -133,7 +138,7 @@ internal class KtFirCompilerFacility(
|
|||||||
generationState.factory.done()
|
generationState.factory.done()
|
||||||
|
|
||||||
val backendDiagnostics = generationState.collectedExtraJvmDiagnostics.all()
|
val backendDiagnostics = generationState.collectedExtraJvmDiagnostics.all()
|
||||||
val backendErrors = computeErrors(backendDiagnostics, effectiveConfiguration)
|
val backendErrors = computeErrors(backendDiagnostics, allowedErrorFilter)
|
||||||
|
|
||||||
if (backendErrors.isNotEmpty()) {
|
if (backendErrors.isNotEmpty()) {
|
||||||
return KtCompilationResult.Failure(backendErrors)
|
return KtCompilationResult.Failure(backendErrors)
|
||||||
@@ -152,9 +157,10 @@ internal class KtFirCompilerFacility(
|
|||||||
return firFile
|
return firFile
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeErrors(diagnostics: Collection<DiagnosticMarker>, configuration: CompilerConfiguration): List<KtDiagnostic> {
|
private fun computeErrors(
|
||||||
val allowedErrorFilter = configuration[ALLOWED_ERROR_FILTER] ?: { true }
|
diagnostics: Collection<DiagnosticMarker>,
|
||||||
|
allowedErrorFilter: (KtDiagnostic) -> Boolean,
|
||||||
|
): List<KtDiagnostic> {
|
||||||
return buildList {
|
return buildList {
|
||||||
for (diagnostic in diagnostics) {
|
for (diagnostic in diagnostics) {
|
||||||
require(diagnostic is KtPsiDiagnostic)
|
require(diagnostic is KtPsiDiagnostic)
|
||||||
|
|||||||
+16
-9
@@ -69,13 +69,12 @@ public sealed class KtCompilerTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract class KtCompilerFacility : KtAnalysisSessionComponent() {
|
public abstract class KtCompilerFacility : KtAnalysisSessionComponent() {
|
||||||
public companion object {
|
public abstract fun compile(
|
||||||
/** Filter for the allowed errors. Compilation will be aborted if there are errors that this filter rejects. */
|
file: KtFile,
|
||||||
public val ALLOWED_ERROR_FILTER: CompilerConfigurationKey<(KtDiagnostic) -> Boolean> =
|
configuration: CompilerConfiguration,
|
||||||
CompilerConfigurationKey<(KtDiagnostic) -> Boolean>("error filter")
|
target: KtCompilerTarget,
|
||||||
}
|
allowedErrorFilter: (KtDiagnostic) -> Boolean,
|
||||||
|
): KtCompilationResult
|
||||||
public abstract fun compile(file: KtFile, configuration: CompilerConfiguration, target: KtCompilerTarget): KtCompilationResult
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface KtCompilerFacilityMixIn : KtAnalysisSessionMixIn {
|
public interface KtCompilerFacilityMixIn : KtAnalysisSessionMixIn {
|
||||||
@@ -92,14 +91,22 @@ public interface KtCompilerFacilityMixIn : KtAnalysisSessionMixIn {
|
|||||||
*
|
*
|
||||||
* @param target Compilation target platform.
|
* @param target Compilation target platform.
|
||||||
*
|
*
|
||||||
|
* @param allowedErrorFilter Filter for the allowed errors.
|
||||||
|
* Compilation will be aborted if there are errors that this filter rejects.
|
||||||
|
*
|
||||||
* @return Compilation result.
|
* @return Compilation result.
|
||||||
*
|
*
|
||||||
* The function _does not_ wrap unchecked exceptions from the compiler.
|
* The function _does not_ wrap unchecked exceptions from the compiler.
|
||||||
* The implementation should wrap the `compile()` call into a `try`/`catch` block if necessary.
|
* The implementation should wrap the `compile()` call into a `try`/`catch` block if necessary.
|
||||||
*/
|
*/
|
||||||
public fun compile(file: KtFile, configuration: CompilerConfiguration, target: KtCompilerTarget): KtCompilationResult {
|
public fun compile(
|
||||||
|
file: KtFile,
|
||||||
|
configuration: CompilerConfiguration,
|
||||||
|
target: KtCompilerTarget,
|
||||||
|
allowedErrorFilter: (KtDiagnostic) -> Boolean
|
||||||
|
): KtCompilationResult {
|
||||||
return withValidityAssertion {
|
return withValidityAssertion {
|
||||||
analysisSession.compilerFacility.compile(file, configuration, target)
|
analysisSession.compilerFacility.compile(file, configuration, target, allowedErrorFilter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user