View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.annotations;
20  
21  import java.util.List;
22  
23  import org.eclipse.jetty.annotations.AnnotationParser.ClassHandler;
24  import org.eclipse.jetty.util.MultiMap;
25  import org.eclipse.jetty.util.log.Log;
26  import org.eclipse.jetty.util.log.Logger;
27  
28  /**
29   * ClassInheritanceHandler
30   *
31   * As asm scans for classes, remember the type hierarchy.
32   */
33  public class ClassInheritanceHandler implements ClassHandler
34  {
35      private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class);
36  
37      
38      MultiMap _inheritanceMap = new MultiMap();
39      
40      public ClassInheritanceHandler()
41      {
42      }
43  
44      public void handle(String className, int version, int access, String signature, String superName, String[] interfaces)
45      {
46          try
47          {
48              for (int i=0; interfaces != null && i<interfaces.length;i++)
49              {
50                  _inheritanceMap.add (interfaces[i], className);
51              }
52              //To save memory, we don't record classes that only extend Object, as that can be assumed
53              if (!"java.lang.Object".equals(superName))
54                  _inheritanceMap.add(superName, className);
55          }
56          catch (Exception e)
57          {
58              LOG.warn(e);
59          }  
60      }
61      
62      public List getClassNamesExtendingOrImplementing (String className)
63      {
64          return _inheritanceMap.getValues(className);
65      }
66      
67      public MultiMap getMap ()
68      {
69          return _inheritanceMap;
70      }
71  }