Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 给定一个ASTNode,如何使用EclipseJDT查找方法体?_Java_Eclipse_Eclipse Jdt - Fatal编程技术网

Java 给定一个ASTNode,如何使用EclipseJDT查找方法体?

Java 给定一个ASTNode,如何使用EclipseJDT查找方法体?,java,eclipse,eclipse-jdt,Java,Eclipse,Eclipse Jdt,我有一个ASTNode,我需要找出定义这个ASTNode的方法名。如果它是在类本身中定义的,那么我需要找出类名 例如,ASTNode指向“\R”,我需要找出定义它的方法,即emittendindent(字符串s)。示例如下: /** * Emits {@code s} with indentation as required. It's important that all code that writes to{@link #out} does it through here, sinc

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

例如,ASTNode指向“\R”,我需要找出定义它的方法,即
emittendindent(字符串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,依此类推


方法正确吗?

我不理解您的代码以及它与您的问题的关系,因为它不包含
ASTNode
。您可以看看@howlger,我给出了一个代码示例,其中我必须提取
emittendindent
的主体。