Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343476 - [1.7][assist] propose String variables and fields inside switch case.
Summary: [1.7][assist] propose String variables and fields inside switch case.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.7.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-21 02:21 EDT by Ayushman Jain CLA
Modified: 2011-08-05 02:54 EDT (History)
2 users (show)

See Also:
Olivier_Thomann: review+


Attachments
proposed fix v1.0 + regression tests (8.50 KB, patch)
2011-04-21 08:53 EDT, Ayushman Jain CLA
no flags Details | Diff
released patch (8.55 KB, patch)
2011-04-21 10:02 EDT, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2011-04-21 02:21:44 EDT
BETA_JAVA7

After the fix for bug 343342, we no longer propose strings inside the case expression. We should suggest them if the compliance is 1.7 or greater and the switch is done on a string type

public class Try {
     void f(String a) {
	 String xyz = null;
         final String xyzz = "";
         switch (a){    
            case xy[CTRL-SPACE]: break;    // propose xyz and xyzz here
         }
      }
}
Comment 1 Ayushman Jain CLA 2011-04-21 08:53:37 EDT
Created attachment 193812 [details]
proposed fix v1.0 + regression tests

This fix follows from the fix for bug 343342, and makes sure that not only are strings proposed in compliance >= 1.7, but also that they are proposed only when the switch has been done on a string
Comment 2 Ayushman Jain CLA 2011-04-21 08:58:57 EDT
Olivier, can you please review, time permitting? Thanks!

With this fix, we'll atleast be more relevant in the proposals we give for switch case in all compliance levels.
Comment 3 Olivier Thomann CLA 2011-04-21 09:26:58 EDT
Looks good.
I would make a small change though.
Instead of testing == with scope.getJavaLangString().

We can simply test == with the binding id and org.eclipse.jdt.internal.compiler.lookup.TypeIds.T_JavaLangString. This of course means that we have to make sure the binding is not null before we get its id.
Comment 4 Ayushman Jain CLA 2011-04-21 10:02:03 EDT
Created attachment 193824 [details]
released patch

Same fix with the change suggested by Olivier.
Comment 5 Ayushman Jain CLA 2011-04-21 10:02:48 EDT
Released in BETA_JAVA7 branch.
Comment 6 Srikanth Sankaran CLA 2011-06-29 02:02:21 EDT
Note that as opposed to what the comment in the code snippet claims,
we propose only xyzz (which is as it should be).

Verified using "Eclipse Java Development Tools Patch for Java 7 Support (BETA)	1.0.0.v20110623-0900	org.eclipse.jdt.patch.feature.group	Eclipse.org"