Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 343476

Summary: [1.7][assist] propose String variables and fields inside switch case.
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: Olivier_Thomann, srikanth_sankaran
Version: 3.7Flags: Olivier_Thomann: review+
Target Milestone: 3.7.1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
proposed fix v1.0 + regression tests
none
released patch none

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"