2014-03-31 31 views
0
VariableDeclarationFragment node; 

SimpleName name = node.getName(); 

如果node.getName()String類型的使用ASTParser可變的,則輸出應該String。 如果node.getName()Integer類型,則輸出應爲Integer數據類型在Java

有沒有辦法使用ASTParser或以其他方式做到這一點?

+0

可能的[Java JDT parser。獲取變量類型的VariableDeclarationFragment](http://stackoverflow.com/questions/18454697/java-jdt-parser-get-variable-type-of-variabledeclarationfragment) –

回答

0

您可以在VariableDeclarationFragment上使用resolveBinding()操作。它將變量與其類型關聯起來。取決於AST結構的狀態,綁定可能不可用。