2

I am creating a custom PMD rule for JSP parsing. I have a requirement to visit ASTCompilationUnit and get its end line number. I am using the following code for the same :

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);
} 

While applying this rule, PMD is ignoring this and not visiting to ASTCompilationUnit node. However it is working if ASTCompilationUnit is replace by ASTContent. But my requirement is to get the end line of CompilationUnit of AST as it is the top node of AST. Please help!

The generated AST is:

 <?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>
4
  • Are you able to generate a AST for your JSP? If so, can you post that? Feb 21, 2014 at 14:47
  • Yes I am able to generate AST for the JSP: code <?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> code. The top node is ASTCompilationUnit. But I am not able to visit that node with method defined in AbstractJspRule. Feb 24, 2014 at 5:13
  • Hmm. It seems like that should work. I've edited your post to include the AST. It does look like your ASTCompilationUnit method should match though. Feb 25, 2014 at 2:21
  • yes, even I think it should work. I have written similar kind of rule for java file parsing using ASTCompilationNode which is working fine. But I am not quite sure the issue while JSP parsing. Feb 25, 2014 at 6:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.