View Javadoc

1   /**
2    * Redistribution  and use  in source  and binary  forms, with  or without
3    * modification, are permitted provided  that the following conditions are
4    * met :
5    *
6    * . Redistributions  of  source  code  must  retain  the  above copyright
7    *   notice, this list of conditions and the following disclaimer.
8    *
9    * . Redistributions in  binary form  must reproduce  the above  copyright
10   *   notice, this list of conditions  and the following disclaimer in  the
11   *   documentation and/or other materials provided with the distribution.
12   *
13   * . The name of the author may not be used to endorse or promote products
14   *   derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS  PROVIDED BY THE  AUTHOR ``AS IS''  AND ANY EXPRESS  OR
17   * IMPLIED  WARRANTIES,  INCLUDING,  BUT   NOT  LIMITED  TO,  THE   IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE ARE
19   * DISCLAIMED.  IN NO  EVENT SHALL  THE AUTHOR  BE LIABLE  FOR ANY  DIRECT,
20   * INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL  DAMAGES
21   * (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT OF  SUBSTITUTE  GOODS OR
22   * SERVICES;  LOSS  OF USE,  DATA,  OR PROFITS;  OR  BUSINESS INTERRUPTION)
23   * HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN  CONTRACT,
24   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE, EVEN  IF  ADVISED OF  THE
26   * POSSIBILITY OF SUCH DAMAGE.
27   */
28  
29  package cppncss.counter;
30  
31  import cppast.AstBreakStatement;
32  import cppast.AstCaseStatement;
33  import cppast.AstCatchBlock;
34  import cppast.AstConstructorDeclaration;
35  import cppast.AstConstructorInitializer;
36  import cppast.AstContinueStatement;
37  import cppast.AstDeclaration;
38  import cppast.AstDeclarationStatement;
39  import cppast.AstDefaultStatement;
40  import cppast.AstDestructorDeclaration;
41  import cppast.AstElseStatement;
42  import cppast.AstExpressionStatement;
43  import cppast.AstFunctionBody;
44  import cppast.AstFunctionDeclaration;
45  import cppast.AstGotoStatement;
46  import cppast.AstIfStatement;
47  import cppast.AstIterationStatement;
48  import cppast.AstLabelStatement;
49  import cppast.AstMemberDeclaration;
50  import cppast.AstNamespaceDefinition;
51  import cppast.AstReturnStatement;
52  import cppast.AstSwitchStatement;
53  
54  /**
55   * Implements a NCSS counter.
56   *
57   * @author Mathieu Champlon
58   */
59  public final class NcssCounter extends AbstractCounter
60  {
61      /**
62       * Create a NCSS counter.
63       *
64       * @param observer a counter observer
65       */
66      public NcssCounter( final CounterObserver observer )
67      {
68          super( "NCSS", observer );
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      public Object visit( final AstFunctionBody node, final Object data )
75      {
76          increment();
77          return node.accept( this, data );
78      }
79  
80      /**
81       * {@inheritDoc}
82       */
83      public Object visit( final AstConstructorInitializer node, final Object data )
84      {
85          increment();
86          return node.accept( this, data );
87      }
88  
89      /**
90       * {@inheritDoc}
91       */
92      public Object visit( final AstDeclarationStatement node, final Object data )
93      {
94          increment();
95          return node.accept( this, data );
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     public Object visit( final AstExpressionStatement node, final Object data )
102     {
103         increment();
104         return node.accept( this, data );
105     }
106 
107     /**
108      * {@inheritDoc}
109      */
110     public Object visit( final AstIfStatement node, final Object data )
111     {
112         increment();
113         return node.accept( this, data );
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     public Object visit( final AstElseStatement node, final Object data )
120     {
121         increment();
122         return node.accept( this, data );
123     }
124 
125     /**
126      * {@inheritDoc}
127      */
128     public Object visit( final AstIterationStatement node, final Object data ) // FIXME homogeneity
129     {
130         increment();
131         return node.accept( this, data );
132     }
133 
134     /**
135      * {@inheritDoc}
136      */
137     public Object visit( final AstSwitchStatement node, final Object data )
138     {
139         increment();
140         return node.accept( this, data );
141     }
142 
143     /**
144      * {@inheritDoc}
145      */
146     public Object visit( final AstGotoStatement node, final Object data )
147     {
148         increment();
149         return node.accept( this, data );
150     }
151 
152     /**
153      * {@inheritDoc}
154      */
155     public Object visit( final AstBreakStatement node, final Object data )
156     {
157         increment();
158         return node.accept( this, data );
159     }
160 
161     /**
162      * {@inheritDoc}
163      */
164     public Object visit( final AstContinueStatement node, final Object data )
165     {
166         increment();
167         return node.accept( this, data );
168     }
169 
170     /**
171      * {@inheritDoc}
172      */
173     public Object visit( final AstReturnStatement node, final Object data )
174     {
175         increment();
176         return node.accept( this, data );
177     }
178 
179     /**
180      * {@inheritDoc}
181      */
182     public Object visit( final AstLabelStatement node, final Object data )
183     {
184         increment();
185         return node.accept( this, data );
186     }
187 
188     /**
189      * {@inheritDoc}
190      */
191     public Object visit( final AstCaseStatement node, final Object data )
192     {
193         increment();
194         return node.accept( this, data );
195     }
196 
197     /**
198      * {@inheritDoc}
199      */
200     public Object visit( final AstDefaultStatement node, final Object data )
201     {
202         increment();
203         return node.accept( this, data );
204     }
205 
206     /**
207      * {@inheritDoc}
208      */
209     public Object visit( final AstCatchBlock node, final Object data )
210     {
211         increment();
212         return node.accept( this, data );
213     }
214 
215     /**
216      * {@inheritDoc}
217      */
218     public Object visit( final AstNamespaceDefinition node, final Object data )
219     {
220         increment();
221         return node.accept( this, data );
222     }
223 
224     /**
225      * {@inheritDoc}
226      */
227     public Object visit( final AstDeclaration node, final Object data )
228     {
229         increment();
230         return node.accept( this, data );
231     }
232 
233     /**
234      * {@inheritDoc}
235      */
236     public Object visit( final AstMemberDeclaration node, final Object data )
237     {
238         increment();
239         return node.accept( this, data );
240     }
241 
242     /**
243      * {@inheritDoc}
244      */
245     public Object visit( final AstFunctionDeclaration node, final Object data )
246     {
247         increment();
248         return node.accept( this, data );
249     }
250 
251     /**
252      * {@inheritDoc}
253      */
254     public Object visit( final AstConstructorDeclaration node, final Object data )
255     {
256         increment();
257         return node.accept( this, data );
258     }
259 
260     /**
261      * {@inheritDoc}
262      */
263     public Object visit( final AstDestructorDeclaration node, final Object data )
264     {
265         increment();
266         return node.accept( this, data );
267     }
268 }