J2K: Add RemoveRedundantSamConstructor postprocessing
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.psi.search.searches.ReferencesSearch
|
|||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
|
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
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.*
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
|
||||||
@@ -46,6 +47,7 @@ object J2KPostProcessingRegistrar {
|
|||||||
_processings.add(MoveLambdaOutsideParenthesesProcessing())
|
_processings.add(MoveLambdaOutsideParenthesesProcessing())
|
||||||
_processings.add(ConvertToStringTemplateProcessing())
|
_processings.add(ConvertToStringTemplateProcessing())
|
||||||
_processings.add(UsePropertyAccessSyntaxProcessing())
|
_processings.add(UsePropertyAccessSyntaxProcessing())
|
||||||
|
_processings.add(RemoveRedundantSamAdaptersProcessing())
|
||||||
|
|
||||||
registerIntentionBasedProcessing(IfThenToSafeAccessIntention()) { applyTo(it) }
|
registerIntentionBasedProcessing(IfThenToSafeAccessIntention()) { applyTo(it) }
|
||||||
registerIntentionBasedProcessing(IfThenToElvisIntention()) { applyTo(it) }
|
registerIntentionBasedProcessing(IfThenToElvisIntention()) { applyTo(it) }
|
||||||
@@ -164,4 +166,18 @@ object J2KPostProcessingRegistrar {
|
|||||||
return { intention.applyTo(element, propertyName) }
|
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) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user