1
我正在開發一個eclipse插件來分析java源代碼。我遍歷整個AST樹,並寫一個訪問者來訪問每個變量DeclartionStatement,我注意到一些變量,「解析綁定」返回一個IVariableBinding的實例,但其他人不。我無法區分它們。順便說一句:我已經設置了ASTParser.setKind(K_COMPILATION_UNIT)和setResolveBindings(true)。我的代碼如下:爲什麼一些VariableDeclaration resolveBinding返回null,但其他變量不是
@Override
public boolean visit(VariableDeclarationStatement vStatement) {
Type theType = vStatement.getType();
for(Iterator iterator = vStatement.fragments().iterator();iterator.hasNext();){
VariableDeclarationFragment fragment = (VariableDeclarationFragment)iterator.next();
IVariableBinding binding = fragment.resolveBinding();
if(binding !=null){
ITypeBinding tBinding = binding.getType();
if(tBinding !=null){
// if there is ArrayType, get the root type
while(tBinding.getComponentType()!=null){
tBinding = tBinding.getComponentType();
}
System.out.println("USING BINDING VARIABLE CLASS IS: " + tBinding.getQualifiedName());
}
}
}
}
我的問題是:我如何區分變量聲明可以與其他哪些不可以解決的綁定?
預先