如何使用JDT获取封闭方法节点? [英] How to get the enclosing method node with JDT?

查看:169
本文介绍了如何使用JDT获取封闭方法节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有一个调用bar()的方法foo()时,如何从MethodInvocation节点(或方法中的任何语句/表达式)获取foo()AST节点?例如,我需要知道来自b.bar()的IMethod foo。

  public void foo()
{
b.bar();
}


解决方案

在JDT /一个帮忙的方法来做到这一点。看看 org.eclipse.jdt.internal.corext.dom.ASTNodes.getParent(ASTNode,int)


When I have a method foo() that calls bar(), how can I get the foo() AST node from MethodInvocation node (or whatever statements/expressions in the method)? For example, I need to know the IMethod foo from b.bar().

public void foo()
{
    b.bar();
}

解决方案

In JDT/UI we have a helper method to do this. Take a look at org.eclipse.jdt.internal.corext.dom.ASTNodes.getParent(ASTNode, int)

这篇关于如何使用JDT获取封闭方法节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆