mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
remove unused assignment: do not move the transformed statement up as it could change the semantic and is not evident (IDEA-123841)
This commit is contained in:
@@ -118,8 +118,13 @@ public class DefUseInspection extends DefUseInspectionBase {
|
||||
else if (res == RemoveUnusedVariableUtil.MAKE_STATEMENT) {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
final PsiStatement statementFromText = factory.createStatementFromText(psiInitializer.getText() + ";", null);
|
||||
declaration.getParent().addAfter(statementFromText, declaration);
|
||||
elementToDelete.delete();
|
||||
final PsiElement parent = elementToDelete.getParent();
|
||||
if (parent instanceof PsiExpressionStatement) {
|
||||
parent.replace(statementFromText);
|
||||
} else {
|
||||
declaration.getParent().addAfter(statementFromText, declaration);
|
||||
elementToDelete.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Remove redundant assignment" "true"
|
||||
class A {
|
||||
A a = null;
|
||||
String m(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
{
|
||||
String ss = "";
|
||||
|
||||
System.out.println();
|
||||
|
||||
a.m(ss);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Remove redundant assignment" "true"
|
||||
class A {
|
||||
A a = null;
|
||||
String m(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
{
|
||||
String ss = "";
|
||||
|
||||
System.out.println();
|
||||
|
||||
s<caret>s = a.m(ss);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user