Community
Participate
Working Groups
HEAD class Test { void f(int a) { String str = null; final String ss = ""; switch (a){ case s[CTRL-SPC]: break; } } } In the above snippet str and ss are proposed. But theyre not allowed in java 1.6 and below
There are more cases that should be brought under the ambit of this bug. We should also not propose any non constant variable/field, or methods.
Created attachment 193702 [details] proposed fix v1.0 + regression tests The patch makes sure no non-constant variable, string, or method is proposed inside the case statement since JLS says only constant expressions can be used inside a case. It makes the use of CompletionEngine.isAssistNodeInsideCase field from bug 195346.
Olivier, can you please review? Its a small fix. Thanks! The motivation behind this fix is to make sure strings are proposed only in 1.7 compliance. I'll open another bug for the BETA_JAVA7 branch for that once this is fixed.
Looks good. I guess the fix for compliance 1.7 will be different.
Released in HEAD for 3.7M7
Created attachment 193792 [details] minor update Just noticed that instead of calling the org.eclipse.jdt.internal.codeassist.CompletionEngine.assistNodeIsInsideCase(ASTNode, ASTNode) method in each of completionOn* methods, we can call it once at CompletionEngine#computeExpectedTypes(..). Also, the check for whether to find methods, instead of being done at the call site for findMethods(..) should be done inside findMethods(..) itself, so as to catch all cases where methods are being proposed inside case. This patch consists of just these minor changes.
Released above patch also in HEAD.
Verified.