Community
Participate
Working Groups
Version: 3.1.0 Build id: I20050509-2010 Steps to reproduce: 1.) Find the attached class Foo and open it 2.) Refactor > Extract Constant on the Method "testFailing()" Actual Results: Refactor is resulting in an Error Expected Results: Refactor working the same way it does when running it on the Method "testWorking()" Regards, Ben
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.