J2K fix: do not use auto-conversion of accessors to = Unit format

This commit is contained in:
Mikhail Glukhikh
2016-09-19 11:07:24 +03:00
parent 4509cd43cb
commit 909b9b6463
2 changed files with 5 additions and 3 deletions
@@ -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())