我正在为JSP解析创建自定义PMD规则。我需要访问ASTCompilationUnit并获取其结束行号。我使用以下代码:
public class MyCustomRule extends AbstractJspRule {
//
@Override
public Object visit(ASTCompilationUnit node, Object data) {
logger.log(Level.INFO, "***INSIDE COMPILATION UNIT END LINE IN JSP***" + node.getEndLine());
return super.visit(node, data);
}
在应用此规则时,PMD忽略此规则而不访问ASTCompilationUnit节点。 但是,如果ASTCompilationUnit被ASTContent替换,它就可以工作。但我的要求是获得AST的CompilationUnit的结束行,因为它是AST的顶级节点。 请帮忙!
生成的AST是:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CompilationUnit BeginColumn="1" BeginLine="13" EndColumn="2" EndLine="13" Image="" Label="">
<Content BeginColumn="1" BeginLine="1" EndColumn="7" EndLine="12" Image="" Label="">
<!-- Other AST NODES-->
</Content>
</CompilationUnit>