| Summary: | [refactoring] [extract method] Extract Method refactoring fails if trailing ';' is not selected | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Mohsen Vakilian <reprogrammer> |
| Component: | UI | Assignee: | Deepak Azad <deepakazad> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | deepakazad, djanoiup, nchen, reprogrammer, snegara2 |
| Version: | 3.8 | ||
| Target Milestone: | 3.8 M5 | ||
| Hardware: | PC | ||
| OS: | All | ||
| Whiteboard: | |||
|
Description
Mohsen Vakilian
The if condition in ExtractMethodAnalyzer.visit(Assignment) does not look perfect. What about using this:
if ((getSelection().covers(node.getLeftHandSide()) && !getSelection().covers(node.getRightHandSide())) || getSelection().coveredBy(node.getLeftHandSide())) {
(In reply to comment #2) > if ((getSelection().covers(node.getLeftHandSide()) && > !getSelection().covers(node.getRightHandSide())) || > getSelection().coveredBy(node.getLeftHandSide())) { Thanks! That works. Fixed in master - 371ad683cf46d904a9c00c3494d31522d33f5b08 Note that the result is slightly different when you select 'i = 0;' or 'i = 0', but I think that is OK. (In reply to comment #3) > Note that the result is slightly different when you select 'i = 0;' or 'i = 0' How are the results different? (In reply to comment #4) > How are the results different? New method with ; selected private void extracted() { field = 1; } New method with ; NOT selected private int extracted() { return field = 1; } Full code snippets are available here - http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=371ad683cf46d904a9c00c3494d31522d33f5b08 (In reply to comment #5) > (In reply to comment #4) > > How are the results different? > > New method with ; selected > private void extracted() { > field = 1; > } > > New method with ; NOT selected > private int extracted() { > return field = 1; > } > > Full code snippets are available here - > http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=371ad683cf46d904a9c00c3494d31522d33f5b08 Deepak, Thanks for pointing me to the examples. The different behaviors in the above two cases seem consistent with how Eclipse handles other similar selections. I will try a few more examples when a build of Eclipse that contains your patch appears at http://download.eclipse.org/eclipse/downloads/ |