Community
Participate
Working Groups
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?
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.