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.ASM6 );
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 public void visitTypeInsn( final int opcode, final String desc )
80 {
81 if ( desc.charAt( 0 ) == '[' )
82 {
83 resultCollector.addDesc( desc );
84 }
85 else
86 {
87 resultCollector.addName( desc );
88 }
89 }
90
91 public void visitFieldInsn( final int opcode, final String owner, final String name, final String desc )
92 {
93 resultCollector.addName( owner );
94
95
96
97
98
99
100 }
101
102 @Override
103 public void visitMethodInsn( int opcode, String owner, String name, String desc, boolean itf )
104 {
105 resultCollector.addName( owner );
106 }
107
108 public void visitLdcInsn( final Object cst )
109 {
110 if ( cst instanceof Type )
111 {
112 resultCollector.addType( (Type) cst );
113 }
114 }
115
116 public void visitMultiANewArrayInsn( final String desc, final int dims )
117 {
118 resultCollector.addDesc( desc );
119 }
120
121 public void visitTryCatchBlock( final Label start, final Label end, final Label handler, final String type )
122 {
123 resultCollector.addName( type );
124 }
125
126 public void visitLocalVariable( final String name, final String desc, final String signature, final Label start,
127 final Label end, final int index )
128 {
129 if ( signature == null )
130 {
131 resultCollector.addDesc( desc );
132 }
133 else
134 {
135 addTypeSignature( signature );
136 }
137 }
138
139
140
141 private void addTypeSignature( final String signature )
142 {
143 if ( signature != null )
144 {
145 new SignatureReader( signature ).acceptType( signatureVisitor );
146 }
147 }
148 }