public static TypeDeclarationNode unionType(TypeDeclarationNode... options) { return unionType(Arrays.asList(options)); }
public static TypeDeclarationNode unionType(TypeDeclarationNode... options) { return unionType(Arrays.asList(options)); }
/** * Deep flattens a list of types into a single union type. * * @return A flattened union type with at most 1 null. */ TypeDeclarationNode flatUnionType(Iterable<TypeDeclarationNode> types) { List<TypeDeclarationNode> flatTypes = new ArrayList<>(); flatten(types, flatTypes, false); return unionType(flatTypes); } }
Node processUnionType(UnionTypeTree tree) { ImmutableList.Builder<TypeDeclarationNode> options = ImmutableList.builder(); for (ParseTree option : tree.types) { options.add((TypeDeclarationNode) transform(option)); } return cloneProps(unionType(options.build())); }
Node processUnionType(UnionTypeTree tree) { ImmutableList.Builder<TypeDeclarationNode> options = ImmutableList.builder(); for (ParseTree option : tree.types) { options.add((TypeDeclarationNode) transform(option)); } return cloneProps(unionType(options.build())); }
private Node maybeProcessOptionalProperty(Node n, Node type) { if (n.isOptionalEs6Typed()) { n.putBooleanProp(Node.OPT_ES6_TYPED, false); TypeDeclarationNode baseType = (TypeDeclarationNode) maybeCreateAnyType(n, type); type = TypeDeclarationsIR.unionType( ImmutableList.of(baseType, TypeDeclarationsIR.undefinedType())); type.useSourceInfoIfMissingFromForTree(baseType); } else { type = maybeCreateAnyType(n, type); } return convertWithLocation(type); }
private Node maybeProcessOptionalProperty(Node n, Node type) { if (n.isOptionalEs6Typed()) { n.putBooleanProp(Node.OPT_ES6_TYPED, false); TypeDeclarationNode baseType = (TypeDeclarationNode) maybeCreateAnyType(n, type); type = TypeDeclarationsIR.unionType( ImmutableList.of(baseType, TypeDeclarationsIR.undefinedType())); type.useSourceInfoIfMissingFromForTree(baseType); } else { type = maybeCreateAnyType(n, type); } return convertWithLocation(type); }
return types.get(0); default: return unionType(types);