Summary: | [quick fix] Adjust quick fixes for unused variable/field/param to improved problem detection | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Dani Megert <daniel_megert> | ||||||
Component: | UI | Assignee: | Deepak Azad <deepakazad> | ||||||
Status: | VERIFIED FIXED | QA Contact: | |||||||
Severity: | enhancement | ||||||||
Priority: | P3 | CC: | deepakazad, markus.kell.r, stephan.herrmann | ||||||
Version: | 3.7 | Flags: | markus.kell.r:
review+
|
||||||
Target Milestone: | 3.7 M3 | ||||||||
Hardware: | All | ||||||||
OS: | All | ||||||||
Whiteboard: | |||||||||
Attachments: |
|
Description
Dani Megert
2010-10-22 10:44:06 EDT
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 |