Community
Participate
Working Groups
Build ID: M20070212-1330 Steps To Reproduce: I discovered this bug while developing for our product Jtest in "org.eclipse.jdt.ui.actions.ChangeTypeAction". (Jtest also uses this action) 1. I will attach the ".java" files, but the basic idea is that I have the following two classes: public class ExampleBroken { private Map _previousTrackedVariables = new MyProperties(); void method() { MyProperties trackedVariables= null; //CANNOT generalize the type to "Map" _previousTrackedVariables = (trackedVariables == null) ? new MyProperties() : trackedVariables; } private class MyProperties extends Hashtable { } } and public class ExampleWorks { private Map _previousTrackedVariables = new MyProperties(); void method() { MyProperties trackedVariables= null; //CAN generalize the type to "Map" if(trackedVariables == null){ _previousTrackedVariables = new MyProperties(); } else { _previousTrackedVariables = trackedVariables; } } private class MyProperties extends Hashtable { } } Notice that the methods "method()" are equivalent in the two classes except that one uses the conditional expression syntax "? :" for the assignment and the other expands this into an "if-else" statement. Still, the semantics are the same. 2. Highlight "MyProperties" in the first line of "method()" in "ExampleBroken" in the Eclipse editor. Right-click and select "Refactor > Generalize Declared Type". Notice that it is unable to generalize the type. The dialog comes up with the error message "Type of selected declaration cannot be changed". 3. Highlight "MyProperties" in the first line of "method()" in "ExampleWorks" in the Eclipse editor. Right-click and select "Refactor > Generalize Declared Type". Notice that it is able to generalize the type to "Map". Expected: I expect the "Generalize Declared Type" feature to be able to generalize the type of "trackedVariables" to "java.util.Map" in both classes since the two classes are semantically the same. Observed: "Generalize Declared Type" only works in "ExampleWorks" but not in "ExampleBroken". More information:
Created attachment 63451 [details] test case that does not work
Created attachment 63452 [details] ExampleWorks.java This is an equivalent test case where "Generalize Declared Type" does work.
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. If you have further information on the current state of the bug, please add it. 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.