Community
Participate
Working Groups
Build ID: M20071023-1652 Steps To Reproduce: There is a curious behavior of extract method when extracting a code snippet out of a loop after a for(Class var : Colection) construction. More information: Sample Code: ------------------------------------ Line of code to extract: list.add(a++); ------------------------------------ Code where Extract Method returns an int as return value of the extracted snippet: Good Code: ------------------------------------ ArrayList<Integer> list = new ArrayList<Integer>(); int a = 0; for (int c = 0; c < 10; c++) { list.add(a++); } System.out.println(list.toString()); ------------------------------------ Method signature: private static int someMethodName(ArrayList<Integer> list,int a) After adding a for loop in front of the counting loop, the Extract Method return value is void. Bad Code: ------------------------------------ ArrayList<Integer> list = new ArrayList<Integer>(); for (Integer var: list) {} int a = 0; for (int c = 0; c < 10; c++) { list.add(a++); } System.out.println(list.toString()); ------------------------------------ Method signature: private static void someMethodName(ArrayList<Integer> list,int a)
Move to JDT/UI
Markus please investigate.
Created attachment 140727 [details] patch + testcases Attached is a patch with several testcases. The problem was that the LoopReentranceVisitor is only set once with the first occurence of a loop and discarded later if the node under investigation is not part of the loop. I moved the check before the creation of the visitor which matches the right loop. One thing which is still problematic: nested loops. But I think this is worth a FUP of this bug
Thanks, released to HEAD (I added the missing return_out/A_test729.java). > One thing which is still problematic: nested loops. But I think this is worth a > FUP of this bug. Yep, that's a separate (albeit related) problem. Could you please open a new bug, reference this bug's comment 3 in the description (to speed up the analysis when fixing that bug), and add a failing example if possible?
The 'Bad Code' example from comment 0 still doesn't work for me using I20090803-1800 when I just select "list.add(a++)": I get a dialog with a cryptic text. Markus said he'll file a bug for that. Please post it here. As stated in comment 3 and 4 nested loops are still broken and I could not see a new bug yet. Raksha, that's probably the issue you saw. Please file the bug report and post it here.
> The 'Bad Code' example from comment 0 still doesn't work for me using > I20090803-1800 when I just select "list.add(a++)" That's bug 285551.
(In reply to comment #5) > As stated in comment 3 and 4 nested loops are still broken and I could not see > a new bug yet. Raksha, that's probably the issue you saw. Please file the bug > report and post it here. > Filed bug 285554 to track this.
Marking as VERIFIED, given we have the FUPS.
*** Bug 334558 has been marked as a duplicate of this bug. ***
*** Bug 335674 has been marked as a duplicate of this bug. ***