View Javadoc

1   /***************************************************************************************
2    * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package org.codehaus.aspectwerkz.reflect;
9   
10  /***
11   * Inspects info.
12   * 
13   * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
14   */
15  public class MetaDataInspector {
16      /***
17       * Checks if a class has a certain field.
18       * 
19       * @param classInfo
20       * @param fieldName
21       * @return
22       */
23      public static boolean hasField(final ClassInfo classInfo, final String fieldName) {
24          for (int i = 0; i < classInfo.getFields().length; i++) {
25              FieldInfo fieldMetaData = classInfo.getFields()[i];
26              if (fieldMetaData.getName().equals(fieldName)) {
27                  return true;
28              }
29          }
30          return false;
31      }
32  
33      /***
34       * Checks if a class implements a certain interface.
35       * 
36       * @param classInfo
37       * @param interfaceName
38       * @return
39       */
40      public static boolean hasInterface(final ClassInfo classInfo, final String interfaceName) {
41          for (int i = 0; i < classInfo.getInterfaces().length; i++) {
42              ClassInfo interfaceMetaData = classInfo.getInterfaces()[i];
43              if (interfaceMetaData.getName().equals(interfaceName)) {
44                  return true;
45              }
46          }
47          return false;
48      }
49  }