From 22a45175bfa5dd2c827c8f38f6c9b5408d7573ff Mon Sep 17 00:00:00 2001 From: Louis Vignier Date: Tue, 19 Jul 2022 19:15:42 +0200 Subject: [PATCH] [codeInspection] JoinDeclarationAndAssignmentFix: support preview GitOrigin-RevId: ec78d6ebcd51dddc2c0516f12f3f6ee92dcef9bd --- ...JoinDeclarationAndAssignmentJavaInspection.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/JoinDeclarationAndAssignmentJavaInspection.java b/java/java-impl-inspections/src/com/intellij/codeInspection/JoinDeclarationAndAssignmentJavaInspection.java index fde4d544cac9..937a93c39d80 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/JoinDeclarationAndAssignmentJavaInspection.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/JoinDeclarationAndAssignmentJavaInspection.java @@ -1,8 +1,9 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInspection; import com.intellij.codeInsight.FileModificationService; import com.intellij.codeInsight.editorActions.DeclarationJoinLinesHandler; +import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo; import com.intellij.java.JavaBundle; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.project.Project; @@ -229,6 +230,17 @@ public class JoinDeclarationAndAssignmentJavaInspection extends AbstractBaseJava WriteAction.run(() -> DeclarationJoinLinesHandler.joinDeclarationAndAssignment(context.myVariable, context.myAssignment)); } } + + @Override + public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull ProblemDescriptor previewDescriptor) { + Context context = getContext(previewDescriptor.getPsiElement()); + if (context != null) { + DeclarationJoinLinesHandler.joinDeclarationAndAssignment(context.myVariable, context.myAssignment); + return IntentionPreviewInfo.DIFF; + } else { + return IntentionPreviewInfo.EMPTY; + } + } } private static class Context {