-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix extract method false negative on local variable usage (#1418)
- fix ExtractMethodAnalyzer.computeOutput() method to add a check for local variables that have been added to the returnValues list but the declaration and all references are within the selected region - add new test to ExtractMethodTests - fixes #1292
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
....refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/locals_in/A_test579.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package locals_in; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
public class A_test579 { | ||
public static void foo(List<String> defs) { | ||
List<String> newDefs= new ArrayList<>(); | ||
|
||
for (String rule : defs) { | ||
/*]*/boolean isLeftRecursive= false; | ||
if (!isLeftRecursive) { | ||
continue; | ||
} | ||
|
||
List<String> oldRules= new ArrayList<String>(); | ||
List<String> newSuffixes= new ArrayList<String>(); | ||
|
||
newDefs.addAll(oldRules); | ||
newDefs.addAll(newSuffixes);/*[*/ | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/locals_out/A_test579.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package locals_out; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
public class A_test579 { | ||
public static void foo(List<String> defs) { | ||
List<String> newDefs= new ArrayList<>(); | ||
|
||
for (String rule : defs) { | ||
/*]*/extracted(newDefs);/*[*/ | ||
} | ||
} | ||
|
||
protected static void extracted(List<String> newDefs) { | ||
boolean isLeftRecursive= false; | ||
if (!isLeftRecursive) { | ||
return; | ||
} | ||
|
||
List<String> oldRules= new ArrayList<String>(); | ||
List<String> newSuffixes= new ArrayList<String>(); | ||
|
||
newDefs.addAll(oldRules); | ||
newDefs.addAll(newSuffixes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters