Package java.lang.reflect

Examples of java.lang.reflect.Field


          }

          String propertyName = Character.toLowerCase(methodName
              .charAt(3)) + methodName.substring(4);

          Field field = null;
          try {
            field = clazz.getDeclaredField(propertyName);
          } catch (SecurityException e) {
            e.printStackTrace();
          } catch (NoSuchFieldException e) {
            e.printStackTrace();
          }

          if (field != null
              && Modifier.isTransient(field.getModifiers())) {
            continue;
          }

          try {
            JsonObjMetaInfo fieldSerializer = new JsonObjMetaInfo();
            fieldSerializer.setPropertyName(propertyName);
            fieldSerializer.setMethod(method);
            fieldList.add(fieldSerializer);
          } catch (IllegalArgumentException e) {
            e.printStackTrace();
          }
        } else if (methodName.startsWith("is")) { // 取is方法的返回值
          if (methodName.length() < 3
              || !Character.isUpperCase(methodName.charAt(2))) {
            continue;
          }

          String propertyName = Character.toLowerCase(methodName
              .charAt(2)) + methodName.substring(3);

          Field field = null;
          try {
            field = clazz.getDeclaredField(propertyName);
          } catch (SecurityException e) {
            e.printStackTrace();
          } catch (NoSuchFieldException e) {
            e.printStackTrace();
          }
          if (field != null
              && Modifier.isTransient(field.getModifiers())) {
            continue;
          }

          try {
            JsonObjMetaInfo fieldSerializer = new JsonObjMetaInfo();
View Full Code Here


    Class<?> currentType = clazz;
    for (int i = 0, tokensLength = tokens.length; i < tokensLength; i++) {
      String token = tokens[i];
      descriptorChain[i] = new ChainedPropertyDescriptor(currentType, token, isIndexed, index);
      if (i < tokensLength) {
        Field field = ReflectionUtils.getFieldFromBean(currentType, tokens[i]);
        currentType = field.getType();
      }
    }
  }
View Full Code Here

        CreateUpdateProcedureCommand cloned = (CreateUpdateProcedureCommand)s1.clone();
       
        Class clazz = CreateUpdateProcedureCommand.class;
        Class superClazz = Command.class;
       
        Field field = null;
        //Command class state
        field = superClazz.getDeclaredField("tempGroupIDs"); //$NON-NLS-1$
        field.setAccessible( true );
        assertNotNull(field.get(cloned));
        field = superClazz.getDeclaredField("externalGroups"); //$NON-NLS-1$
        field.setAccessible( true );
        assertNotNull(field.get(cloned));
        field = superClazz.getDeclaredField("isResolved"); //$NON-NLS-1$
        field.setAccessible( true );
        assertTrue(((Boolean)field.get(cloned)).booleanValue());
        field = superClazz.getDeclaredField("option"); //$NON-NLS-1$
        field.setAccessible( true );
        assertNotNull(field.get(cloned));
       
        //CreateUpdateProcedure class state
        field = clazz.getDeclaredField("block"); //$NON-NLS-1$
        field.setAccessible( true );
        assertNotNull(field.get(cloned));
        field = clazz.getDeclaredField("symbolMap"); //$NON-NLS-1$
        field.setAccessible( true );
        assertNotNull(field.get(cloned));
        field = clazz.getDeclaredField("isUpdateProcedure"); //$NON-NLS-1$
        field.setAccessible( true );
        assertTrue(((Boolean)field.get(cloned)).booleanValue());
        field = clazz.getDeclaredField("projectedSymbols"); //$NON-NLS-1$
        field.setAccessible( true );
        assertNotNull(field.get(cloned));
    }
View Full Code Here

    }
  }

  @Test
  public void shouldGetField() {
    Field field = ReflectionUtils.getFieldFromBean(GrandChild.class, "c");
    assertNotNull(field);
  }
View Full Code Here

    assertNotNull(field);
  }

  @Test
  public void shouldGoToSuperclass() {
    Field field = ReflectionUtils.getFieldFromBean(GrandChild.class, "a");
    assertNotNull(field);

    field = ReflectionUtils.getFieldFromBean(GrandChild.class, "b");
    assertNotNull(field);
  }
View Full Code Here

    assertNotNull(field);
  }

  @Test
  public void shouldModifyAccessor() {
    Field field = ReflectionUtils.getFieldFromBean(String.class, "offset");
    assertNotNull(field);
  }
View Full Code Here

    return getFieldFromBean(clazz, fieldName, clazz);
  }

  private static Field getFieldFromBean(Class<?> clazz, String fieldName, final Class<?> originalClass)  {
    try {
      Field field = clazz.getDeclaredField(fieldName);
      // Allow access to private instance var's that dont have public setter.
      field.setAccessible(true);
      return field;
    } catch (NoSuchFieldException e) {
      if (clazz.getSuperclass() != null) {
        return getFieldFromBean(clazz.getSuperclass(), fieldName, originalClass);
      }
View Full Code Here

        Iterator<ImportNode> iter = source.getAST().getImports().iterator();
        while (iter.hasNext()) {
            ImportNode importedClass = iter.next();
            if (!isVisible(source, importedClass.getClassName())) {
                try {
                    Field field = ModuleNode.class.getDeclaredField("imports");
                    field.setAccessible(true);
                    Map value = (Map) field.get(source.getAST());
                    value.remove(importedClass.getAlias());
                } catch (Exception e) {
                    throw UncheckedException.asUncheckedException(e);
                }
            }
View Full Code Here

     * @return list of bindings defined for that class (as a text string)
     * @throws JiBXException on error accessing binding information
     */
    private static String getBindingList(Class clas)throws JiBXException {
        try {
            Field field = clas.getDeclaredField(BINDINGLIST_NAME);
            try {
                // should be able to access field anyway, but just in case
                field.setAccessible(true);
            } catch (Exception e) { /* deliberately left empty */ }
            return (String)field.get(null);
        } catch (NoSuchFieldException e) {
            throw new JiBXException
                ("Unable to access binding information for class " +
                clas.getName() +
                "\nMake sure the binding has been compiled", e);
View Full Code Here

            AnnotatedElement annotationTarget = null;
            if (method.getAnnotation(annotationType) != null) {
                annotationTarget = method;
            } else {
                try {
                    Field field = method.getDeclaringClass().getDeclaredField(fieldName);
                    if (field.getAnnotation(annotationType) != null) {
                        annotationTarget = field;
                    }
                } catch (NoSuchFieldException e) {
                    // ok - ignore
                }
View Full Code Here

TOP

Related Classes of java.lang.reflect.Field

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.