Returns a new NestableFieldValidator for a List of the given Class.

@param cls         the Class of elements composing the list
@param nullAllowed whether or not a value of null is valid
@return a NestableFieldValidator for a list of the given class
348572
public static NestableFieldValidator listFv(Class cls, boolean nullAllowed) {
        return listFv(fv(cls, false), nullAllowed);
    }
120144
private ValidationResult isValidClassForType(Class<?> clazz, SoyType type) {
    // Exit early if the class is primitive and the type is nullable -- that's not allowed.
    // Then remove null from the type.  This allows us to accept precise params for nullable
    // types, e.g, for int|null we can allow IntegerData (which will be passed as 'null').
    if (SoyTypes.isNullable(type) && Primitives.allPrimitiveTypes().contains(clazz)) {
      return ValidationResult.forNullToPrimitive(type);
    }
    // Also exit early if the type is a VE, since those aren't allowed as params.
    if (SoyTypes.isKindOrUnionOfKind(type, SoyType.Kind.VE)
        || SoyTypes.isKindOrUnionOfKind(type, SoyType.Kind.VE_DATA)) {
      return ValidationResult.ve(type);
    }

    ImmutableSet<Class<?>> expectedClasses = null;
    GenericDescriptor expectedDescriptor = null;
    type = SoyTypes.tryRemoveNull(type);
    switch (type.getKind()) {
      case ANY:
      case UNKNOWN:
        expectedClasses = UNKNOWN_TYPES;
        break;
      case ATTRIBUTES:
      case CSS:
      case HTML:
      case URI:
      case TRUSTED_RESOURCE_URI:
      case JS:
        expectedClasses = SANITIZED_TYPES;
        break;
      case BOOL:
        expectedClasses = BOOL_TYPES;
        break;
      case FLOAT:
        expectedClasses = FLOAT_TYPES;
        break;
      case INT:
        expectedClasses = INT_TYPES;
        break;
      case LEGACY_OBJECT_MAP:
        expectedClasses = LEGACY_OBJECT_MAP_TYPES;
        break;
      case LIST:
        expectedClasses = LIST_TYPES;
        break;
      case MAP:
        expectedClasses = MAP_TYPES;
        break;
      case RECORD:
        expectedClasses = RECORD_TYPES;
        break;
      case STRING:
        expectedClasses = STRING_TYPES;
        break;
      case NULL:
        expectedClasses = NULL_TYPES;
        break;
      case PROTO:
        expectedClasses = PROTO_TYPES;
        expectedDescriptor = ((SoyProtoType) type).getDescriptor();
        break;
      case PROTO_ENUM:
        expectedClasses = PROTO_ENUM_TYPES;
        expectedDescriptor = ((SoyProtoEnumType) type).getDescriptor();
        break;
      case UNION:
        // number is a special case, it should work for double and NumberData
        if (type.equals(SoyTypes.NUMBER_TYPE)) {
          expectedClasses = NUMBER_TYPES;
          break;
        }
        // If this is a union, make sure the type is valid for every member.
        // If the type isn't valid for any member, then there's no guarantee this will work
        // for an arbitrary template at runtime.
        ValidationResult result = ValidationResult.valid();
        for (SoyType member : ((UnionType) type).getMembers()) {
          result.merge(isValidClassForType(clazz, member));
        }
        return result;
      case VE:
      case VE_DATA:
        throw new IllegalStateException("This should have been caught above");
      case ERROR:
        throw new IllegalStateException("Cannot have error type from function signature");
    }

    checkState(expectedClasses != null, "expectedClass not set!");
    if (expectedClasses.contains(clazz)) {
      return ValidationResult.valid();
    }
    ImmutableSet<String> expectedDescriptorNames = ImmutableSet.of();
    if (expectedDescriptor instanceof Descriptor) {
      expectedDescriptorNames =
          ImmutableSet.of(JavaQualifiedNames.getClassName((Descriptor) expectedDescriptor));
      if (matchesProtoDescriptor(Message.class, clazz, expectedDescriptor)) {
        return ValidationResult.valid();
      }
    }
    if (expectedDescriptor instanceof EnumDescriptor) {
      expectedDescriptorNames =
          ImmutableSet.of(JavaQualifiedNames.getClassName((EnumDescriptor) expectedDescriptor));
      if (clazz.isEnum()
          && matchesProtoDescriptor(ProtocolMessageEnum.class, clazz, expectedDescriptor)) {
        return ValidationResult.valid();
      }
    }
    // If none of the above conditions match, we failed.
    return ValidationResult.invalid(
        Stream.concat(
                expectedClasses.stream().map(Class::getName), expectedDescriptorNames.stream())
            .collect(toImmutableSet()));
  }
829367
public static Set<Field> getFieldsAnnotatedBy(Class<?> classs, Class<? extends Annotation> ann) {
    Set<Field> set = new HashSet<>();
    for (Field field : getAllFields(classs)) {
      if (field.isAnnotationPresent(ann)) {
        set.add(field);
      }
    }
    return set;
  }
501527
public static Field[] getAllFields(Class<?> clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException("You must specify the class that contains the fields");
        }
        Set<Field> fields = new LinkedHashSet<Field>();

        Class<?> thisType = clazz;

        while (thisType != null) {
            final Field[] declaredFields = thisType.getDeclaredFields();
            for (Field field : declaredFields) {
                field.setAccessible(true);
                fields.add(field);
            }
            thisType = thisType.getSuperclass();
        }
        return fields.toArray(new Field[fields.size()]);
    }
886266
public static @Nonnull FormValidation aggregate(@Nonnull Collection<FormValidation> validations) {
        if (validations == null || validations.isEmpty()) return FormValidation.ok();

        if (validations.size() == 1) return validations.iterator().next();

        final StringBuilder sb = new StringBuilder("<ul style='list-style-type: none; padding-left: 0; margin: 0'>");
        FormValidation.Kind worst = Kind.OK;
        for (FormValidation validation: validations) {
            sb.append("<li>").append(validation.renderHtml()).append("</li>");

            if (validation.kind.ordinal() > worst.ordinal()) {
                worst = validation.kind;
            }
        }
        sb.append("</ul>");

        return respond(worst, sb.toString());
    }
4362
public static Field getField(Class cls, String fieldname) throws NoSuchFieldException
    {
        while (true)
        {
            try
            {
                return cls.getDeclaredField(fieldname);
            }
            catch (NoSuchFieldException ex)
            {
                cls = cls.getSuperclass();
                if (Object.class.equals(cls))
                {
                    throw ex;
                }
            }
            catch (SecurityException ex)
            {
                throw new IllegalArgumentException(ex);
            }
        }
    }
1147878
protected HashMap<String, FieldDeserializer> getFieldMap(Class cl)
    {
        HashMap<String, FieldDeserializer> fieldMap = new HashMap<String, FieldDeserializer>();

        for (; cl != null; cl = cl.getSuperclass()) {
            Field[] fields = cl.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];

                if (Modifier.isTransient(field.getModifiers())
                    || Modifier.isStatic(field.getModifiers()))
                    continue;
                else if (fieldMap.get(field.getName()) != null)
                    continue;

                // XXX: could parameterize the handler to only deal with public
                try {
                    field.setAccessible(true);
                } catch (Throwable e) {
                    e.printStackTrace();
                }

                Class<?> type = field.getType();
                FieldDeserializer deser;

                if (String.class.equals(type))
                    deser = new StringFieldDeserializer(field);
                else if (byte.class.equals(type)) {
                    deser = new ByteFieldDeserializer(field);
                }
                else if (short.class.equals(type)) {
                    deser = new ShortFieldDeserializer(field);
                }
                else if (int.class.equals(type)) {
                    deser = new IntFieldDeserializer(field);
                }
                else if (long.class.equals(type)) {
                    deser = new LongFieldDeserializer(field);
                }
                else if (float.class.equals(type)) {
                    deser = new FloatFieldDeserializer(field);
                }
                else if (double.class.equals(type)) {
                    deser = new DoubleFieldDeserializer(field);
                }
                else if (boolean.class.equals(type)) {
                    deser = new BooleanFieldDeserializer(field);
                }
                else if (java.sql.Date.class.equals(type)) {
                    deser = new SqlDateFieldDeserializer(field);
                }
                else if (java.sql.Timestamp.class.equals(type)) {
                    deser = new SqlTimestampFieldDeserializer(field);
                }
                else if (java.sql.Time.class.equals(type)) {
                    deser = new SqlTimeFieldDeserializer(field);
                }
                else {
                    deser = new ObjectFieldDeserializer(field);
                }

                fieldMap.put(field.getName(), deser);
            }
        }

        return fieldMap;
    }
1293161
@Override
    public Iterator<String> getEnclosingValidatorIds()
    {
        if (_enclosingValidatorIdsStack != null && !_enclosingValidatorIdsStack.isEmpty())
        {
            return new KeyEntryIterator<String, EditableValueHolderAttachedObjectHandler>
                (_enclosingValidatorIdsStack.iterator()); 
        }
        return null;
    }
993885
@Override
    protected <T> T instantiateClass(Class<T> clazz) throws Throwable {
        // Get the current BeanManager for this module. If one doesn't exist it is because 
        // the module isn't CDI enabled and we fall back to the original behavior.

        ManagedObject<T> mo = null;
        if (releasableFactory != null) {
            mo = releasableFactory.createValidationReleasable(clazz);
        }

        if (mo != null) {
            if (releasables == null) {
                releasables = new LinkedList<ValidationReleasable<?>>();
            }

            // Save off the context under which the class was created as a CDI managed
            // bean so it can be cleaned up upon stopping the module.
            //releasables.add(mo);

            return mo.getObject();
        } else {
            return super.instantiateClass(clazz);
        }
    }
1245678
private static Field[] getBurstableFields(Class<?> cls) {
    final List<Field> fields = new ArrayList<>();

    for (Field field : getAllFields(cls)) {
      if (field.isAnnotationPresent(Burst.class)) {

        if (Modifier.isStatic(field.getModifiers())) {
          throw new IllegalStateException("Burstable field must not be static: " + field.getName());
        }

        if (Modifier.isFinal(field.getModifiers())) {
          throw new IllegalStateException("Burstable field must not be final: " + field.getName());
        }

        fields.add(field);
      }
    }

    return fields.toArray(new Field[fields.size()]);
  }
243522
private static List<Field> getFieldsList(final Class cls, final boolean declared) {
		$.checkNotNull(cls);

		final List<Field> allFields = new ArrayList<Field>();
		Class currentClass = cls;
		while (currentClass != null) {
			final Field[] declaredFields = declared ? currentClass.getDeclaredFields() : currentClass.getFields();
			for (Field field : declaredFields) {
				allFields.add(field);
			}
			currentClass = currentClass.getSuperclass();
		}
		return allFields;
	}
1336201
public static <T> T castOrNull(Object o, Class<T> cls)
	{
		if(o == null)
			return null;
		if(cls.isInstance(o))
			return cls.cast(o);
		return null;
	}
316313
public static Field[] getAllFields(final Class<?> cls) {
        final List<Field> allFieldsList = getAllFieldsList(cls);
        return allFieldsList.toArray(new Field[allFieldsList.size()]);
    }
76848
public static TreeSet<Class<?>> getAllInterfaces(Class<?> cls) {
        final TreeSet<Class<?>> interfacesFound = new TreeSet<>(
            (c1, c2) -> {
                if (c1.equals(c2)) {
                    return 0;
                } else if (c1.isAssignableFrom(c2)) {
                    return 1;
                } else {
                    return -1;
                }
            }
        );
        getAllInterfaces(cls, interfacesFound);
        return interfacesFound;
    }
1035889
@SuppressWarnings("unchecked")
    public <T extends WebLocatorAbstractBuilder> T setCls(final String cls) {
        pathBuilder.setCls(cls);
        return (T) this;
    }
56490
private static Collection<ValidationViolation> validate(Collection<ValidationViolation> colViolations, Object objectToValidate) {
        String className = objectToValidate.getClass().getSimpleName();
        Field[] fields = MPCoreUtils.getAllFields(objectToValidate.getClass());
        for(Field field : fields) {
            Annotation[] annotations = field.getAnnotations();
            if (annotations != null) {
                Object value = null;
                try {
                    field.setAccessible(true);
                    value = field.get(objectToValidate);
                } catch (Exception ex) {
                    colViolations.add(new ValidationViolation(className, field.getName(), "is not accesible"));
                }

                if (value != null &&
                        value.getClass().getCanonicalName().indexOf("com.mercadopago.resources.datastructures.") == 0 &&
                        !value.getClass().getName().contains("$")) {
                    colViolations = validate(colViolations, value);
                } else if (value != null &&
                        value.getClass().getCanonicalName().equals("java.util.ArrayList")) {
                    for (Object arrayItem : (ArrayList)value) {
                        colViolations = validate(colViolations, arrayItem);
                    }
                } else {
                    for (Annotation annotation : annotations) {
                        if (annotation instanceof NotNull) {
                            if (value == null) {
                                colViolations.add(new ValidationViolation(className, field.getName(), "can not be 'null'"));
                            }

                        } else if (annotation instanceof Numeric) {
                            if (value != null) {
                                if (!NumberUtils.isNumber(value.toString())) {
                                    colViolations.add(new ValidationViolation(className, field.getName(), "is not a valid number", value));
                                } else {
                                    Float floatValue = Float.parseFloat(value.toString());
                                    String stringValue = NumberUtils.createBigDecimal(value.toString()).toString();
                                    Numeric numeric = (Numeric) annotation;
                                    if (numeric.min() > floatValue) {
                                        colViolations.add(new ValidationViolation(className, field.getName(), "falls short of the minimum value", stringValue, numeric.min()));
                                    }
                                    if (numeric.max() < floatValue) {
                                        colViolations.add(new ValidationViolation(className, field.getName(), "exceeds the maximum value", stringValue, numeric.max()));
                                    }
                                    if (numeric.fractionDigits() > -1) {
                                        if (stringValue.contains(".") &&
                                                stringValue.substring(String.valueOf((floatValue)).indexOf(".") + 1).length() > numeric.fractionDigits()) {
                                            colViolations.add(new ValidationViolation(className, field.getName(), "exceeds the maximum decimal digits", stringValue, numeric.fractionDigits()));
                                        }
                                    }
                                }
                            }

                        } else if (annotation instanceof Size) {
                            if (value != null) {
                                String stringValue = value.toString();
                                Size size = (Size) annotation;
                                if (size.min() > -1 &&
                                        stringValue.length() < size.min()) {
                                    colViolations.add(new ValidationViolation(className, field.getName(), "fall short of the minimum length", stringValue.length(), size.min()));
                                }
                                if (size.max() > -1 &&
                                        stringValue.length() > size.max()) {
                                    colViolations.add(new ValidationViolation(className, field.getName(), "exceed the maximum length value", stringValue.length(), size.max()));
                                }
                            }
                        }
                    }
                }
            }
        }
        return colViolations;
    }
997930
public static<T extends ParamValidator> T getValidator(Class<T> clazz, boolean required) {

        List<ParamValidator> validators = validatorsMap.get(clazz);
        if (validators != null) {

            if (required) {
                return (T)validators.get(0);
            }

            return (T)validators.get(1);
        }

        return null;
    }