static String className(Type type) { if (type instanceof ArrayType) { return className(((ArrayType) type).getComponentType()) + "[]"; } if (!(type instanceof Class)) { return type.toString(); } Class clazz = (Class) type; if (clazz.isArray()) { return className(clazz.getComponentType()) + "[]"; } String className = clazz.getName(); if (!clazz.isPrimitive() && clazz.getPackage() != null && clazz.getPackage().getName().equals("java.lang")) { return className.substring("java.lang.".length()); } return className.replace('$', '.'); }
/** * Returns the element type of a {@link Collection}, {@link Iterable} * (including {@link org.apache.calcite.linq4j.Queryable Queryable} and * {@link org.apache.calcite.linq4j.Enumerable Enumerable}), {@link Iterator}, * {@link Enumerator}, or an array. * * <p>Returns null if the type is not one of these.</p> */ public static Type getElementType(Type type) { if (type instanceof ArrayType) { return ((ArrayType) type).getComponentType(); } if (type instanceof GenericArrayType) { return ((GenericArrayType) type).getGenericComponentType(); } Class clazz = toClass(type); if (clazz.isArray()) { return clazz.getComponentType(); } if (Collection.class.isAssignableFrom(clazz) || Iterable.class.isAssignableFrom(clazz) || Iterator.class.isAssignableFrom(clazz) || Enumerator.class.isAssignableFrom(clazz)) { if (type instanceof ParameterizedType) { return ((ParameterizedType) type).getActualTypeArguments()[0]; } return Object.class; } return null; }
/** * Returns the component type of an array. */ public static Type getComponentType(Type type) { if (type instanceof Class) { return ((Class) type).getComponentType(); } if (type instanceof ArrayType) { return ((ArrayType) type).getComponentType(); } if (type instanceof GenericArrayType) { return ((GenericArrayType) type).getGenericComponentType(); } if (type instanceof ParameterizedType) { return getComponentType(((ParameterizedType) type).getRawType()); } if (type instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) type; return getComponentType(typeVariable.getBounds()[0]); } return null; // not an array type }
final Types.ArrayType arrayType = (Types.ArrayType) type; final RelDataType componentRelType = createType(arrayType.getComponentType()); return createArrayType( createTypeWithNullability(componentRelType,
final Types.ArrayType arrayType = (Types.ArrayType) type; final RelDataType componentRelType = createType(arrayType.getComponentType()); return createArrayType( createTypeWithNullability(componentRelType,