Java 给定一个ASTNode,如何使用EclipseJDT查找方法体?
我有一个ASTNode,我需要找出定义这个ASTNode的方法名。如果它是在类本身中定义的,那么我需要找出类名 例如,ASTNode指向“\R”,我需要找出定义它的方法,即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
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
的主体。