[FIR] Refactor the default messages presence checking
Forbid calling `checkMissingMessages` accidentally outside tests. Checking Parcelize default messages inside a test.
This commit is contained in:
committed by
Space Team
parent
73f8c984a1
commit
20786bb35a
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.utils
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.AbstractKtDiagnosticFactory
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryForDeprecation
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.full.memberProperties
|
||||
|
||||
fun KtDiagnosticFactoryToRendererMap.checkMissingMessages(objectWithErrors: Any) {
|
||||
for (property in objectWithErrors.javaClass.kotlin.memberProperties) {
|
||||
when (val factory = property.getter.call(objectWithErrors)) {
|
||||
is AbstractKtDiagnosticFactory -> {
|
||||
checkMissingMessagesForFactory(factory, property)
|
||||
}
|
||||
is KtDiagnosticFactoryForDeprecation<*> -> {
|
||||
checkMissingMessagesForFactory(factory.warningFactory, property)
|
||||
checkMissingMessagesForFactory(factory.errorFactory, property)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun KtDiagnosticFactoryToRendererMap.checkMissingMessagesForFactory(factory: AbstractKtDiagnosticFactory, property: KProperty<*>) {
|
||||
if (!containsKey(factory)) {
|
||||
throw IllegalStateException("No default diagnostic renderer is provided for ${property.name}")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user