我正在分析的类:
public class Users{
private String name = "Jacob";
private String address = "711 11th Ave, New York";
private int age = 28;
public String verifyAgeLimit() {
String msg = (this.age < 16) ? " is not allwed to use it." : " is Allwed to use it.";
return this.name+msg;
}
public String showName() {
return "User name is:"+this.name;
}
public String showAddress() {
return this.address;
}
public String hello() {
return "Hello World";
}
}
我正在尝试使用MethodDeclaration获取变量名,但无法做到
public void visit(MethodDeclaration n, Object arg) {
System.out.println(n.getName().toString());//It displays the full method
super.visit(n, arg);
}
我正在尝试获得这个is的输出。
verifyAgeLimit((:this.name或name
verifyAgeLimit((:this.name或name
showAddress((:this.address或address
我试图将整个方法转换为sting,并读取字符串以找出名称,但它变得太复杂,而且非常不准确。
有什么办法解决吗?
所用变量的名称由NameExpr
节点保存,字段由FieldAccessExpr
节点保存。为他们添加一个访问者,或者以其他方式递归到他们。