Bug 181867 - [generalize type] ChangeTypeAction does not work when an assignment uses the conditional expression format
Summary: [generalize type] ChangeTypeAction does not work when an assignment uses the ...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-10 19:15 EDT by Steve Luich CLA
Modified: 2022-12-10 12:45 EST (History)
1 user (show)

See Also:


Attachments
test case that does not work (529 bytes, text/java)
2007-04-10 19:17 EDT, Steve Luich CLA
no flags Details
ExampleWorks.java (595 bytes, text/java)
2007-04-10 19:18 EDT, Steve Luich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Luich CLA 2007-04-10 19:15:50 EDT
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:
Comment 1 Steve Luich CLA 2007-04-10 19:17:27 EDT
Created attachment 63451 [details]
test case that does not work
Comment 2 Steve Luich CLA 2007-04-10 19:18:31 EDT
Created attachment 63452 [details]
ExampleWorks.java

This is an equivalent test case where "Generalize Declared Type" does work.
Comment 3 Eclipse Genie CLA 2020-08-27 12:30:27 EDT
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.
Comment 4 Eclipse Genie CLA 2022-12-10 12:45:40 EST
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.