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 default:
77 }
78 }
79
80 public void add( String name )
81 {
82 classes.add( name );
83 }
84
85 void addNames( final String[] names )
86 {
87 if ( names == null )
88 {
89 return;
90 }
91
92 for ( String name : names )
93 {
94 addName( name );
95 }
96 }
97
98 void addMethodDesc( final String desc )
99 {
100 addType( Type.getReturnType( desc ) );
101
102 Type[] types = Type.getArgumentTypes( desc );
103
104 for ( Type type : types )
105 {
106 addType( type );
107 }
108 }
109 }