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.Type;
23
24 import java.util.HashSet;
25 import java.util.Set;
26
27
28
29
30 public class ResultCollector
31 {
32
33 private final Set<String> classes = new HashSet<String>();
34
35 public Set<String> getDependencies()
36 {
37 return classes;
38 }
39
40 public void addName( String name )
41 {
42 if ( name == null )
43 {
44 return;
45 }
46
47
48 if ( name.startsWith( "[L" ) && name.endsWith( ";" ) )
49 {
50 name = name.substring( 2, name.length() - 1 );
51 }
52
53
54 name = name.replace( '/', '.' );
55
56 classes.add( name );
57 }
58
59 void addDesc( final String desc )
60 {
61 addType( Type.getType( desc ) );
62 }
63
64 void addType( final Type t )
65 {
66 switch ( t.getSort() )
67 {
68 case Type.ARRAY:
69 addType( t.getElementType() );
70 break;
71
72 case Type.OBJECT:
73 addName( t.getClassName().replace( '.', '/' ) );
74 break;
75 }
76 }
77
78 public void add( String name )
79 {
80 classes.add( name );
81 }
82
83 void addNames( final String[] names )
84 {
85 if ( names == null )
86 {
87 return;
88 }
89
90 for ( String name : names )
91 {
92 addName( name );
93 }
94 }
95
96 void addMethodDesc( final String desc )
97 {
98 addType( Type.getReturnType( desc ) );
99
100 Type[] types = Type.getArgumentTypes( desc );
101
102 for ( Type type : types )
103 {
104 addType( type );
105 }
106 }
107 }