例如,我的代码如下
SomeObject1 obj1 = new SomeObject1();
SomeObject2 obj2 = new SomeObject2();
...
obj1.foo();
obj1.boo();
...
obj2.foo2();
obj2.boo2();我想得到下一个输出:
类型: SomeObject1 名称: obj1 方法: foo,boo ========== 类型: SomeObject2 名称: obj2 调用方法: foo2,boo2
谢谢
UPD:我已经做了一个代码
public boolean visit(VariableDeclarationFragment v)
{
System.out.println("Declaration of " + v.getName().resolveBinding().getKey());
return true;
}
public boolean visit(MethodInvocation inv)
{
Expression e = inv.getExpression();
if(e instanceof Name)
{
Name n = (Name) e;
System.out.println("Calling the method \"" + inv.getName().getFullyQualifiedName() + "\" for " + n.resolveBinding().getKey());
}
return true;
}Ltest/C的声明:\Test\src\Test~Test;..abc)i Ltest/C的声明:\Test\src\Test~Test;..method()V#a Ltest/C的声明:\Test\src\Test~Test;..method()V#url 为Ltest/C调用“替换”方法:\Test\src\Test~Test;. method ()V#url
对于测试代码:
package test;
public class Test
{
private int abc;
public void method()
{
int a;
String url = "ftp://fdh/sdcard/dfsgh";
url.replace("'", ".");
}
}最后两个键是相等的,这意味着我找到了适当的声明。很容易得到变量的类型,我不会发布这个
发布于 2015-06-16 08:44:27
根据这个例子,你需要一个ASTVisitor (除了一个AstParser和它创建的CompilationUnit )。然后,您可以让它访问对象声明的VariableDeclarationFragment和MethodInvocation。方法调用。
https://stackoverflow.com/questions/30862438
复制相似问题