test_class.declarator: logger = LoggerFactory.getLogger(BeanUtilTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger logger = LoggerFactory.getLogger(BeanUtilTest.class);
test_class.type: Logger
test_class.var_name: logger
test_class.file: ch-commons-util/src/test/java/com/cloudhopper/commons/util/BeanUtilTest.java
test_class.identifier: BeanUtilTest
test_case.body: @Test
      public void getBeanPropertyAddOrSet() throws Exception {
          TestBeanE bean = new TestBeanE();
  
          // use utility class to get the "bean" property
          BeanProperty property = BeanUtil.findBeanProperty(bean.getClass(), "host", true);
  
          Assert.assertEquals(String.class, property.getType());
          Assert.assertEquals("host", property.getName());
          Assert.assertEquals(false, property.canGet());
          Assert.assertEquals(true, property.canSet());
          Assert.assertEquals(true, property.canAdd());
          Assert.assertEquals(true, property.canAddOrSet());
          Assert.assertEquals(null, property.getField());
          Assert.assertEquals(TestBeanE.class.getDeclaredMethod("addHost", String.class), property.getAddMethod());
          Assert.assertEquals(TestBeanE.class.getDeclaredMethod("setHost", String.class), property.getSetMethod());
          Assert.assertEquals(null, property.getGetMethod());
  
          // verify that the "addHost" method takes precedence over the "setHost"
          property.addOrSet(bean, "www.google.com");
  
          Assert.assertEquals("www.google.com", bean.addhost);
          Assert.assertEquals(null, bean.sethost);
      }
test_case.class_method_signature: BeanUtilTest.getBeanPropertyAddOrSet()
test_case.full_signature: @Test public void getBeanPropertyAddOrSet()
test_case.identifier: getBeanPropertyAddOrSet
test_case.invocations: findBeanProperty getClass assertEquals getType assertEquals getName assertEquals canGet assertEquals canSet assertEquals canAdd assertEquals canAddOrSet assertEquals getField assertEquals getDeclaredMethod getAddMethod assertEquals getDeclaredMethod getSetMethod assertEquals getGetMethod addOrSet assertEquals assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void getBeanPropertyAddOrSet()
focal_class.declarator: logger = LoggerFactory.getLogger(BeanUtil.class)
focal_class.modifier: private static
focal_class.original_string: private static Logger logger = LoggerFactory.getLogger(BeanUtil.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: ch-commons-util/src/main/java/com/cloudhopper/commons/util/BeanUtil.java
focal_class.identifier: BeanUtil
focal_class.class_method_signature: BeanUtil.findBeanProperty(Class type, String propertyName, boolean caseSensitive)
focal_class.full_signature: public static BeanProperty findBeanProperty(Class type, String propertyName, boolean caseSensitive)
focal_class.identifier: findBeanProperty
focal_class.modifiers: public static
focal_class.parameters: (Class type, String propertyName, boolean caseSensitive)
focal_class.return: BeanProperty
focal_class.signature: BeanProperty findBeanProperty(Class type, String propertyName, boolean caseSensitive)
focal_method.body: public static BeanProperty findBeanProperty(Class type, String propertyName, boolean caseSensitive) throws IllegalAccessException {
          // bean property we'd return if found
          BeanProperty beanProperty = null;
  
          // class we'll start our search from
          Class classType = type;
  
          //
          // search for field first - loop thru all classes
          //
          while (classType != null && !classType.equals(Object.class)) {
              // search all declared fields
              for (Field f : classType.getDeclaredFields()) {
                  // grab this field's name
                  String fieldName = f.getName();
                  // check if its the property we're searching for
                  if ((!caseSensitive && fieldName.equalsIgnoreCase(propertyName)) || (caseSensitive && fieldName.equals(propertyName))) {
                      // success, we found the method we're looking for
                      Class fieldType = f.getType();
                      // make sure its accessible
                      f.setAccessible(true);
                      // create the BeanProperty we're going to use
                      beanProperty = new BeanProperty(propertyName, fieldType, f);
                      // done with this loop, break out of it
                      break;
                  }
              }
              // move onto the superclass
              classType = classType.getSuperclass();
          }
  
          String capitalizedName = StringUtil.capitalize(propertyName);
          String getMethodName = "get" + capitalizedName;
          String setMethodName = "set" + capitalizedName;
          String addMethodName = "add" + capitalizedName;
  
          
          // if we get here and the beanProperty does not exist, then we need
          // to search thru the hierarchy of classes for a setter or getter
          // method that matches the name
          if (beanProperty == null) {
              // class we'll start our search from
              classType = type;
              while (classType != null && !classType.equals(Object.class)) {
                  // search all declared fields
                  for (Method m : classType.getDeclaredMethods()) {
                      // grab this methods's name
                      String methodName = m.getName();
                      // is this a getter we've been looking for?
                      if ((!caseSensitive && methodName.equalsIgnoreCase(getMethodName)) || (caseSensitive && methodName.equals(getMethodName))) {
                          // check to make sure this accepts no arguments
                          if (m.getParameterTypes().length == 0) {
                              // success, we found the getter method
                              beanProperty = new BeanProperty(propertyName, m.getReturnType(), null);
                              m.setAccessible(true);
                              beanProperty.getMethod = m;
                              break;
                          }
                      // is this a setter we've been looking for?
                      } else if ((!caseSensitive && methodName.equalsIgnoreCase(setMethodName)) || (caseSensitive && methodName.equals(setMethodName))) {
                          // check to make sure this accepts 1 argument
                          if (m.getParameterTypes().length == 1) {
                              // success, we found the setter method
                              beanProperty = new BeanProperty(propertyName, m.getParameterTypes()[0], null);
                              m.setAccessible(true);
                              beanProperty.setMethod = m;
                              break;
                          }
                      // is this a adder we've been looking for?
                      } else if ((!caseSensitive && methodName.equalsIgnoreCase(addMethodName)) || (caseSensitive && methodName.equals(addMethodName))) {
                          // check to make sure this accepts 1 argument
                          if (m.getParameterTypes().length == 1) {
                              // success, we found the adder method
                              beanProperty = new BeanProperty(propertyName, m.getParameterTypes()[0], null);
                              m.setAccessible(true);
                              beanProperty.addMethod = m;
                              break;
                          }
                      }
                  }
                  // move onto the superclass
                  classType = classType.getSuperclass();
              }
          }
  
          // if we get here and beanProperty exists, then we need to search for
          // whether its getter/setter methods also exist
          if (beanProperty != null) {
              if (beanProperty.getMethod == null) {
                  try {
                      // look for a "getter" method
                      Method getMethod = ClassUtil.getMethod(type, getMethodName, beanProperty.getType(), null, caseSensitive);
                      // set to accessible?
                      getMethod.setAccessible(true);
                      beanProperty.getMethod = getMethod;
                  } catch (NoSuchMethodException e) {
                      // its okay if this happens, ignore
                  }
              }
  
              if (beanProperty.setMethod == null) {
                  try {
                      // look for a "setter" method
                      Method setMethod = ClassUtil.getMethod(type, setMethodName, null, beanProperty.getType(), caseSensitive);
                      // set to accessible?
                      setMethod.setAccessible(true);
                      beanProperty.setMethod = setMethod;
                  } catch (NoSuchMethodException e) {
                      // its okay if this happens, ignore
                  }
              }
  
              if (beanProperty.addMethod == null) {
                  try {
                      // look for a "adder" method
                      Method addMethod = ClassUtil.getMethod(type, addMethodName, null, beanProperty.getType(), caseSensitive);
                      // set to accessible?
                      addMethod.setAccessible(true);
                      beanProperty.addMethod = addMethod;
                  } catch (NoSuchMethodException e) {
                      // its okay if this happens, ignore
                  }
              }
          }
  
          return beanProperty;
      }
focal_method.class_method_signature: BeanUtil.findBeanProperty(Class type, String propertyName, boolean caseSensitive)
focal_method.full_signature: public static BeanProperty findBeanProperty(Class type, String propertyName, boolean caseSensitive)
focal_method.identifier: findBeanProperty
focal_method.invocations: equals getDeclaredFields getName equalsIgnoreCase equals getType setAccessible getSuperclass capitalize equals getDeclaredMethods getName equalsIgnoreCase equals getParameterTypes getReturnType setAccessible equalsIgnoreCase equals getParameterTypes getParameterTypes setAccessible equalsIgnoreCase equals getParameterTypes getParameterTypes setAccessible getSuperclass getMethod getType setAccessible getMethod getType setAccessible getMethod getType setAccessible
focal_method.modifiers: public static
focal_method.parameters: (Class type, String propertyName, boolean caseSensitive)
focal_method.return: BeanProperty
focal_method.signature: BeanProperty findBeanProperty(Class type, String propertyName, boolean caseSensitive)