Bug 387797 - [quick fix] Extract to ... creates compile error due to hidden type
Summary: [quick fix] Extract to ... creates compile error due to hidden type
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-22 10:37 EDT by Peter CLA
Modified: 2013-07-23 06:46 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter CLA 2012-08-22 10:37:43 EDT
If i extract values to fields, variables or constants: If the returning-interface is hidden in the package-scope the hidden returntype is used anyway!

In example:
This constalation create a Compiler Warning:
  You have 2 Interface and 2 Classes:
  Interface 1: 
    package sumsum;
    public interface Show {}

  Interface 2:
    package sumsum;
    interface Hide extends Show{
      String getText();
    }

  Class 1:
    package sumsum;
    public class Case{
      public static Hide getA(){return null;} 
    }
    
  Class 2:
    package org.dontknow.jack;
    class Main{
      public static void main(String[]args){
        Case.getA();
        // Ok, now i do a Extract to ... will produce:
        Hide a = Case.getA();
        // Stop now! The compiler sais he dont know anything 'bout the class "Hide"!
        // Wouldnt it even better to have a result like:
        Show a = Case.getA();
        // Well, even the method Hide.getText isnt accessible anymore.        
        // I accept that eclipse wouldnt know what a interface you like to have, so 
        // cant you guys show a modal Dropdown of Resulting Types?        
      }
    }

I hope i can reproduce what i am missing.

Regards
Comment 1 Srikanth Sankaran CLA 2012-08-22 20:47:33 EDT
Forward to UI for comment.
Comment 2 Dani Megert CLA 2012-08-23 07:26:08 EDT
Test Case for easy pasting:

    package sumsum;
    public interface Show {}

    package sumsum;
    interface Hide extends Show{
      String getText();
    }
    
    package sumsum;
    public class Case{
      public static Hide getA(){return null;} 
    }
    
    package org.dontknow.jack;
    import sumsum.Case;
    class Main{
      public static void main(String[]args){
        Case.getA(); // <- extract this
      }
    }
Comment 3 Martin Mathew CLA 2013-06-27 02:34:31 EDT
Reproducible using Eclipse build id: I20130618-0800
During refactoring user is informed about the visibility issue of the type being extracted to. As suggested in the bug report, if refactoring encounter such a visibility issue, then it will be good to give user options of valid types to choose from, so that we can avoid the compiler error after the refactoring.
Comment 4 Dani Megert CLA 2013-06-27 08:17:23 EDT
(In reply to comment #3)
> Reproducible using Eclipse build id: I20130618-0800
> During refactoring user is informed about the visibility issue of the type
> being extracted to. 

This is not what I see using R4.3 when invoking Extract Method on the snippet from comment 1. Also the Extract to ... Quick Fixes fail with an error - no dialog or warning is shown.
Comment 5 Martin Mathew CLA 2013-07-23 06:46:25 EDT
(In reply to comment #4)
> This is not what I see using R4.3 when invoking Extract Method on the
> snippet from comment 1. 
Refactor> Extract Local Variable... and Refactor> Extract Constant... informs user about the visibility issue. But i understand that user here is talking about the quick assist options available and yes currently we do not give any warning regarding the visibility issues in this case.

> Also the Extract to ... Quick Fixes fail with an
> error - no dialog or warning is shown.
Though user ends up with a compiler error after the quick assist, I did not see the quick assist failing with an error.

The improvement user is asking for (having a drop down to select from one of the possible types) can be taken up as an enhancement.