| Summary: | [extract constant] computes wrong insertion point with generic type using wildcard | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Benjamin Pasero <ENJ> | ||||
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | ||||||
| Version: | 3.1 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | stalebug | ||||||
| Attachments: |
|
||||||
|
Description
Benjamin Pasero
Created attachment 20939 [details]
Class Foo
Sorry, Caret has to be placed inside the field inside the Method Body, not the Method Name. Ben import java.util.ArrayList;
public class Foo {
static ArrayList<? extends Number> alFailing = new ArrayList<Integer>();
static ArrayList alWorking = new ArrayList<Integer>();
void testWorking() {
alWorking.get(0); // extract "alWorking" -> OK
}
void testFailing() {
alFailing.get(0); // extract "alFailing" -> compile error
}
}
The problem is that
private static final ArrayList<? extends Number> AL_FAILING = alFailing;
is inserted as first body declaration, which gives compile error
"Cannot reference a field before it is defined"
The bug in the implementation is that ExtractConstantRefactoring#depends(IExpressionFragment, BodyDeclaration) eventually uses JdtASTMatcher#match(SimpleName, Object) to find occurrences of "alFailing", and the implementation of match(..) ends with
if (node.resolveTypeBinding() != name.resolveTypeBinding())
This fails to find the dependency in this case, since the declaration and the reference resolve to ArrayList with different type arguments (separate captures of the wildcard).
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. |