簡體   English   中英

如何獲取ASTVisitor節點的全名

[英]How to get the full name of an ASTVisitor node

我實現了一個AST訪問器,該訪問器訪問每個“方法調用”節點。 方法

node.getName()

給了我方法的名稱,但是我想知道全名Package.Class.Method。 我敢肯定有一種簡單的方法可以使我丟失,但是我卻找不到任何東西。 這是我到目前為止的內容:

public boolean visit(MethodInvocation node) {
    assert callmap.containsKey(curMethod);
    String m = node.getName().toString();
    callmap.get(curMethod).add(m);
    return false; // do not continue to avoid usage info
}

如何獲得此方法的全名?

您應該使用類似這樣的東西:

    IMethodBinding binding = node.resolveMethodBinding();        
    ITypeBinding typeBinding = expression.resolveTypeBinding();
    ITypeBinding type = binding.getDeclaringClass();        
    Expression expression = node.getExpression();


    System.out.println("Type: " + typeBinding.getName());

從文檔中,我發現了許多所需的方法: http : //help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt %2Fcore%2Fdom%2FMethodInvocation.html

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FIMethodBinding.html

http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FITypeBinding.html

嘗試檢查我給你的所有可變方法

您的問題類似於如何使用Eclipse JDT ASTParser獲得方法的類名?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM