Esempio n. 1
0
  private ObjectMap<String, FieldMetadata> cacheFields(Type type) {
    ArrayList<Field> allFields = new ArrayList();
    Type nextClass = type;
    while (nextClass != null && nextClass.getClassOfType() != Object.class) {
      Collections.addAll(allFields, nextClass.getDeclaredFields());
      nextClass = nextClass.getSuperclass();
    }

    ObjectMap<String, FieldMetadata> nameToField = new ObjectMap();
    for (int i = 0, n = allFields.size(); i < n; i++) {
      Field field = allFields.get(i);

      if (field.isTransient()) continue;
      if (field.isStatic()) continue;
      if (field.isSynthetic()) continue;

      if (!field.isAccessible()) {
        try {
          field.setAccessible(true);
        } catch (AccessControlException ex) {
          continue;
        }
      }

      nameToField.put(field.getName(), new FieldMetadata(field));
    }
    typeToFields.put(type, nameToField);
    return nameToField;
  }
Esempio n. 2
0
 /**
  * s * @return an array containing all public methods of this class and its super classes. See
  * {@link Class#getMethods()}.
  */
 public Method[] getMethods() {
   if (allMethods == null) {
     ArrayList<Method> allMethodsList = new ArrayList<Method>();
     Type t = this;
     while (t != null) {
       for (Method m : t.methods) {
         if (m.isPublic()) allMethodsList.add(m);
       }
       t = t.getSuperclass();
     }
     allMethods = allMethodsList.toArray(new Method[allMethodsList.size()]);
   }
   return allMethods;
 }
Esempio n. 3
0
 /**
  * @return an array containing all the public fields of this class and its super classes. See
  *     {@link Class#getFields()}.
  */
 public Field[] getFields() {
   if (allFields == null) {
     ArrayList<Field> allFieldsList = new ArrayList<Field>();
     Type t = this;
     while (t != null) {
       for (Field f : t.fields) {
         if (f.isPublic) allFieldsList.add(f);
       }
       t = t.getSuperclass();
     }
     allFields = allFieldsList.toArray(new Field[allFieldsList.size()]);
   }
   return allFields;
 }