User: rednesto Date: 28 Sep 24 19:03 Revision: c98bc7a39b474fcf90363bd159570b252379b8e0 Summary: Generate signature fix preview TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=9727&personal=false Index: src/main/kotlin/platform/mixin/inspection/injector/InvalidInjectorMethodSignatureInspection.kt =================================================================== --- src/main/kotlin/platform/mixin/inspection/injector/InvalidInjectorMethodSignatureInspection.kt (revision db1124f82ab28b82d1c715ebdd41c1846622d0aa) +++ src/main/kotlin/platform/mixin/inspection/injector/InvalidInjectorMethodSignatureInspection.kt (revision c98bc7a39b474fcf90363bd159570b252379b8e0) @@ -39,6 +39,7 @@ import com.intellij.codeInsight.FileModificationService import com.intellij.codeInsight.intention.FileModifier.SafeFieldForPreview import com.intellij.codeInsight.intention.QuickFixFactory +import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo import com.intellij.codeInsight.lookup.LookupElement import com.intellij.codeInsight.lookup.LookupElementBuilder import com.intellij.codeInsight.template.Expression @@ -71,6 +72,7 @@ import com.intellij.psi.PsiType import com.intellij.psi.codeStyle.JavaCodeStyleManager import com.intellij.psi.codeStyle.VariableKind +import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiUtil import com.intellij.psi.util.TypeConversionUtil import com.intellij.psi.util.parentOfType @@ -327,12 +329,21 @@ return } val method = startElement as PsiMethod - fixParameters(project, method.parameterList) + fixParameters(project, method.parameterList, false) fixReturnType(method) fixIntLikeTypes(method, editor ?: return) } - private fun fixParameters(project: Project, parameters: PsiParameterList) { + override fun generatePreview(project: Project, editor: Editor, file: PsiFile): IntentionPreviewInfo { + val method = PsiTreeUtil.findSameElementInCopy(startElement, file) as? PsiMethod + ?: return IntentionPreviewInfo.EMPTY + fixParameters(project, method.parameterList, true) + fixReturnType(method) + fixIntLikeTypes(method, editor) + return IntentionPreviewInfo.DIFF + } + + private fun fixParameters(project: Project, parameters: PsiParameterList, preview: Boolean) { if (expectedParams == null) { return } @@ -366,10 +377,14 @@ // Restore the captured locals and sugars before applying the fix newParams.addAll(locals) newParams.addAll(sugars) + if (preview) { + parameters.synchronize(newParams) + } else { - runWriteAction { - parameters.synchronize(newParams) - } - } + runWriteAction { + parameters.synchronize(newParams) + } + } + } private fun fixReturnType(method: PsiMethod) { if (expectedReturnType == null) {