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;
39      
40      public ClassInheritanceHandler()
41      {
42         _inheritanceMap = new MultiMap();
43      }
44      
45      public ClassInheritanceHandler(MultiMap map)
46      {
47          _inheritanceMap = map;
48      }
49  
50      public void handle(String className, int version, int access, String signature, String superName, String[] interfaces)
51      {
52          try
53          {
54              for (int i=0; interfaces != null && i<interfaces.length;i++)
55              {
56                  _inheritanceMap.add (interfaces[i], className);
57              }
58              //To save memory, we don't record classes that only extend Object, as that can be assumed
59              if (!"java.lang.Object".equals(superName))
60                  _inheritanceMap.add(superName, className);
61          }
62          catch (Exception e)
63          {
64              LOG.warn(e);
65          }  
66      }
67      
68      public List getClassNamesExtendingOrImplementing (String className)
69      {
70          return _inheritanceMap.getValues(className);
71      }
72      
73      public MultiMap getMap ()
74      {
75          return _inheritanceMap;
76      }
77  }