Bug 24324 - AST: IVariableBinding.getModifiers not same as in source
Summary: AST: IVariableBinding.getModifiers not same as in source
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-02 12:44 EDT by Martin Aeschlimann CLA
Modified: 2003-03-23 12:26 EST (History)
0 users

See Also:


Attachments

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