Fix formatting of RuntimeAssertion.kt
This commit is contained in:
@@ -39,10 +39,11 @@ class RuntimeAssertionInfo(val needNotNullAssertion: Boolean, val message: Strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic fun create(
|
@JvmStatic
|
||||||
expectedType: KotlinType,
|
fun create(
|
||||||
expressionType: KotlinType,
|
expectedType: KotlinType,
|
||||||
dataFlowExtras: DataFlowExtras
|
expressionType: KotlinType,
|
||||||
|
dataFlowExtras: DataFlowExtras
|
||||||
): RuntimeAssertionInfo? {
|
): RuntimeAssertionInfo? {
|
||||||
fun assertNotNull(): Boolean {
|
fun assertNotNull(): Boolean {
|
||||||
if (expectedType.isError || expressionType.isError) return false
|
if (expectedType.isError || expressionType.isError) return false
|
||||||
@@ -81,9 +82,9 @@ private val KtExpression.textForRuntimeAssertionInfo
|
|||||||
get() = StringUtil.trimMiddle(text, 50)
|
get() = StringUtil.trimMiddle(text, 50)
|
||||||
|
|
||||||
class RuntimeAssertionsDataFlowExtras(
|
class RuntimeAssertionsDataFlowExtras(
|
||||||
private val c: ResolutionContext<*>,
|
private val c: ResolutionContext<*>,
|
||||||
private val expressionType: KotlinType,
|
private val expressionType: KotlinType,
|
||||||
private val expression: KtExpression
|
private val expression: KtExpression
|
||||||
) : RuntimeAssertionInfo.DataFlowExtras {
|
) : RuntimeAssertionInfo.DataFlowExtras {
|
||||||
private val dataFlowValue by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
private val dataFlowValue by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
c.dataFlowValueFactory.createDataFlowValue(expression, expressionType, c)
|
c.dataFlowValueFactory.createDataFlowValue(expression, expressionType, c)
|
||||||
@@ -96,13 +97,18 @@ class RuntimeAssertionsDataFlowExtras(
|
|||||||
}
|
}
|
||||||
|
|
||||||
object RuntimeAssertionsTypeChecker : AdditionalTypeChecker {
|
object RuntimeAssertionsTypeChecker : AdditionalTypeChecker {
|
||||||
override fun checkType(expression: KtExpression, expressionType: KotlinType, expressionTypeWithSmartCast: KotlinType, c: ResolutionContext<*>) {
|
override fun checkType(
|
||||||
|
expression: KtExpression,
|
||||||
|
expressionType: KotlinType,
|
||||||
|
expressionTypeWithSmartCast: KotlinType,
|
||||||
|
c: ResolutionContext<*>
|
||||||
|
) {
|
||||||
if (TypeUtils.noExpectedType(c.expectedType)) return
|
if (TypeUtils.noExpectedType(c.expectedType)) return
|
||||||
|
|
||||||
val assertionInfo = RuntimeAssertionInfo.create(
|
val assertionInfo = RuntimeAssertionInfo.create(
|
||||||
c.expectedType,
|
c.expectedType,
|
||||||
expressionType,
|
expressionType,
|
||||||
RuntimeAssertionsDataFlowExtras(c, expressionType, expression)
|
RuntimeAssertionsDataFlowExtras(c, expressionType, expression)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (assertionInfo != null) {
|
if (assertionInfo != null) {
|
||||||
@@ -127,9 +133,9 @@ object RuntimeAssertionsOnExtensionReceiverCallChecker : CallChecker {
|
|||||||
val c = context.resolutionContext
|
val c = context.resolutionContext
|
||||||
|
|
||||||
val assertionInfo = RuntimeAssertionInfo.create(
|
val assertionInfo = RuntimeAssertionInfo.create(
|
||||||
receiverParameter.type,
|
receiverParameter.type,
|
||||||
receiverValue.type,
|
receiverValue.type,
|
||||||
RuntimeAssertionsDataFlowExtras(c, receiverValue.type, receiverExpression)
|
RuntimeAssertionsDataFlowExtras(c, receiverValue.type, receiverExpression)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (assertionInfo != null) {
|
if (assertionInfo != null) {
|
||||||
@@ -141,10 +147,10 @@ object RuntimeAssertionsOnExtensionReceiverCallChecker : CallChecker {
|
|||||||
object RuntimeAssertionsOnDeclarationBodyChecker {
|
object RuntimeAssertionsOnDeclarationBodyChecker {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun check(
|
fun check(
|
||||||
declaration: KtDeclaration,
|
declaration: KtDeclaration,
|
||||||
descriptor: DeclarationDescriptor,
|
descriptor: DeclarationDescriptor,
|
||||||
bindingTrace: BindingTrace,
|
bindingTrace: BindingTrace,
|
||||||
languageVersionSettings: LanguageVersionSettings
|
languageVersionSettings: LanguageVersionSettings
|
||||||
) {
|
) {
|
||||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.StrictJavaNullabilityAssertions)) return
|
if (!languageVersionSettings.supportsFeature(LanguageFeature.StrictJavaNullabilityAssertions)) return
|
||||||
|
|
||||||
@@ -161,9 +167,9 @@ object RuntimeAssertionsOnDeclarationBodyChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkLocalVariable(
|
private fun checkLocalVariable(
|
||||||
declaration: KtProperty,
|
declaration: KtProperty,
|
||||||
descriptor: VariableDescriptor,
|
descriptor: VariableDescriptor,
|
||||||
bindingTrace: BindingTrace
|
bindingTrace: BindingTrace
|
||||||
) {
|
) {
|
||||||
if (declaration.typeReference != null) return
|
if (declaration.typeReference != null) return
|
||||||
|
|
||||||
@@ -171,20 +177,23 @@ object RuntimeAssertionsOnDeclarationBodyChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkFunction(
|
private fun checkFunction(
|
||||||
declaration: KtFunction,
|
declaration: KtFunction,
|
||||||
descriptor: FunctionDescriptor,
|
descriptor: FunctionDescriptor,
|
||||||
bindingTrace: BindingTrace
|
bindingTrace: BindingTrace
|
||||||
) {
|
) {
|
||||||
if (declaration.typeReference != null || declaration.hasBlockBody()) return
|
if (declaration.typeReference != null || declaration.hasBlockBody()) return
|
||||||
|
|
||||||
checkNullabilityAssertion(declaration.bodyExpression ?: return, descriptor.returnType ?: return,
|
checkNullabilityAssertion(
|
||||||
bindingTrace)
|
declaration.bodyExpression ?: return,
|
||||||
|
descriptor.returnType ?: return,
|
||||||
|
bindingTrace
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkProperty(
|
private fun checkProperty(
|
||||||
declaration: KtProperty,
|
declaration: KtProperty,
|
||||||
descriptor: PropertyDescriptor,
|
descriptor: PropertyDescriptor,
|
||||||
bindingTrace: BindingTrace
|
bindingTrace: BindingTrace
|
||||||
) {
|
) {
|
||||||
if (declaration.typeReference != null) return
|
if (declaration.typeReference != null) return
|
||||||
|
|
||||||
@@ -195,21 +204,24 @@ object RuntimeAssertionsOnDeclarationBodyChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkPropertyAccessor(
|
private fun checkPropertyAccessor(
|
||||||
declaration: KtPropertyAccessor,
|
declaration: KtPropertyAccessor,
|
||||||
descriptor: PropertyAccessorDescriptor,
|
descriptor: PropertyAccessorDescriptor,
|
||||||
bindingTrace: BindingTrace
|
bindingTrace: BindingTrace
|
||||||
) {
|
) {
|
||||||
if (declaration.property.typeReference != null || declaration.hasBlockBody()) return
|
if (declaration.property.typeReference != null || declaration.hasBlockBody()) return
|
||||||
|
|
||||||
checkNullabilityAssertion(declaration.bodyExpression ?: return, descriptor.correspondingProperty.type,
|
checkNullabilityAssertion(
|
||||||
bindingTrace)
|
declaration.bodyExpression ?: return,
|
||||||
|
descriptor.correspondingProperty.type,
|
||||||
|
bindingTrace
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun checkNullabilityAssertion(
|
private fun checkNullabilityAssertion(
|
||||||
expression: KtExpression,
|
expression: KtExpression,
|
||||||
declarationType: KotlinType,
|
declarationType: KotlinType,
|
||||||
bindingTrace: BindingTrace
|
bindingTrace: BindingTrace
|
||||||
) {
|
) {
|
||||||
if (declarationType.unwrap().canContainNull()) return
|
if (declarationType.unwrap().canContainNull()) return
|
||||||
|
|
||||||
@@ -219,9 +231,9 @@ object RuntimeAssertionsOnDeclarationBodyChecker {
|
|||||||
if (!expressionType.hasEnhancedNullability()) return
|
if (!expressionType.hasEnhancedNullability()) return
|
||||||
|
|
||||||
bindingTrace.record(
|
bindingTrace.record(
|
||||||
JvmBindingContextSlices.BODY_RUNTIME_ASSERTION_INFO,
|
JvmBindingContextSlices.BODY_RUNTIME_ASSERTION_INFO,
|
||||||
expression,
|
expression,
|
||||||
RuntimeAssertionInfo(true, expression.textForRuntimeAssertionInfo)
|
RuntimeAssertionInfo(true, expression.textForRuntimeAssertionInfo)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user