Community
Participate
Working Groups
We need to adjust our quick fixes for unused variable/field/param to the improved problem detection, see bug 185682. This means we not only remove the declaration but also the usages of the variables.
Aside from extending the quickfixes' action, test LocalCorrectionsQuickFixTest.testUnusedVariables7() obviously needs adjusting, since this comment: buf.append(" e+=\"\";\n");//makes e an used variable is no longer true. For an easy fix I suggest changing to s.t. like buf.append(" e= e.toUpperCase();\n");//makes e an used variable (in all three contents strings).
(In reply to comment #1) > Aside from extending the quickfixes' action, test > LocalCorrectionsQuickFixTest.testUnusedVariables7() obviously needs > adjusting, since this comment: > buf.append(" e+=\"\";\n");//makes e an used variable > is no longer true. For an easy fix I suggest changing to s.t. like > buf.append(" e= e.toUpperCase();\n");//makes e an used variable > (in all three contents strings). Yep, I'm about to fix the JUnit failures in the latest build.
Created attachment 181829 [details] fix + tests (In reply to comment #0) > This means we not only remove the declaration but also the usages of the > variables. Patch fixes these.
The fix goes into the right direction, but there are some cases that are not handled correctly: void foo(boolean b) { for (int i= 0; ; ) { if (b) i++; System.out.println("hi"); i-= 18; } } private int fField; void bar() { new Snippet().fField++; } See RemoveUnusedMemberOperation#removeVariableWithInitializer(..) for existing code that solves such problems when processing assignments.
> new Snippet().fField++; Sorry, that's also not handled correctly for assignments, e.g.: new Snippet().fField= 12; Please fix if easily possible, otherwise make a new bug for such problems.
Created attachment 181841 [details] fix + tests Fixes this case as well > for (int i= 0; ; ) { > if (b) > i++; > System.out.println("hi"); > i-= 18; > } Will file a new bug for > private int fField; > void bar() { > new Snippet().fField++; > }
(In reply to comment #6) +1 for M3.
Fixed in HEAD. > Will file a new bug for > > private int fField; > > void bar() { > > new Snippet().fField++; > > } Filed Bug 328839.
Verified in I20101027-1800