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