Bug 133562 - Extract to local variable generates variable called 'enum'
Summary: Extract to local variable generates variable called 'enum'
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-28 10:40 EST by Benno Baumgartner CLA
Modified: 2006-04-13 10:34 EDT (History)
0 users

See Also:


Attachments
Proposed fix (2.84 KB, patch)
2006-03-28 15:04 EST, Olivier Thomann CLA
no flags Details | Diff
Regression test (1.72 KB, patch)
2006-03-28 15:06 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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