| Summary: | Extract variable (replace all occurrences) replaces only selected one | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Andrey Loskutov <loskutov> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jarthana, noopur_gupta, stephan.herrmann |
| Version: | 4.7 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | stalebug | ||
The problem seem to be with the type parameter on the list, because extract with the code below works fine:
int hello2(List list) {
if(list.size() == 1 || list.size() ==2){
return list.size();
}
System.out.println(list.size());
return list.size();
}
Looks like we decide that List<?> is not same as list<?>, which may be true. Noopur, can you please confirm if my finding is true? (In reply to Jay Arthanareeswaran from comment #2) > Looks like we decide that List<?> is not same as list<?>, which may be true. I didn't get this. The variable type is same inside the method in all occurences, so whatever type it has (may be just Object), it could be extracted? (In reply to Andrey Loskutov from comment #3) > (In reply to Jay Arthanareeswaran from comment #2) > > Looks like we decide that List<?> is not same as list<?>, which may be true. > > I didn't get this. The variable type is same inside the method in all > occurences, so whatever type it has (may be just Object), it could be > extracted? Each evaluation of an expression with a wildcarded type (here: 'list') creates a fresh capture type. This accommodates the fact that reassigning different values to the same variable could indeed result in 'list' having different types over time. (In reply to Stephan Herrmann from comment #4) > (In reply to Andrey Loskutov from comment #3) > > (In reply to Jay Arthanareeswaran from comment #2) > > > Looks like we decide that List<?> is not same as list<?>, which may be true. > > > > I didn't get this. The variable type is same inside the method in all > > occurences, so whatever type it has (may be just Object), it could be > > extracted? > > Each evaluation of an expression with a wildcarded type (here: 'list') > creates a fresh capture type. This accommodates the fact that reassigning > different values to the same variable could indeed result in 'list' having > different types over time. I still didn't get this: in the given example, the expression result type is int. Does it really matter which types (wildcard or not) are involved in the expression if the result type is same and not wildcard type? (In reply to Andrey Loskutov from comment #5) > (In reply to Stephan Herrmann from comment #4) > > (In reply to Andrey Loskutov from comment #3) > > > (In reply to Jay Arthanareeswaran from comment #2) > > > > Looks like we decide that List<?> is not same as list<?>, which may be true. > > > > > > I didn't get this. The variable type is same inside the method in all > > > occurences, so whatever type it has (may be just Object), it could be > > > extracted? > > > > Each evaluation of an expression with a wildcarded type (here: 'list') > > creates a fresh capture type. This accommodates the fact that reassigning > > different values to the same variable could indeed result in 'list' having > > different types over time. > > I still didn't get this: in the given example, the expression result type is > int. Does it really matter which types (wildcard or not) are involved in the > expression if the result type is same and not wildcard type? good point. I haven't debugged this. Only tried to explain, why indeed different (incompatible) types could be involved. But I agree those probably shouldn't matter. This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
4.7 build I20170417-2000. Try to extract list.size() to the variable via Ctrl+1 -> Extract variable (replace all occurrences): import java.util.List; public class X { int hello(List<?> list) { if(list.size() == 1 || list.size() ==2){ return list.size(); } System.out.println(list.size()); return list.size(); } } It will always replace only one selected part, but never all occurrences!