1 package org.apache.maven.shared.dependency.analyzer.asm;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.objectweb.asm.AnnotationVisitor;
23 import org.objectweb.asm.Label;
24 import org.objectweb.asm.MethodVisitor;
25 import org.objectweb.asm.Opcodes;
26 import org.objectweb.asm.Type;
27 import org.objectweb.asm.TypePath;
28 import org.objectweb.asm.signature.SignatureReader;
29 import org.objectweb.asm.signature.SignatureVisitor;
30
31
32
33
34
35
36
37
38
39 public class DefaultMethodVisitor
40 extends MethodVisitor
41 {
42 private final AnnotationVisitor annotationVisitor;
43
44 private final SignatureVisitor signatureVisitor;
45
46 private final ResultCollector resultCollector;
47
48 public DefaultMethodVisitor( AnnotationVisitor annotationVisitor, SignatureVisitor signatureVisitor,
49 ResultCollector resultCollector )
50 {
51 super( Opcodes.ASM8 );
52 this.annotationVisitor = annotationVisitor;
53 this.signatureVisitor = signatureVisitor;
54 this.resultCollector = resultCollector;
55 }
56
57 public AnnotationVisitor visitAnnotation( final String desc, final boolean visible )
58 {
59 resultCollector.addDesc( desc );
60
61 return annotationVisitor;
62 }
63
64 @Override
65 public AnnotationVisitor visitTypeAnnotation( int typeRef, TypePath typePath, String desc, boolean visible )
66 {
67 resultCollector.addDesc( desc );
68
69 return annotationVisitor;
70 }
71
72 public AnnotationVisitor visitParameterAnnotation( final int parameter, final String desc, final boolean visible )
73 {
74 resultCollector.addDesc( desc );
75
76 return annotationVisitor;
77 }
78
79 @Override
80 public AnnotationVisitor visitLocalVariableAnnotation( int typeRef, TypePath typePath, Label[] start, Label[] end,
81 int[] index, String desc, boolean visible )
82 {
83 resultCollector.addDesc( desc );
84
85 return annotationVisitor;
86 }
87
88 public void visitTypeInsn( final int opcode, final String desc )
89 {
90 if ( desc.charAt( 0 ) == '[' )
91 {
92 resultCollector.addDesc( desc );
93 }
94 else
95 {
96 resultCollector.addName( desc );
97 }
98 }
99
100 public void visitFieldInsn( final int opcode, final String owner, final String name, final String desc )
101 {
102 resultCollector.addName( owner );
103
104
105
106
107
108
109 }
110
111 @Override
112 public void visitMethodInsn( int opcode, String owner, String name, String desc, boolean itf )
113 {
114 resultCollector.addName( owner );
115 }
116
117 public void visitLdcInsn( final Object cst )
118 {
119 if ( cst instanceof Type )
120 {
121 resultCollector.addType( (Type) cst );
122 }
123 }
124
125 public void visitMultiANewArrayInsn( final String desc, final int dims )
126 {
127 resultCollector.addDesc( desc );
128 }
129
130 public void visitTryCatchBlock( final Label start, final Label end, final Label handler, final String type )
131 {
132 resultCollector.addName( type );
133 }
134
135 public void visitLocalVariable( final String name, final String desc, final String signature, final Label start,
136 final Label end, final int index )
137 {
138 if ( signature == null )
139 {
140 resultCollector.addDesc( desc );
141 }
142 else
143 {
144 addTypeSignature( signature );
145 }
146 }
147
148
149
150 private void addTypeSignature( final String signature )
151 {
152 if ( signature != null )
153 {
154 new SignatureReader( signature ).acceptType( signatureVisitor );
155 }
156 }
157 }