[java] remove unused field together with the javadoc (IDEA-293707)

GitOrigin-RevId: eefeda71df06e537d5a2d07119bb8724a70f5def
This commit is contained in:
Anna Kozlova
2022-05-10 11:35:02 +00:00
committed by intellij-monorepo-bot
parent 79aa35d1a0
commit a263c47077
3 changed files with 20 additions and 1 deletions
@@ -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);
}
@@ -0,0 +1,6 @@
// "Remove field 'k'" "true"
import java.io.*;
class a {
}
@@ -0,0 +1,10 @@
// "Remove field 'k'" "true"
import java.io.*;
class a {
/**
* Demo
*/
private int <caret>k;
}