Bug 82216 - IVariableBinding: Need to know if it is enum constant or normal var
Summary: IVariableBinding: Need to know if it is enum constant or normal var
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-05 04:33 EST by Martin Aeschlimann CLA
Modified: 2005-02-16 09:53 EST (History)
1 user (show)

See Also:


Attachments

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