/** Returns an array type whose elements are all instances of {@code componentType}. */ public static ArrayTypeName of(Type componentType) { return of(TypeName.get(componentType)); }
static ArrayTypeName get( ArrayType mirror, Map<TypeParameterElement, TypeVariableName> typeVariables) { return new ArrayTypeName(get(mirror.getComponentType(), typeVariables)); }
@Override public ArrayTypeName annotated(List<AnnotationSpec> annotations) { return new ArrayTypeName(componentType, concatAnnotations(annotations)); }
@Override public ArrayTypeName visitArray(ArrayType t, Void p) { return ArrayTypeName.get(t, typeVariables); }
/** Returns an array type whose elements are all instances of {@code componentType}. */ public static ArrayTypeName of(TypeName componentType) { return new ArrayTypeName(componentType); }
/** Returns an array type equivalent to {@code mirror}. */ public static ArrayTypeName get(ArrayType mirror) { return get(mirror, new LinkedHashMap<>()); }
@Override public ArrayTypeName annotated(List<AnnotationSpec> annotations) { return new ArrayTypeName(componentType, concatAnnotations(annotations)); }
@Override public TypeName withoutAnnotations() { return new ArrayTypeName(componentType); }
@Override public TypeName getTypeName() { return ArrayTypeName.of(arrayType.getTypeName()); }
static TypeName get(Type type, Map<Type, TypeVariableName> map) { if (type instanceof Class<?>) { Class<?> classType = (Class<?>) type; if (type == void.class) return VOID; if (type == boolean.class) return BOOLEAN; if (type == byte.class) return BYTE; if (type == short.class) return SHORT; if (type == int.class) return INT; if (type == long.class) return LONG; if (type == char.class) return CHAR; if (type == float.class) return FLOAT; if (type == double.class) return DOUBLE; if (classType.isArray()) return ArrayTypeName.of(get(classType.getComponentType(), map)); return ClassName.get(classType); } else if (type instanceof ParameterizedType) { return ParameterizedTypeName.get((ParameterizedType) type, map); } else if (type instanceof WildcardType) { return WildcardTypeName.get((WildcardType) type, map); } else if (type instanceof TypeVariable<?>) { return TypeVariableName.get((TypeVariable<?>) type, map); } else if (type instanceof GenericArrayType) { return ArrayTypeName.get((GenericArrayType) type, map); } else { throw new IllegalArgumentException("unexpected type: " + type); } }
/** Returns an array type equivalent to {@code type}. */ public static ArrayTypeName get(GenericArrayType type) { return get(type, new LinkedHashMap<>()); }
static ArrayTypeName get( ArrayType mirror, Map<TypeParameterElement, TypeVariableName> typeVariables) { return new ArrayTypeName(get(mirror.getComponentType(), typeVariables)); }
@Override public ArrayTypeName annotated(List<AnnotationSpec> annotations) { return new ArrayTypeName(componentType, concatAnnotations(annotations)); }
/** Returns an array type whose elements are all instances of {@code componentType}. */ public static ArrayTypeName of(TypeName componentType) { return new ArrayTypeName(componentType); }
@NonNull @Override public CodeBlock visitArray(@NonNull List<? extends AnnotationValue> values, Void v) { ArrayTypeName arrayTypeName = (ArrayTypeName) type; if (arrayTypeName.componentType instanceof ParameterizedTypeName) { arrayTypeName = ArrayTypeName.of(((ParameterizedTypeName) arrayTypeName.componentType).rawType); } return CodeBlock.of("new $T{$L}", arrayTypeName, values.stream().map(value -> value.accept(this, null)) .reduce((c1, c2) -> CodeBlock.builder().add(c1).add(", ").add(c2).build()).orElseGet(() -> CodeBlock.builder().build())); } }
@Override public ArrayTypeName visitArray(ArrayType t, Void p) { return ArrayTypeName.get(t, typeVariables); }
static ArrayTypeName get( ArrayType mirror, Map<TypeParameterElement, TypeVariableName> typeVariables) { return new ArrayTypeName(get(mirror.getComponentType(), typeVariables)); }
/** Returns an array type whose elements are all instances of {@code componentType}. */ public static ArrayTypeName of(TypeName componentType) { return new ArrayTypeName(componentType); }