I have implemented an AST visitor, which visits every Method Invocation node. The method

node.getName()

gives me the name of the method, but I want to know the full name, Package.Class.Method. I'm sure there is an easy way to get this that I am missing, but I have not been able to find anything. Here is what I have so far:

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
}

How can I get the full name of this method?

有帮助吗?

解决方案

You should use something like that :

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


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

From the doc i have found many method that you want : 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

Try to check all method from varaible i have give you

Your question look similar to How to get a class name of a method by using Eclipse JDT ASTParser?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top