View Javadoc
1   package org.apache.maven.shared.dependency.analyzer.asm;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.objectweb.asm.Type;
23  
24  import java.util.HashSet;
25  import java.util.Set;
26  
27  /**
28   * @author Kristian Rosenvold
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          // decode arrays
48          if ( name.startsWith( "[L" ) && name.endsWith( ";" ) )
49          {
50              name = name.substring( 2, name.length() - 1 );
51          }
52  
53          // decode internal representation
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 }