private void addInvalidatingType(JSType type) { checkState(!type.isUnionType()); invalidatingTypes.add(type); }
@Override public final JSType collapseUnion() { if (referencedType.isUnionType()) { return referencedType.collapseUnion(); } return this; }
@Override public JSType collapseUnion() { if (referencedType.isUnionType()) { return referencedType.collapseUnion(); } return this; }
/** * Gets the alternate types of this union type, including structural interfaces * and implicit implementations as are distinct alternates. * @return The alternate types of this union type. The returned set is * immutable. */ public Collection<JSType> getAlternatesWithoutStructuralTyping() { for (JSType t : alternatesWithoutStucturalTyping) { if (t.isUnionType()) { rebuildAlternates(); break; } } return alternatesWithoutStucturalTyping; }
/** * Gets the alternate types of this union type. * @return The alternate types of this union type. The returned set is * immutable. */ public Collection<JSType> getAlternates() { for (JSType t : alternatesWithoutStucturalTyping) { if (t.isUnionType()) { rebuildAlternates(); break; } } return alternates; }
public Iterable<JSType> getUnionMembers() { return isUnionType() ? this.toMaybeUnionType().getAlternatesWithoutStructuralTyping() : null; }
@Override public JSType getLeastSupertype(JSType that) { if (!that.isUnknownType() && !that.isUnionType()) { for (int i = 0; i < alternatesRetainingStructuralSubtypes.size(); i++) { JSType alternate = alternatesRetainingStructuralSubtypes.get(i); if (!alternate.isUnknownType() && that.isSubtypeOf(alternate)) { return this; } } } return JSType.getLeastSupertype(this, that); }
/** Gets the string representation of a var args param. */ private void appendVarArgsString(StringBuilder builder, JSType paramType, boolean forAnnotations) { if (paramType.isUnionType()) { // Remove the optionality from the var arg. paramType = paramType.toMaybeUnionType().getRestrictedUnion( registry.getNativeType(JSTypeNative.VOID_TYPE)); } builder.append("...").append( paramType.toStringHelper(forAnnotations)); }
/** Gets the string representation of an optional param. */ private void appendOptionalArgString( StringBuilder builder, JSType paramType, boolean forAnnotations) { if (paramType.isUnionType()) { // Remove the optionality from the var arg. paramType = paramType.toMaybeUnionType().getRestrictedUnion( registry.getNativeType(JSTypeNative.VOID_TYPE)); } builder.append(paramType.toStringHelper(forAnnotations)).append("="); }
private JSType restrictByUndefined(JSType type) { if (type.isUnionType()) { return type.toMaybeUnionType().getRestrictedUnion( (JSType) registry.getNativeType(JSTypeNative.VOID_TYPE)); } return type; } }
/** Gets the string representation of an optional param. */ private void appendOptionalArgString(StringBuilder sb, JSType paramType, boolean forAnnotations) { if (paramType.isUnionType()) { // Remove the optionality from the var arg. paramType = paramType .toMaybeUnionType() .getRestrictedUnion(registry.getNativeType(JSTypeNative.VOID_TYPE)); } paramType.appendAsNonNull(sb, forAnnotations).append("="); }
private void printErrorLocations(List<String> errors, JSType t) { if (!t.isObject() || t.isAllType()) { return; } if (t.isUnionType()) { for (JSType alt : t.toMaybeUnionType().getAlternates()) { printErrorLocations(errors, alt); } return; } for (JSError error : invalidationMap.get(t)) { errors.add(t + " at " + error.sourceName + ":" + error.lineNumber); } }
private void addReferenceTypeIndexedByProperty( String propertyName, JSType type) { if (type instanceof ObjectType && ((ObjectType) type).hasReferenceName()) { Map<String, ObjectType> typeSet = eachRefTypeIndexedByProperty.computeIfAbsent(propertyName, k -> new LinkedHashMap<>()); ObjectType objType = (ObjectType) type; typeSet.put(objType.getReferenceName(), objType); } else if (type instanceof NamedType) { addReferenceTypeIndexedByProperty( propertyName, ((NamedType) type).getReferencedType()); } else if (type.isUnionType()) { for (JSType alternate : type.toMaybeUnionType().getAlternates()) { addReferenceTypeIndexedByProperty(propertyName, alternate); } } }
@Override public JSType getLeastSupertype(JSType that) { if (!that.isUnknownType() && !that.isUnionType()) { for (JSType alternate : alternatesWithoutStucturalTyping) { if (!alternate.isUnknownType() && that.isSubtype(alternate)) { return this; } } } return getLeastSupertype(this, that); }
private static boolean containsForwardDeclaredUnresolvedName(JSType type) { if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternates()) { if (containsForwardDeclaredUnresolvedName(alt)) { return true; } } } return type.isNoResolvedType(); }
private static boolean containsForwardDeclaredUnresolvedName(JSType type) { if (type.isUnionType()) { for (JSType alt : type.toMaybeUnionType().getAlternates()) { if (containsForwardDeclaredUnresolvedName(alt)) { return true; } } } return type.isNoResolvedType(); }
private boolean conforms(JSType type) { if (type.isUnionType()) { // unwrap union types which might contain unresolved type name // references for example {Foo|undefined} for (JSType part : type.toMaybeUnionType().getAlternates()) { if (!conforms(part)) { return false; } } return true; } else { return !type.isNoResolvedType(); } } }
final StringBuilder appendAsNonNull(StringBuilder sb, boolean forAnnotations) { if (forAnnotations && isObject() && !isUnknownType() && !isTemplateType() && !isRecordType() && !isFunctionType() && !isUnionType() && !isLiteralObject()) { sb.append("!"); } return appendTo(sb, forAnnotations); }
private boolean containsArray(JSType type) { if (isArray(type)) { return true; } if (type.isUnionType()) { JSType arrayType = typeRegistry.getNativeType(ARRAY_TYPE); for (JSType alternate : type.toMaybeUnionType().getAlternates()) { if (alternate.isSubtype(arrayType)) { return true; } } } return false; }
/** * @return true if n MUST be a prototype name reference. */ private boolean isPrototypeNameReference(Node n) { if (!n.isGetProp()) { return false; } JSType type = getType(n.getFirstChild()); if (type.isUnknownType() || type.isUnionType()) { return false; } return (type.isInstanceType() || type.autoboxesTo() != null); }