Bug 82216

Summary: IVariableBinding: Need to know if it is enum constant or normal var
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jeem
Version: 3.0   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Martin Aeschlimann CLA 2005-01-05 04:33:44 EST
20050105

public enum E {
	A, B, C;
	
	public static final int X= 9;
}

Get the IVariableBindings for E. I would like to know which of the variables are
enum constant declarations and which not.
Possibilities to fix this would be new API 'Modifier.isEnum(modifiers)' or
something like 'IVariableBinding.isEnumConstant()'
Comment 1 Olivier Thomann CLA 2005-01-05 09:11:38 EST
Jim, any comment?
Comment 2 Jim des Rivieres CLA 2005-01-05 09:46:54 EST
The case is even more interesting when the enum has self-typed fields; i.e.,
public enum E {
	A, B, C;
	public static E D;
}
Checking whether the variable's type is the same enum type as the variable's 
declaring class would not cut it.

Adding IVariableBinding.isEnumConstant() feels like a good approach.
Comment 3 Jim des Rivieres CLA 2005-01-05 12:30:09 EST
Adding API IVariableBinding.isEnumConstant(). 

I also clarified the spec for IVariableBinding.getConstantValue() to specify
that it returns null for enum constants. This approach is consistent with
JLS3 15.28, which does not consider enumeration types to be compile-time 
constant expressions.

Olivier, please complete VariableBinding.isEnumConstant() implementation and 
add tests.
Comment 4 Olivier Thomann CLA 2005-01-05 14:16:44 EST
The test needs to be done on the modifiers of the binding. An enum constant has
AccEnum is its bits.
Fixed and released in HEAD.
Regression test added in ASTConverter15Test.test0100.
Comment 5 David Audel CLA 2005-02-16 09:53:17 EST
Verified in I20050215-2300