给定 ASTNode 如何使用 Eclipse JDT 查找方法主体?

问题描述

我有一个 ASTNode,我需要找出定义这个 ASTNode 的方法名称。如果它在类本身中定义,那么我需要找出类名。

举个例子,ASTNode 指向“\R”,我需要找出它定义的方法,即emitAndindent(String s)。下面的例子:

/** 
 * Emits  {@code s} with indentation as required. It's important that all code that writes to{@link #out} does it through here,since we emit indentation lazily in order to avoidunnecessary trailing whitespace.
 */
CodeWriter emitAndindent(String s) throws IOException {
  boolean first=true;
  for (  String line : s.split("\\R",-1)) {
    if (!first) {
      if ((javadoc || comment) && trailingNewline) {
        emitIndentation();
        out.append(javadoc ? " *" : "//");
      }
      out.append("\n");
      trailingNewline=true;
      if (statementLine != -1) {
        if (statementLine == 0) {
          indent(2);
        }
        statementLine++;
      }
    }
    first=false;
    if (line.isEmpty())     continue;
    if (trailingNewline) {
      emitIndentation();
      if (javadoc) {
        out.append(" * ");
      }
 else       if (comment) {
        out.append("// ");
      }
    }
    out.append(line);
    trailingNewline=false;
  }
  return this;
}

目前,我正在递归检查 newASTNode.parent 和 newASTNode.parent.parent,依此类推。

方法正确吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)