View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.jsp.rule;
5   
6   import java.util.List;
7   
8   import net.sourceforge.pmd.RuleContext;
9   import net.sourceforge.pmd.lang.Language;
10  import net.sourceforge.pmd.lang.ast.Node;
11  import net.sourceforge.pmd.lang.jsp.ast.ASTAttribute;
12  import net.sourceforge.pmd.lang.jsp.ast.ASTAttributeValue;
13  import net.sourceforge.pmd.lang.jsp.ast.ASTCData;
14  import net.sourceforge.pmd.lang.jsp.ast.ASTCommentTag;
15  import net.sourceforge.pmd.lang.jsp.ast.ASTCompilationUnit;
16  import net.sourceforge.pmd.lang.jsp.ast.ASTContent;
17  import net.sourceforge.pmd.lang.jsp.ast.ASTDeclaration;
18  import net.sourceforge.pmd.lang.jsp.ast.ASTDoctypeDeclaration;
19  import net.sourceforge.pmd.lang.jsp.ast.ASTDoctypeExternalId;
20  import net.sourceforge.pmd.lang.jsp.ast.ASTElExpression;
21  import net.sourceforge.pmd.lang.jsp.ast.ASTElement;
22  import net.sourceforge.pmd.lang.jsp.ast.ASTHtmlScript;
23  import net.sourceforge.pmd.lang.jsp.ast.ASTJspComment;
24  import net.sourceforge.pmd.lang.jsp.ast.ASTJspDeclaration;
25  import net.sourceforge.pmd.lang.jsp.ast.ASTJspDirective;
26  import net.sourceforge.pmd.lang.jsp.ast.ASTJspDirectiveAttribute;
27  import net.sourceforge.pmd.lang.jsp.ast.ASTJspExpression;
28  import net.sourceforge.pmd.lang.jsp.ast.ASTJspExpressionInAttribute;
29  import net.sourceforge.pmd.lang.jsp.ast.ASTJspScriptlet;
30  import net.sourceforge.pmd.lang.jsp.ast.ASTText;
31  import net.sourceforge.pmd.lang.jsp.ast.ASTUnparsedText;
32  import net.sourceforge.pmd.lang.jsp.ast.ASTValueBinding;
33  import net.sourceforge.pmd.lang.jsp.ast.JspNode;
34  import net.sourceforge.pmd.lang.jsp.ast.JspParserVisitor;
35  import net.sourceforge.pmd.lang.rule.AbstractRule;
36  import net.sourceforge.pmd.lang.rule.ImmutableLanguage;
37  
38  public abstract class AbstractJspRule extends AbstractRule implements JspParserVisitor, ImmutableLanguage {
39      
40      public AbstractJspRule() {
41  	super.setLanguage(Language.JSP);
42      }
43  
44      @Override
45      public void setUsesTypeResolution() {
46  	// No Type resolution for JSP rules?
47      }
48  
49      public void apply(List<? extends Node> nodes, RuleContext ctx) {
50  	visitAll(nodes, ctx);
51      }
52  
53      protected void visitAll(List<? extends Node> nodes, RuleContext ctx) {
54  	for (Object element : nodes) {
55  	    JspNode node = (JspNode) element;
56  	    visit(node, ctx);
57  	}
58      }
59  
60      //
61      // The following APIs are identical to those in JspParserVisitorAdapter.
62      // Due to Java single inheritance, it preferred to extend from the more
63      // complex Rule base class instead of from relatively simple Visitor.
64      //
65  
66      public Object visit(JspNode node, Object data) {
67  	node.childrenAccept(this, data);
68  	return null;
69      }
70  
71      public Object visit(ASTCompilationUnit node, Object data) {
72  	return visit((JspNode) node, data);
73      }
74  
75      public Object visit(ASTContent node, Object data) {
76  	return visit((JspNode) node, data);
77      }
78  
79      public Object visit(ASTJspDirective node, Object data) {
80  	return visit((JspNode) node, data);
81      }
82  
83      public Object visit(ASTJspDirectiveAttribute node, Object data) {
84  	return visit((JspNode) node, data);
85      }
86  
87      public Object visit(ASTJspScriptlet node, Object data) {
88  	return visit((JspNode) node, data);
89      }
90  
91      public Object visit(ASTJspExpression node, Object data) {
92  	return visit((JspNode) node, data);
93      }
94  
95      public Object visit(ASTJspDeclaration node, Object data) {
96  	return visit((JspNode) node, data);
97      }
98  
99      public Object visit(ASTJspComment node, Object data) {
100 	return visit((JspNode) node, data);
101     }
102 
103     public Object visit(ASTText node, Object data) {
104 	return visit((JspNode) node, data);
105     }
106 
107     public Object visit(ASTUnparsedText node, Object data) {
108 	return visit((JspNode) node, data);
109     }
110 
111     public Object visit(ASTElExpression node, Object data) {
112 	return visit((JspNode) node, data);
113     }
114 
115     public Object visit(ASTValueBinding node, Object data) {
116 	return visit((JspNode) node, data);
117     }
118 
119     public Object visit(ASTCData node, Object data) {
120 	return visit((JspNode) node, data);
121     }
122 
123     public Object visit(ASTElement node, Object data) {
124 	return visit((JspNode) node, data);
125     }
126 
127     public Object visit(ASTAttribute node, Object data) {
128 	return visit((JspNode) node, data);
129     }
130 
131     public Object visit(ASTAttributeValue node, Object data) {
132 	return visit((JspNode) node, data);
133     }
134 
135     public Object visit(ASTJspExpressionInAttribute node, Object data) {
136 	return visit((JspNode) node, data);
137     }
138 
139     public Object visit(ASTCommentTag node, Object data) {
140 	return visit((JspNode) node, data);
141     }
142 
143     public Object visit(ASTDeclaration node, Object data) {
144 	return visit((JspNode) node, data);
145     }
146 
147     public Object visit(ASTDoctypeDeclaration node, Object data) {
148 	return visit((JspNode) node, data);
149     }
150 
151     public Object visit(ASTDoctypeExternalId node, Object data) {
152 	return visit((JspNode) node, data);
153     }
154 
155     public Object visit(ASTHtmlScript node, Object data) {
156 	return visit((JspNode) node, data);
157     }
158 }