diff --git a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt index e4540f32bf6..707b73dc8ed 100644 --- a/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt +++ b/idea/src/org/jetbrains/kotlin/idea/j2k/J2kPostProcessings.kt @@ -21,6 +21,7 @@ import com.intellij.psi.search.searches.ReferencesSearch import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.DiagnosticFactory import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.idea.inspections.RedundantSamConstructorInspection import org.jetbrains.kotlin.idea.intentions.* import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention @@ -46,6 +47,7 @@ object J2KPostProcessingRegistrar { _processings.add(MoveLambdaOutsideParenthesesProcessing()) _processings.add(ConvertToStringTemplateProcessing()) _processings.add(UsePropertyAccessSyntaxProcessing()) + _processings.add(RemoveRedundantSamAdaptersProcessing()) registerIntentionBasedProcessing(IfThenToSafeAccessIntention()) { applyTo(it) } registerIntentionBasedProcessing(IfThenToElvisIntention()) { applyTo(it) } @@ -164,4 +166,18 @@ object J2KPostProcessingRegistrar { return { intention.applyTo(element, propertyName) } } } + + private class RemoveRedundantSamAdaptersProcessing : J2kPostProcessing { + override fun createAction(element: JetElement, diagnostics: Diagnostics): (() -> Unit)? { + if (element !is JetCallExpression) return null + + val expressions = RedundantSamConstructorInspection.samConstructorCallsToBeConverted(element) + if (expressions.isEmpty()) return null + + return { + RedundantSamConstructorInspection.samConstructorCallsToBeConverted(element) + .forEach { RedundantSamConstructorInspection.replaceSamConstructorCall(it) } + } + } + } } \ No newline at end of file