Bug 133562

Summary: Extract to local variable generates variable called 'enum'
Product: [Eclipse Project] JDT Reporter: Benno Baumgartner <benno.baumgartner>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Regression test none

Description Benno Baumgartner CLA 2006-03-28 10:40:32 EST
Given:
public void foo(Object o) {
	System.out.println(o.getClass().isEnum());
}

1. Select 'o.getClass().isEnum()'
2. Extract to local variable
Is:
public void foo(Object o) {
	boolean enum = o.getClass().isEnum();
	System.out.println(enum);
}
Should:
something else then 'enum' since in 1.5 enum is a keyword.
Comment 1 Martin Aeschlimann CLA 2006-03-28 12:23:39 EST
Moving to jdt.core: We're using NamingConventions.suggestLocalVariableNames to get a name.
Comment 2 Olivier Thomann CLA 2006-03-28 14:28:31 EST
The problem comes from the fact that the call JavaConventions.validateFieldName(new String(suffixName)) returns true even if the field name is a keyword. The scanner used by JavaConventions is used in 1.3 mode. So technically assert or enum can be returned as valid identifiers (field or variable names).
Comment 3 Olivier Thomann CLA 2006-03-28 15:04:53 EST
Created attachment 37130 [details]
Proposed fix
Comment 4 Olivier Thomann CLA 2006-03-28 15:05:13 EST
With this patch, "enum1" is returned.
Comment 5 Olivier Thomann CLA 2006-03-28 15:06:29 EST
Created attachment 37132 [details]
Regression test
Comment 6 Olivier Thomann CLA 2006-04-05 14:59:50 EDT
Fixed and released in HEAD.
Regression tests added in org.eclipse.jdt.core.tests.model.NamingConventionTests.testSuggestLocalName001/testSuggestLocalName002
Comment 7 Philipe Mulet CLA 2006-04-09 07:24:28 EDT
+1 for 3.2RC1
Comment 8 David Audel CLA 2006-04-13 10:34:07 EDT
Verified for 3.2 RC1 using build I20060413-0010