/** * Test instance if is array like. If instance to test is not null delegates {@link #isArrayLike(Type)}; otherwise * return false. * * @param o instance to test, possible null in which case returns false. * @return true if instance is array like; returns false if instance to test is null. */ public static boolean isArrayLike(Object o) { return o != null && isArrayLike(o.getClass()); }
private static String expectedStartSequence(Type[] formalParameters) { if (formalParameters.length == 0) { return "["; } StringBuilder builder = new StringBuilder(); builder.append('['); Type parameter = formalParameters[0]; while (Types.isArrayLike(parameter)) { builder.append('['); if (!(parameter instanceof ParameterizedType)) { break; } ParameterizedType parameterizedType = (ParameterizedType) parameter; parameter = parameterizedType.getActualTypeArguments()[0]; } return builder.toString(); }
/** * Retrieve content array like instance as iterable. Delegates {@link #getValue(Object, String)} to obtain the requested * value. If value is null warn the event and return empty list. I value is array like return it as iterable, otherwise * throws content exception. * * @param scope scope object, * @param propertyPath object property path. * @return array like instance, possible empty, converted to iterable. * @throws TemplateException if requested value is undefined or is not an {@link Types#isArrayLike(Object) an array like}. */ Iterable<?> getIterable(Object scope, String propertyPath) throws TemplateException { Object value = getValue(scope, propertyPath); if (value == null) { warn(scope.getClass(), propertyPath); return Collections.EMPTY_LIST; } if (!Types.isArrayLike(value)) { throw new TemplateException("Invalid type. Expected list but got |%s|.", value.getClass()); } return Types.asIterable(value); }
/** * Test if method formal parameters designates a strict object, that is, is not primitive, array, collection or map. * * @param formalParameters method formal parameters list. * @return true if formal parameters designates a strict object. */ private static boolean isObject(Type[] formalParameters) { if (formalParameters.length != 1) { return false; } final Type type = formalParameters[0]; if (!(type instanceof Class)) { return false; } if (Types.isPrimitive(type)) { return false; } if (Types.isArrayLike(type)) { return false; } if (Types.isMap(type)) { return false; } if (ConverterRegistry.hasType(type)) { return false; } return true; }
if (!Types.isArrayLike(type)) { if (!(type instanceof Class)) { throw new BugError("Generic value types are not supported.");
if (Types.isArrayLike(value)) { serializeArray(value); return;