Bug 24324

Summary: AST: IVariableBinding.getModifiers not same as in source
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.1 M2   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Martin Aeschlimann CLA 2002-10-02 12:44:48 EDT
20021001
  interface I {
    int CONST= 1;
  }
  class A {
  void foo() {
    int x= I.CONST;
  }
Create the AST for A and get the IVariableBinding for CONST, 
IVariableBinding.getModifiers returns 'public static final'.

Is this intended or should it be as defined in source?
Comment 1 Olivier Thomann CLA 2002-10-02 14:03:07 EDT
From my point of view, this is intented. A binding is something completely 
resolved. So its modifiers in this case is STATIC, FINAL and PUBLIC.
If you get the declaring node of this binding (a variable declaration fragment)
and get its parents (in order to retrieve the field declaration), you can get 
the modifiers specified in the source.
A code like this does it:
ASTNode declaringNode = unit.findDeclaringNode(variableBinding);
if (declaringNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT) {
   VariableDeclarationFragment variableDeclarationFragment = 
(VariableDeclarationFragment) declaringNode;
  ASTNode parentNode = variableDeclarationFragment.getParent();
  if (parentNode.getNodeType() == ASTNode.FieldDeclaration) {
    int sourceModifiers = ((FieldDeclaration) parentNode).getModifiers();
  }
}
You can adapt that code for VariableDeclarationStatement or other cases you 
need. Only nodes in the tree are supposed to be related to the source. The name 
in binding are fully qualified even if the name in the source is not.
So I close this PR for now as INVALID.