diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java index 3f27d34b5124..11ce40e5f7dd 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 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.codeInsight.daemon.impl.quickfix; import com.intellij.psi.*; @@ -220,6 +220,9 @@ public final class RemoveUnusedVariableUtil { private static void deleteVariable(PsiVariable variable) { CommentTracker tracker = new CommentTracker(); tracker.markUnchanged(variable.getInitializer()); // assume that initializer is used (e.g. inlined) + if (variable instanceof PsiJavaDocumentedElement) { + tracker.markUnchanged(((PsiJavaDocumentedElement)variable).getDocComment()); + } tracker.deleteAndRestoreComments(variable); } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable/afterField3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable/afterField3.java new file mode 100644 index 000000000000..4127542278fc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable/afterField3.java @@ -0,0 +1,6 @@ +// "Remove field 'k'" "true" +import java.io.*; + +class a { +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable/beforeField3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable/beforeField3.java new file mode 100644 index 000000000000..a100088ef9ff --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable/beforeField3.java @@ -0,0 +1,10 @@ +// "Remove field 'k'" "true" +import java.io.*; + +class a { + /** + * Demo + */ + private int k; +} +