简体   繁体   中英

Eclipse JDT AST: check if SimpleName is a variable identifier

I'm trying to list all variables used in an Expression node. I've created a visitor to SimpleName node but this captures all identifiers like function calls, class names etc. How do I check if a SimpleName node is identifier of a variable?

Type binding of the node gives this information

example for variable:

SimpleName simpleName = //initialize variable;
if (simpleName.resolveBinding() instanceof VariableBinding){
    // simpleName is a variable identifier
}
if (simpleName.resolveBinding() instanceof MethodBinding){
    // simpleName is a method identifier
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM