我有一些javascript文件,并使用Rhino的javascript解析器解析它.
但我无法得到评论.
我怎样才能得到评论?
这是我的代码的一部分.
运行此代码,"comment"变量为null.另外,在运行"astRoot.toSource();"时,它只显示javascript代码.没有评论.它消失了!
[java code]
public void parser() {
AstRoot astRoot = new Parser().parse(this.jsString, this.uri, 1);
List<AstNode> statList = astRoot.getStatements();
for(Iterator<AstNode> iter = statList.iterator(); iter.hasNext();) {
FunctionNode fNode = (FunctionNode)iter.next();
System.out.println("*** function Name : " + fNode.getName() + ", paramCount : " + fNode.getParamCount() + ", depth : " + fNode.depth());
AstNode bNode = fNode.getBody();
Block block = (Block)bNode;
visitBody(block);
}
System.out.println(astRoot.toSource());
SortedSet<Comment> comment = astRoot.getComments();
if(comment == null)
System.out.println("comment is null");
}
Run Code Online (Sandbox Code Playgroud)