View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   */
18  
19  package org.apache.bcel.visitors;
20  
21  import org.apache.bcel.classfile.AnnotationDefault;
22  import org.apache.bcel.classfile.AnnotationEntry;
23  import org.apache.bcel.classfile.Annotations;
24  import org.apache.bcel.classfile.BootstrapMethods;
25  import org.apache.bcel.classfile.Code;
26  import org.apache.bcel.classfile.CodeException;
27  import org.apache.bcel.classfile.ConstantClass;
28  import org.apache.bcel.classfile.ConstantDouble;
29  import org.apache.bcel.classfile.ConstantDynamic;
30  import org.apache.bcel.classfile.ConstantFieldref;
31  import org.apache.bcel.classfile.ConstantFloat;
32  import org.apache.bcel.classfile.ConstantInteger;
33  import org.apache.bcel.classfile.ConstantInterfaceMethodref;
34  import org.apache.bcel.classfile.ConstantInvokeDynamic;
35  import org.apache.bcel.classfile.ConstantLong;
36  import org.apache.bcel.classfile.ConstantMethodHandle;
37  import org.apache.bcel.classfile.ConstantMethodType;
38  import org.apache.bcel.classfile.ConstantMethodref;
39  import org.apache.bcel.classfile.ConstantModule;
40  import org.apache.bcel.classfile.ConstantNameAndType;
41  import org.apache.bcel.classfile.ConstantPackage;
42  import org.apache.bcel.classfile.ConstantPool;
43  import org.apache.bcel.classfile.ConstantString;
44  import org.apache.bcel.classfile.ConstantUtf8;
45  import org.apache.bcel.classfile.ConstantValue;
46  import org.apache.bcel.classfile.Deprecated;
47  import org.apache.bcel.classfile.EnclosingMethod;
48  import org.apache.bcel.classfile.ExceptionTable;
49  import org.apache.bcel.classfile.Field;
50  import org.apache.bcel.classfile.InnerClass;
51  import org.apache.bcel.classfile.InnerClasses;
52  import org.apache.bcel.classfile.JavaClass;
53  import org.apache.bcel.classfile.LineNumber;
54  import org.apache.bcel.classfile.LineNumberTable;
55  import org.apache.bcel.classfile.LocalVariable;
56  import org.apache.bcel.classfile.LocalVariableTable;
57  import org.apache.bcel.classfile.LocalVariableTypeTable;
58  import org.apache.bcel.classfile.Method;
59  import org.apache.bcel.classfile.MethodParameter;
60  import org.apache.bcel.classfile.MethodParameters;
61  import org.apache.bcel.classfile.Module;
62  import org.apache.bcel.classfile.ModuleExports;
63  import org.apache.bcel.classfile.ModuleOpens;
64  import org.apache.bcel.classfile.ModuleProvides;
65  import org.apache.bcel.classfile.ModuleRequires;
66  import org.apache.bcel.classfile.ModuleMainClass;
67  import org.apache.bcel.classfile.ModulePackages;
68  import org.apache.bcel.classfile.NestHost;
69  import org.apache.bcel.classfile.NestMembers;
70  import org.apache.bcel.classfile.ParameterAnnotationEntry;
71  import org.apache.bcel.classfile.ParameterAnnotations;
72  import org.apache.bcel.classfile.Signature;
73  import org.apache.bcel.classfile.SourceFile;
74  import org.apache.bcel.classfile.StackMap;
75  import org.apache.bcel.classfile.StackMapEntry;
76  import org.apache.bcel.classfile.Synthetic;
77  import org.apache.bcel.classfile.Unknown;
78  import org.apache.bcel.classfile.Visitor;
79  
80  public class CounterVisitor implements Visitor
81  {
82      // CHECKSTYLE:OFF (public mutable fields in test code)
83      public int unknownCount = 0;
84  
85      public int syntheticCount = 0;
86  
87      public int stackMapEntryCount = 0;
88  
89      public int stackMapCount = 0;
90  
91      public int sourceFileCount = 0;
92  
93      public int signatureAnnotationCount = 0;
94  
95      public int parameterAnnotationCount = 0;
96  
97      public int methodCount = 0;
98  
99      public int localVariableTypeTableCount = 0;
100 
101     public int localVariableTableCount = 0;
102 
103     public int localVariableCount = 0;
104 
105     public int lineNumberTableCount = 0;
106 
107     public int lineNumberCount = 0;
108 
109     public int javaClassCount = 0;
110 
111     public int innerClassesCount = 0;
112 
113     public int innerClassCount = 0;
114 
115     public int fieldCount = 0;
116 
117     public int exceptionTableCount = 0;
118 
119     public int enclosingMethodCount = 0;
120 
121     public int deprecatedCount = 0;
122 
123     public int constantValueCount = 0;
124 
125     public int constantUtf8Count = 0;
126 
127     public int constantStringCount = 0;
128 
129     public int constantNameAndTypeCount = 0;
130 
131     public int constantPoolCount = 0;
132 
133     public int constantMethodrefCount = 0;
134 
135     public int constantLongCount = 0;
136 
137     public int constantIntegerCount = 0;
138 
139     public int constantInterfaceMethodrefCount = 0;
140 
141     public int constantFloatCount = 0;
142 
143     public int constantFieldrefCount = 0;
144 
145     public int constantClassCount = 0;
146 
147     public int constantDoubleCount = 0;
148 
149     public int codeExceptionCount = 0;
150 
151     public int codeCount = 0;
152 
153     public int annotationEntryCount = 0;
154 
155     public int annotationDefaultCount = 0;
156 
157     public int annotationCount = 0;
158 
159     /** @since 6.0 */
160     public int bootstrapMethodsCount = 0;
161 
162     /** @since 6.0 */
163     public int methodParameterCount = 0;
164 
165     /** @since 6.0 */
166     public int methodParametersCount = 0;
167 
168     /** @since 6.0 */
169     public int constantInvokeDynamic = 0;
170 
171     /** @since 6.1 */
172     public int constantModuleCount = 0;
173 
174     /** @since 6.1 */
175     public int constantPackageCount = 0;
176 
177     /** @since 6.3 */
178     public int constantDynamicCount = 0;
179 
180     /** @since 6.4.0 */
181     public int moduleCount = 0;
182 
183     /** @since 6.4.0 */
184     public int moduleExportsCount = 0;
185 
186     /** @since 6.4.0 */
187     public int moduleOpensCount = 0;
188 
189     /** @since 6.4.0 */
190     public int moduleProvidesCount = 0;
191 
192     /** @since 6.4.0 */
193     public int moduleRequiresCount = 0;
194 
195     /** @since 6.4.0 */
196     public int moduleMainClassCount = 0;
197 
198     /** @since 6.4.0 */
199     public int modulePackagesCount = 0;
200 
201     /** @since 6.4.0 */
202     public int nestHostCount = 0;
203 
204     /** @since 6.4.0 */
205     public int nestMembersCount = 0;
206     // CHECKSTYLE:ON
207 
208 
209     @Override
210     public void visitAnnotation(final Annotations obj)
211     {
212         annotationCount++;
213     }
214 
215     @Override
216     public void visitAnnotationDefault(final AnnotationDefault obj)
217     {
218         annotationDefaultCount++;
219     }
220 
221     @Override
222     public void visitAnnotationEntry(final AnnotationEntry obj)
223     {
224         annotationEntryCount++;
225     }
226 
227     @Override
228     public void visitCode(final Code obj)
229     {
230         codeCount++;
231     }
232 
233     @Override
234     public void visitCodeException(final CodeException obj)
235     {
236         codeExceptionCount++;
237     }
238 
239     @Override
240     public void visitConstantClass(final ConstantClass obj)
241     {
242         constantClassCount++;
243     }
244 
245     @Override
246     public void visitConstantDouble(final ConstantDouble obj)
247     {
248         constantDoubleCount++;
249     }
250 
251     @Override
252     public void visitConstantFieldref(final ConstantFieldref obj)
253     {
254         constantFieldrefCount++;
255     }
256 
257     @Override
258     public void visitConstantFloat(final ConstantFloat obj)
259     {
260         constantFloatCount++;
261     }
262 
263     @Override
264     public void visitConstantInteger(final ConstantInteger obj)
265     {
266         constantIntegerCount++;
267     }
268 
269     @Override
270     public void visitConstantInterfaceMethodref(final ConstantInterfaceMethodref obj)
271     {
272         constantInterfaceMethodrefCount++;
273     }
274 
275     @Override
276     public void visitConstantLong(final ConstantLong obj)
277     {
278         constantLongCount++;
279     }
280 
281     @Override
282     public void visitConstantMethodref(final ConstantMethodref obj)
283     {
284         constantMethodrefCount++;
285     }
286 
287     @Override
288     public void visitConstantNameAndType(final ConstantNameAndType obj)
289     {
290         constantNameAndTypeCount++;
291     }
292 
293     @Override
294     public void visitConstantPool(final ConstantPool obj)
295     {
296         constantPoolCount++;
297     }
298 
299     @Override
300     public void visitConstantString(final ConstantString obj)
301     {
302         constantStringCount++;
303     }
304 
305     @Override
306     public void visitConstantUtf8(final ConstantUtf8 obj)
307     {
308         constantUtf8Count++;
309     }
310 
311     @Override
312     public void visitConstantValue(final ConstantValue obj)
313     {
314         constantValueCount++;
315     }
316 
317     @Override
318     public void visitDeprecated(final Deprecated obj)
319     {
320         deprecatedCount++;
321     }
322 
323     @Override
324     public void visitEnclosingMethod(final EnclosingMethod obj)
325     {
326         enclosingMethodCount++;
327     }
328 
329     @Override
330     public void visitExceptionTable(final ExceptionTable obj)
331     {
332         exceptionTableCount++;
333     }
334 
335     @Override
336     public void visitField(final Field obj)
337     {
338         fieldCount++;
339     }
340 
341     @Override
342     public void visitInnerClass(final InnerClass obj)
343     {
344         innerClassCount++;
345     }
346 
347     @Override
348     public void visitInnerClasses(final InnerClasses obj)
349     {
350         innerClassesCount++;
351     }
352 
353     @Override
354     public void visitJavaClass(final JavaClass obj)
355     {
356         javaClassCount++;
357     }
358 
359     @Override
360     public void visitLineNumber(final LineNumber obj)
361     {
362         lineNumberCount++;
363     }
364 
365     @Override
366     public void visitLineNumberTable(final LineNumberTable obj)
367     {
368         lineNumberTableCount++;
369     }
370 
371     @Override
372     public void visitLocalVariable(final LocalVariable obj)
373     {
374         localVariableCount++;
375     }
376 
377     @Override
378     public void visitLocalVariableTable(final LocalVariableTable obj)
379     {
380         localVariableTableCount++;
381     }
382 
383     @Override
384     public void visitLocalVariableTypeTable(final LocalVariableTypeTable obj)
385     {
386         localVariableTypeTableCount++;
387     }
388 
389     @Override
390     public void visitMethod(final Method obj)
391     {
392         methodCount++;
393     }
394 
395     @Override
396     public void visitParameterAnnotation(final ParameterAnnotations obj)
397     {
398         parameterAnnotationCount++;
399     }
400 
401     @Override
402     public void visitSignature(final Signature obj)
403     {
404         signatureAnnotationCount++;
405     }
406 
407     @Override
408     public void visitSourceFile(final SourceFile obj)
409     {
410         sourceFileCount++;
411     }
412 
413     @Override
414     public void visitStackMap(final StackMap obj)
415     {
416         stackMapCount++;
417     }
418 
419     @Override
420     public void visitStackMapEntry(final StackMapEntry obj)
421     {
422         stackMapEntryCount++;
423     }
424 
425     @Override
426     public void visitSynthetic(final Synthetic obj)
427     {
428         syntheticCount++;
429     }
430 
431     @Override
432     public void visitUnknown(final Unknown obj)
433     {
434         unknownCount++;
435     }
436 
437     /** @since 6.0 */
438     @Override
439     public void visitBootstrapMethods(final BootstrapMethods obj)
440     {
441         bootstrapMethodsCount++;
442     }
443 
444     /** @since 6.0 */
445     @Override
446     public void visitMethodParameter(final MethodParameter obj)
447     {
448         methodParameterCount++;
449     }
450 
451     /** @since 6.0 */
452     @Override
453     public void visitMethodParameters(final MethodParameters obj)
454     {
455         methodParametersCount++;
456     }
457 
458     /** @since 6.0 */
459     @Override
460     public void visitConstantInvokeDynamic(final ConstantInvokeDynamic obj)
461     {
462         constantInvokeDynamic++;
463     }
464 
465     /** @since 6.0 */
466     @Override
467     public void visitConstantMethodType(final ConstantMethodType obj) {
468         // TODO Auto-generated method stub
469     }
470 
471     /** @since 6.0 */
472     @Override
473     public void visitConstantMethodHandle(final ConstantMethodHandle constantMethodHandle) {
474         // TODO Auto-generated method stub
475     }
476 
477     /** @since 6.0 */
478     @Override
479     public void visitParameterAnnotationEntry(final ParameterAnnotationEntry parameterAnnotationEntry) {
480         // TODO Auto-generated method stub
481     }
482 
483     /** @since 6.1 */
484     @Override
485     public void visitConstantPackage(final ConstantPackage constantPackage) {
486         constantPackageCount++;
487     }
488 
489     /** @since 6.1 */
490     @Override
491     public void visitConstantModule(final ConstantModule constantModule) {
492         constantModuleCount++;
493     }
494 
495     /** @since 6.3 */
496     @Override
497     public void visitConstantDynamic(final ConstantDynamic constantDynamic) {
498         constantDynamicCount++;
499     }
500 
501     /** @since 6.4.0 */
502     @Override
503     public void visitModule(final Module obj) {
504         moduleCount++;
505     }
506 
507     /** @since 6.4.0 */
508     @Override
509     public void visitModuleExports(final ModuleExports obj) {
510         moduleExportsCount++;
511     }
512 
513     /** @since 6.4.0 */
514     @Override
515     public void visitModuleOpens(final ModuleOpens obj) {
516         moduleOpensCount++;
517     }
518 
519     /** @since 6.4.0 */
520     @Override
521     public void visitModuleProvides(final ModuleProvides obj) {
522         moduleProvidesCount++;
523     }
524 
525     /** @since 6.4.0 */
526     @Override
527     public void visitModuleRequires(final ModuleRequires obj) {
528         moduleRequiresCount++;
529     }
530 
531     /** @since 6.4.0 */
532     @Override
533     public void visitModuleMainClass(final ModuleMainClass obj) {
534         moduleMainClassCount++;
535     }
536 
537     /** @since 6.4.0 */
538     @Override
539     public void visitModulePackages(final ModulePackages obj) {
540         modulePackagesCount++;
541     }
542 
543     /** @since 6.4.0 */
544     @Override
545     public void visitNestHost(final NestHost obj) {
546         nestHostCount++;
547     }
548 
549     /** @since 6.4.0 */
550     @Override
551     public void visitNestMembers(final NestMembers obj) {
552         nestMembersCount++;
553     }
554 }