J2K fix: do not use auto-conversion of accessors to = Unit format
This commit is contained in:
@@ -31,7 +31,9 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
|
||||
class ConvertToExpressionBodyIntention : SelfTargetingOffsetIndependentIntention<KtDeclarationWithBody>(
|
||||
class ConvertToExpressionBodyIntention(
|
||||
val convertEmptyToUnit: Boolean = true
|
||||
) : SelfTargetingOffsetIndependentIntention<KtDeclarationWithBody>(
|
||||
KtDeclarationWithBody::class.java, "Convert to expression body"
|
||||
) {
|
||||
override fun isApplicableTo(element: KtDeclarationWithBody): Boolean {
|
||||
@@ -98,7 +100,7 @@ class ConvertToExpressionBodyIntention : SelfTargetingOffsetIndependentIntention
|
||||
|
||||
private fun calcValue(declaration: KtDeclarationWithBody): KtExpression? {
|
||||
val body = declaration.blockExpression() ?: return null
|
||||
return calcValue(body, emptyAllowed = declaration !is KtConstructor<*>)
|
||||
return calcValue(body, emptyAllowed = declaration !is KtConstructor<*> && convertEmptyToUnit)
|
||||
}
|
||||
|
||||
private fun calcValue(body: KtBlockExpression, emptyAllowed: Boolean = true): KtExpression? {
|
||||
|
||||
@@ -58,7 +58,7 @@ object J2KPostProcessingRegistrar {
|
||||
_processings.add(RemoveRedundantSamAdaptersProcessing())
|
||||
_processings.add(RemoveRedundantCastToNullableProcessing())
|
||||
|
||||
registerIntentionBasedProcessing(ConvertToExpressionBodyIntention()) { it is KtPropertyAccessor }
|
||||
registerIntentionBasedProcessing(ConvertToExpressionBodyIntention(convertEmptyToUnit = false)) { it is KtPropertyAccessor }
|
||||
registerIntentionBasedProcessing(IfThenToSafeAccessIntention())
|
||||
registerIntentionBasedProcessing(IfThenToElvisIntention())
|
||||
registerIntentionBasedProcessing(IfNullToElvisIntention())
|
||||
|
||||
Reference in New Issue
Block a user