View Javadoc
1   /*
2    * Copyright (C) 2015 Uwe Plonus
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.sw4j.apisniffer.visitor;
18  
19  import javax.annotation.concurrent.NotThreadSafe;
20  import org.objectweb.asm.AnnotationVisitor;
21  import org.objectweb.asm.Attribute;
22  import org.objectweb.asm.ClassVisitor;
23  import org.objectweb.asm.FieldVisitor;
24  import org.objectweb.asm.MethodVisitor;
25  import org.objectweb.asm.Opcodes;
26  import org.objectweb.asm.TypePath;
27  import org.sw4j.apisniffer.builder.ApiBuilder;
28  import org.sw4j.apisniffer.builder.TypeBuilder;
29  
30  /**
31   *
32   * @author Uwe Plonus
33   */
34  @NotThreadSafe
35  public final class ApiClassVisitor extends ClassVisitor {
36  
37      private final ApiBuilder apiBuilder;
38  
39      private TypeBuilder typeBuilder;
40  
41      public ApiClassVisitor(ApiBuilder apiBuilder) {
42          super(Opcodes.ASM5);
43          this.apiBuilder = apiBuilder;
44      }
45  
46      @Override
47      public void visit(int version, int access, String name, String signature, String superName,
48              String[] interfaces) {
49          if ((access & Opcodes.ACC_ANNOTATION) == Opcodes.ACC_ANNOTATION) {
50              typeBuilder = apiBuilder.createAnnotationTypeBuilder();
51          } else if ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE) {
52              typeBuilder = apiBuilder.createInterfaceTypeBuilder();
53          } else if ((access & Opcodes.ACC_ENUM) == Opcodes.ACC_ENUM) {
54              typeBuilder = apiBuilder.createEnumTypeBuilder();
55          } else {
56              typeBuilder = apiBuilder.createClassTypeBuilder();
57          }
58          typeBuilder.setInternalName(name);
59          super.visit(version, access, name, signature, superName, interfaces);
60      }
61  
62      @Override
63      public MethodVisitor visitMethod(int access, String name, String desc, String signature,
64              String[] exceptions) {
65          return super.visitMethod(access, name, desc, signature, exceptions);
66      }
67  
68      @Override
69      public FieldVisitor visitField(int access, String name, String desc, String signature,
70              Object value) {
71          return super.visitField(access, name, desc, signature, value);
72      }
73  
74      @Override
75      public void visitInnerClass(String name, String outerName, String innerName, int access) {
76          super.visitInnerClass(name, outerName, innerName, access);
77      }
78  
79      @Override
80      public void visitAttribute(Attribute attr) {
81          super.visitAttribute(attr);
82      }
83  
84      @Override
85      public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc,
86              boolean visible) {
87          return super.visitTypeAnnotation(typeRef, typePath, desc, visible);
88      }
89  
90      @Override
91      public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
92          return super.visitAnnotation(desc, visible);
93      }
94  
95      @Override
96      public void visitOuterClass(String owner, String name, String desc) {
97          super.visitOuterClass(owner, name, desc);
98      }
99  
100     @Override
101     public void visitEnd() {
102         super.visitEnd();
103     }
104 
105 }