Take the 2-minute tour ×

I want to get the information about a field modifier. To be precise, I want to find out is the field a static one. For example, I want to examine the following code:

ASTParser parser = ASTParser.newParser(AST.JLS3);

How can I infer that the JLS3 is static field? I used getModifiers with Modifier.isStatic when analyzing methods and it worked fine. However, now I am not able to get the information that JLS3 in above code snippet is a static field. Is there something I am missing?


This is the code that I am using:

private boolean visit(SimpleName name){
   boolean isStatic = Modifier.isStatic(name.resolveTypeBinding().getModifiers());
   return true;

isStatic is false in the case of JLS3.

share|improve this question
getModifiers should work for both FieldDeclaration and MethodDeclaration. Can you post your code and the exact problem that you face, e.g. method call which is giving unexpected results. –  Deepak Azad Sep 22 '12 at 14:44
I've added the code. –  bellpeace Sep 22 '12 at 19:32
add comment

1 Answer

up vote 3 down vote accepted

That's obviously wrong, use name.resolveBinding() instead of name.resolveTypeBinding() --- so you should get an object of type IVariableBinding.

name.resolveTypeBinding() returns the binding for the type of the field, but not the binding of field itself, which is not what you want here.

share|improve this answer
add comment

Your Answer


