View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 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.util;
20  
21  import org.eclipse.jetty.util.log.Log;
22  import org.eclipse.jetty.util.log.Logger;
23  
24  public class DeprecationWarning implements Decorator
25  {
26      private static final Logger LOG = Log.getLogger(DeprecationWarning.class);
27  
28      @Override
29      public <T> T decorate(T o)
30      {
31          if (o == null)
32          {
33              return null;
34          }
35  
36          Class<?> clazz = o.getClass();
37  
38          try
39          {
40              Deprecated depr = clazz.getAnnotation(Deprecated.class);
41              if (depr != null)
42              {
43                  LOG.warn("Using @Deprecated Class {}",clazz.getName());
44              }
45          }
46          catch (Throwable t)
47          {
48              LOG.ignore(t);
49          }
50  
51          verifyIndirectTypes(clazz.getSuperclass(),clazz,"Class");
52          for (Class<?> ifaceClazz : clazz.getInterfaces())
53          {
54              verifyIndirectTypes(ifaceClazz,clazz,"Interface");
55          }
56  
57          return o;
58      }
59  
60      private void verifyIndirectTypes(Class<?> superClazz, Class<?> clazz, String typeName)
61      {
62          try
63          {
64              // Report on super class deprecation too
65              while (superClazz != null && superClazz != Object.class)
66              {
67                  Deprecated supDepr = superClazz.getAnnotation(Deprecated.class);
68                  if (supDepr != null)
69                  {
70                      LOG.warn("Using indirect @Deprecated {} {} - (seen from {})",typeName,superClazz.getName(),clazz);
71                  }
72  
73                  superClazz = superClazz.getSuperclass();
74              }
75          }
76          catch (Throwable t)
77          {
78              LOG.ignore(t);
79          }
80      }
81  
82      @Override
83      public void destroy(Object o)
84      {
85      }
86  }