@@ -330,16 +330,17 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
330
330
}
331
331
val method = startElement as PsiMethod
332
332
fixParameters(project, method.parameterList, false )
333
- fixReturnType(method)
334
- fixIntLikeTypes(method, editor ? : return )
333
+ fixReturnType(method, editor ? : return , file, false )
334
+ fixIntLikeTypes(method, editor, false )
335
335
}
336
336
337
337
override fun generatePreview (project : Project , editor : Editor , file : PsiFile ): IntentionPreviewInfo {
338
338
val method = PsiTreeUtil .findSameElementInCopy(startElement, file) as ? PsiMethod
339
339
? : return IntentionPreviewInfo .EMPTY
340
340
fixParameters(project, method.parameterList, true )
341
- fixReturnType(method)
342
- fixIntLikeTypes(method, editor)
341
+ // Pass the original startElement because the underlying fix gets the preview element itself
342
+ fixReturnType(startElement as PsiMethod , editor, file, true )
343
+ fixIntLikeTypes(method, editor, true )
343
344
return IntentionPreviewInfo .DIFF
344
345
}
345
346
@@ -386,34 +387,43 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
386
387
}
387
388
}
388
389
389
- private fun fixReturnType (method : PsiMethod ) {
390
+ private fun fixReturnType (method : PsiMethod , editor : Editor , file : PsiFile , preview : Boolean ) {
390
391
if (expectedReturnType == null ) {
391
392
return
392
393
}
393
- QuickFixFactory .getInstance()
394
- .createMethodReturnFix(method, expectedReturnType, false )
395
- .applyFix()
394
+ val fix = QuickFixFactory .getInstance().createMethodReturnFix(method, expectedReturnType, false )
395
+ if (preview) {
396
+ fix.generatePreview(file.project, editor, file)
397
+ } else {
398
+ fix.applyFix()
399
+ }
396
400
}
397
401
398
- private fun fixIntLikeTypes (method : PsiMethod , editor : Editor ) {
402
+ private fun fixIntLikeTypes (method : PsiMethod , editor : Editor , preview : Boolean ) {
399
403
if (intLikeTypePositions.isEmpty()) {
400
404
return
401
405
}
402
- invokeLater {
403
- WriteCommandAction .runWriteCommandAction(
404
- method.project,
405
- " Choose Int-Like Type" ,
406
- null ,
407
- {
408
- val template = makeIntLikeTypeTemplate(method, intLikeTypePositions)
409
- if (template != null ) {
410
- editor.caretModel.moveToOffset(method.startOffset)
411
- TemplateManager .getInstance(method.project)
412
- .startTemplate(editor, template)
413
- }
414
- },
415
- method.parentOfType<PsiFile >()!!
416
- )
406
+ val runnable = {
407
+ val template = makeIntLikeTypeTemplate(method, intLikeTypePositions)
408
+ if (template != null ) {
409
+ editor.caretModel.moveToOffset(method.startOffset)
410
+ TemplateManager .getInstance(method.project)
411
+ .startTemplate(editor, template)
412
+ }
413
+ }
414
+
415
+ if (preview) {
416
+ runnable()
417
+ } else {
418
+ invokeLater {
419
+ WriteCommandAction .runWriteCommandAction(
420
+ method.project,
421
+ " Choose Int-Like Type" ,
422
+ null ,
423
+ runnable,
424
+ method.parentOfType<PsiFile >()!!
425
+ )
426
+ }
417
427
}
418
428
}
419
429
0 commit comments