【问题标题】:Get IMethod from the method name in java从java中的方法名获取IMethod
【发布时间】:2017-02-21 09:59:14
【问题描述】:

我正在寻找一种查找 IMethod 的方法,将方法名称作为进一步开发我的 eclipse 插件的输入。

想不出办法。

谁能指引我正确的道路。

【问题讨论】:

  • 方法名不唯一,同名方法可以存在于同一个类(重载)或其他类中。您还向插件传递了什么输入?
  • 感谢您的回复。我可以给出方法名称和参数以区别于其他方法

标签: java eclipse plugins eclipse-jdt


【解决方案1】:

有两种方法:

  1. 您可以使用ASTVisitor 模式访问MethodDeclaration 节点,检查名称和参数,并通过解析绑定从它们获取IMethod。参考以下帖子:

  2. 从编译单元获取ITypes 并循环通过IMethods,检查名称和参数以找到所需的。

    IType [] typeDeclarationList = unit.getTypes();
    for (IType typeDeclaration : typeDeclarationList) {
       // Get methods under each type declaration.
       IMethod [] methodList = typeDeclaration.getMethods();
       for (IMethod method : methodList) {
          // Logic here.
       }
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多