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